Class: Syskit::GUI::LoggingConfiguration

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/syskit/gui/logging_configuration.rb

Overview

A widget containing an editable TreeView to allow the user to manage basic Syskit's logging configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, syskit) ⇒ LoggingConfiguration

Returns a new instance of LoggingConfiguration



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/syskit/gui/logging_configuration.rb', line 15

def initialize(parent = nil, syskit)
    super(parent)
    main_layout = Qt::VBoxLayout.new(self)
    @treeView = Qt::TreeView.new

    Vizkit.setup_tree_view treeView
    @model = Vizkit::VizkitItemModel.new
    treeView.setModel @model
    main_layout.add_widget(treeView)
    treeView.setColumnWidth(0, 200)
    treeView.style_sheet = "QTreeView { background-color: rgb(255, 255, 219);
                                        alternate-background-color: rgb(255, 255, 174);
                                        color: rgb(0, 0, 0); }
                            QTreeView:disabled { color: rgb(159, 158, 158); }"

    @syskit = syskit
    @timer = Qt::Timer.new
    @timer.connect(SIGNAL('timeout()')) { refresh }
    @timer.start 1500

    refresh
end

Instance Attribute Details

#item_nameObject (readonly)

Returns the value of attribute item_name



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def item_name
  @item_name
end

#item_valueObject (readonly)

Returns the value of attribute item_value



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def item_value
  @item_value
end

#modelObject (readonly)

Returns the value of attribute model



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def model
  @model
end

#pending_callObject (readonly)

Returns the value of attribute pending_call



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def pending_call
  @pending_call
end

#syskitObject (readonly)

Returns the value of attribute syskit



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def syskit
  @syskit
end

#treeViewObject (readonly)

Returns the value of attribute treeView



14
15
16
# File 'lib/syskit/gui/logging_configuration.rb', line 14

def treeView
  @treeView
end

Instance Method Details

#enabled(toggle) ⇒ Object

Changes the top most item in the tree state and makes it update its childs accordingly



75
76
77
# File 'lib/syskit/gui/logging_configuration.rb', line 75

def enabled(toggle)
    @item_name.enabled toggle unless @item_name.nil?
end

#recursive_expand(item) ⇒ Object

Expands the entire tree



66
67
68
69
70
71
# File 'lib/syskit/gui/logging_configuration.rb', line 66

def recursive_expand(item)
    treeView.expand(item.index)
    (0...item.rowCount).each do |i|
        recursive_expand(item.child(i))
    end
end

#refreshObject

Fetches the current logging configuration from syskit's sync interface



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/syskit/gui/logging_configuration.rb', line 45

def refresh
    if syskit.reachable?
        begin
            return if refreshing?
            @pending_call = syskit.async_call ['syskit'], :logging_conf do |error, result|
                if error.nil?
                    enabled true
                    update_model(result)
                else
                    enabled false
                end
            end
        rescue Roby::Interface::ComError
            enabled false
        end
    else
        enabled false
    end
end

#refreshing?Boolean

Whether there is a refreshing call pending

Returns:

  • (Boolean)


39
40
41
# File 'lib/syskit/gui/logging_configuration.rb', line 39

def refreshing?
    syskit.async_call_pending?(pending_call)
end

#update_model(conf) ⇒ Object

Updates the view model



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/syskit/gui/logging_configuration.rb', line 80

def update_model(conf)
    if @item_name.nil?
        @item_name = LoggingConfigurationItem.new(conf, :accept => true)
        @item_value = LoggingConfigurationItem.new(conf)
        @item_value.setEditable true
        @item_value.setText ""
        @model.appendRow([@item_name, @item_value])
        recursive_expand(@item_name)

        @item_name.on_accept_changes do |new_conf|
            begin
                syskit.async_call ['syskit'], :update_logging_conf, new_conf do |error, result|
                    enabled false unless error.nil?
                end
            rescue Roby::Interface::ComError
                enabled false
            end
        end
    else
        return if @item_name.modified?
        @item_name.update_conf(conf)
    end
end