Class: Syskit::GUI::GlobalStateLabel

Inherits:
StateLabel show all
Defined in:
lib/syskit/gui/global_state_label.rb

Overview

Representation of the state of the connected Roby instance

Constant Summary

Constants inherited from StateLabel

StateLabel::COLORS, StateLabel::STYLE, StateLabel::TEXT_WITHOUT_NAME, StateLabel::TEXT_WITH_NAME

Instance Attribute Summary collapse

Attributes inherited from StateLabel

#current_color, #current_state, #current_text, #default_color, #extra_style, #name, #states

Instance Method Summary collapse

Methods inherited from StateLabel

#color_from_state, #declare_default_color, #declare_state, #handle_color_argument, #ignore_state, #rate_limited?, #update_state, #update_style, #update_text

Constructor Details

#initialize(actions: Array.new, **options) ⇒ GlobalStateLabel

Returns a new instance of GlobalStateLabel

Parameters:

  • the (Array<Qt::Action>)

    list of actions that can be performed on the remote Roby instance



13
14
15
16
17
18
19
20
21
# File 'lib/syskit/gui/global_state_label.rb', line 13

def initialize(actions: Array.new, **options)
    super(extra_style: 'margin-left: 2px; margin-top: 2px; font-size: 10pt;',
          rate_limited: true, **options)
    @actions = actions
    declare_state 'STARTING', :blue
    declare_state 'RESTARTING', :blue
    declare_state 'CONNECTED', :green
    declare_state 'UNREACHABLE', :red
end

Instance Attribute Details

#actionsArray<Qt::Action> (readonly)

Actions that are shown when the context menu is activated

Returns:

  • (Array<Qt::Action>)

    the list of actions that can be performed on the remote Roby instance (e.g. start/stop …)



9
10
11
# File 'lib/syskit/gui/global_state_label.rb', line 9

def actions
  @actions
end

Instance Method Details

#app_state_menu(global_pos) ⇒ Object

Execute the app state menu



34
35
36
37
38
39
40
41
# File 'lib/syskit/gui/global_state_label.rb', line 34

def app_state_menu(global_pos)
    if !actions.empty?
        menu = Qt::Menu.new(self)
        actions.each { |act| menu.add_action(act) }
        menu.exec(global_pos)
        true
    end
end

#contextMenuEvent(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Qt handler called when the context menu is activated



26
27
28
29
30
31
# File 'lib/syskit/gui/global_state_label.rb', line 26

def contextMenuEvent(event)
    if !actions.empty?
        app_state_menu(event.global_pos)
        event.accept
    end
end

#mousePressEvent(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Qt handler called when the mouse is pressed



46
47
48
# File 'lib/syskit/gui/global_state_label.rb', line 46

def mousePressEvent(event)
    event.accept
end

#mouseReleaseEvent(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Qt handler called when the mouse is released

It emits the 'clicked' signal



55
56
57
58
# File 'lib/syskit/gui/global_state_label.rb', line 55

def mouseReleaseEvent(event)
    emit clicked(event.global_pos)
    event.accept
end