Class: Roby::Interface::V2::Async::UIConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/interface/v2/async/ui_connector.rb

Overview

Creates a connection between a Syskit job and a Qt-based GUI

A job is a placeholder for an action with some arguments set. It is created by Interface#connect_to_ui. More than one job can exist based on a given action (as long as they differ by their arguments), but a given job can be started by the GUI only once.

Examples:

represent an action with some argument(s) set

action = <name_of_action>!(x: 10)

start a job from an action when a button is pressed

connect widget, SIGNAL('clicked()'), START(action)

allow a job to be restarted (otherwise an existing job must be manually killed first)

connect widget, SIGNAL('clicked()'), START(action), restart: true

kill the job when a button is pressed

connect widget, SIGNAL('clicked()'), KILL(action)

call a block with a job monitoring object when its state changes

connect PROGRESS(job) do |action|
   # 'action' is an ActionMonitor
end

set an action’s argument from a signal (by default, requires the user to press the ‘start’ button afterwards)

connect widget, SIGNAL('textChanged(QString)'), ARGUMENT(action,:z),
   getter: ->(z) { Integer(z) }

set an action’s argument from a signal, and restart the action right away

connect widget, SIGNAL('textChanged(QString)'), ARGUMENT(action,:z),
   getter: ->(z) { Integer(z) },
   auto_apply: true

Defined Under Namespace

Classes: ActionConnector, DropCommand, KillCommand, ProgressMonitorCommand, SetArgumentCommand, StartCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface, widget) ⇒ UIConnector

Returns a new instance of UIConnector.



111
112
113
114
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 111

def initialize(interface, widget)
    @interface = interface
    @widget = widget
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



170
171
172
173
174
175
176
177
178
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 170

def method_missing(m, *args, &block)
    if m =~ /!$/
        ActionMonitor.new(interface, m.to_s[0..-2], *args)
    elsif widget.respond_to?(m)
        widget.public_send(m, *args, &block)
    else
        super
    end
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



109
110
111
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 109

def interface
  @interface
end

#widgetObject (readonly)

Returns the value of attribute widget.



109
110
111
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 109

def widget
  @widget
end

Instance Method Details

#ARGUMENT(action, argument_name) ⇒ Object



162
163
164
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 162

def ARGUMENT(action, argument_name)
    SetArgumentCommand.new(self, action, argument_name)
end

#connect(*args, &block) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 124

def connect(*args, &block)
    if args.first.kind_of?(Qt::Widget)
        # Signature from a widget's signal to Syskit
        widget = args.shift
        signal = args.shift
        action = args.shift
        action.options = args.shift || {}
        if widget.respond_to?(:to_widget)
            widget = widget.to_widget
        end
        widget.connect(signal) do |*args|
            action.run(*args)
        end
    else
        # Signature from syskit to a block
        action = args.shift
        action.options = args.shift
        action.callback = block
        action.connect
    end
end

#DROP(action) ⇒ Object



150
151
152
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 150

def DROP(action)
    DropCommand.new(self, action)
end

#KILL(action) ⇒ Object



154
155
156
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 154

def KILL(action)
    KillCommand.new(self, action)
end

#on_reachable(&block) ⇒ Object



116
117
118
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 116

def on_reachable(&block)
    interface.on_reachable(&block)
end

#on_unreachable(&block) ⇒ Object



120
121
122
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 120

def on_unreachable(&block)
    interface.on_unreachable(&block)
end

#PROGRESS(action) ⇒ Object



158
159
160
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 158

def PROGRESS(action)
    ProgressMonitorCommand.new(self, action)
end

#respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 166

def respond_to_missing?(m, include_private = false)
    (m =~ /!$/) || widget.respond_to?(m) || super
end

#START(action) ⇒ Object



146
147
148
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 146

def START(action)
    StartCommand.new(self, action)
end

#to_widgetObject



180
181
182
# File 'lib/roby/interface/v2/async/ui_connector.rb', line 180

def to_widget
    widget
end