class Roby::Interface::Async::UIConnector

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.

@example represent an action with some argument(s) set

action = <name_of_action>!(x: 10)

@example start a job from an action when a button is pressed

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

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

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

@example kill the job when a button is pressed

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

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

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

@example 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) }

@example 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

Constants

ActionConnector

Attributes

interface[R]
widget[R]

Public Class Methods

new(interface, widget) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 107
def initialize(interface, widget)
    @interface = interface
    @widget = widget
end

Public Instance Methods

ARGUMENT(action, argument_name) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 158
def ARGUMENT(action, argument_name)
    SetArgumentCommand.new(self, action, argument_name)
end
DROP(action) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 146
def DROP(action)
    DropCommand.new(self, action)
end
KILL(action) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 150
def KILL(action)
    KillCommand.new(self, action)
end
PROGRESS(action) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 154
def PROGRESS(action)
    ProgressMonitorCommand.new(self, action)
end
START(action) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 142
def START(action)
    StartCommand.new(self, action)
end
connect(*args, &block) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 120
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 || Hash.new
        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
method_missing(m, *args, &block) click to toggle source
Calls superclass method
# File lib/roby/interface/async/ui_connector.rb, line 166
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
on_reachable(&block) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 112
def on_reachable(&block)
    interface.on_reachable(&block)
end
on_unreachable(&block) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 116
def on_unreachable(&block)
    interface.on_unreachable(&block)
end
respond_to_missing?(m, include_private = false) click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 162
def respond_to_missing?(m, include_private = false)
    (m =~ /!$/) || widget.respond_to?(m)
end
to_widget() click to toggle source
# File lib/roby/interface/async/ui_connector.rb, line 176
def to_widget
    widget
end