Class: Roby::GUI::ChronicleView

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/roby/gui/chronicle_view.rb

Overview

Integration of a ChronicleWidget to use with a PlanRebuilderWidget

Constant Summary collapse

PLAY_STEP =
0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(history_widget, parent = nil) ⇒ ChronicleView

Returns a new instance of ChronicleView.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/roby/gui/chronicle_view.rb', line 14

def initialize(history_widget, parent = nil)
    super(parent)

    @layout = Qt::VBoxLayout.new(self)
    @menu_layout = Qt::HBoxLayout.new
    @layout.add_layout(@menu_layout)
    @history_widget = history_widget
    @chronicle = ChronicleWidget.new(self)
    Qt::Object.connect(@chronicle, SIGNAL("selectedTime(QDateTime)"),
                       history_widget, SLOT("seek(QDateTime)"))
    chronicle.add_tasks_info(*history_widget.tasks_info)
    Qt::Object.connect(history_widget, SIGNAL("addedSnapshot(int)"),
                       self, SLOT("addedSnapshot(int)"))
    @layout.add_widget(@chronicle)

    # Now setup the menu bar
    @btn_play = Qt::PushButton.new("Play", self)
    @menu_layout.add_widget(@btn_play)
    @btn_play.connect(SIGNAL("clicked()")) do
        if @play_timer
            stop
            @btn_play.text = "Play"
        else
            play
            @btn_play.text = "Stop"
        end
    end

    @btn_sort = Qt::PushButton.new("Sort", self)
    @menu_layout.add_widget(@btn_sort)
    @btn_sort.menu = sort_options
    @btn_show = Qt::PushButton.new("Show", self)
    @menu_layout.add_widget(@btn_show)
    @btn_show.menu = show_options
    @menu_layout.add_stretch(1)
    @restrict_to_jobs_btn = Qt::CheckBox.new("Restrict to jobs", self)
    @restrict_to_jobs_btn.checkable = true
    @restrict_to_jobs_btn.connect(SIGNAL("toggled(bool)")) do |set|
        chronicle.restrict_to_jobs = set
    end
    @menu_layout.add_widget(@restrict_to_jobs_btn)

    @filter_lbl = Qt::Label.new("Filter", self)
    @filter_box = Qt::LineEdit.new(self)
    @filter_box.connect(SIGNAL("textChanged(QString const&)")) do |text|
        if text.empty?
            chronicle.filter = nil
        else
            chronicle.filter = Regexp.new(text.split(" ").join("|"))
        end
    end
    @menu_layout.add_widget(@filter_lbl)
    @menu_layout.add_widget(@filter_box)
    @filter_out_lbl = Qt::Label.new("Filter out", self)
    @filter_out_box = Qt::LineEdit.new(self)
    @filter_out_box.connect(SIGNAL("textChanged(QString const&)")) do |text|
        if text.empty?
            chronicle.filter_out = nil
        else
            chronicle.filter_out = Regexp.new(text.split(" ").join("|"))
        end
    end
    @menu_layout.add_widget(@filter_out_lbl)
    @menu_layout.add_widget(@filter_out_box)
    @menu_layout.add_stretch(1)

    resize(500, 300)
end

Instance Attribute Details

#chronicleObject (readonly)

The underlying ChronicleWidget instance



10
11
12
# File 'lib/roby/gui/chronicle_view.rb', line 10

def chronicle
  @chronicle
end

#history_widgetObject (readonly)

The historyw widget instance



12
13
14
# File 'lib/roby/gui/chronicle_view.rb', line 12

def history_widget
  @history_widget
end

Instance Method Details

#addedSnapshot(cycle) ⇒ Object



83
84
85
# File 'lib/roby/gui/chronicle_view.rb', line 83

def addedSnapshot(cycle)
    chronicle.add_tasks_info(*history_widget.tasks_info_of_snapshot(cycle))
end

#apply_options(options) ⇒ Object

Apply saved configuration



211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/roby/gui/chronicle_view.rb', line 211

def apply_options(options)
    if scale = options["time_scale"]
        chronicle.time_scale = scale
    end
    if mode = options["show_mode"]
        @act_show[mode].checked = true
    end
    if mode = options["sort_mode"]
        @act_sort[mode].checked = true
    end
    if mode = options["restrict_to_jobs"]
        @restrict_to_jobs_btn.checked = true
    end
end

#playObject



138
139
140
141
142
# File 'lib/roby/gui/chronicle_view.rb', line 138

def play
    @play_timer = Qt::Timer.new(self)
    Qt::Object.connect(@play_timer, SIGNAL("timeout()"), self, SLOT("step()"))
    @play_timer.start(Integer(1000 * PLAY_STEP))
end

#save_optionsObject

Save view configuration



201
202
203
204
205
206
207
208
# File 'lib/roby/gui/chronicle_view.rb', line 201

def save_options
    result = {}
    result["show_mode"] = chronicle.show_mode
    result["sort_mode"] = chronicle.sort_mode
    result["time_scale"] = chronicle.time_scale
    result["restrict_to_jobs"] = chronicle.restrict_to_jobs?
    result
end

#setCurrentTime(time) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/roby/gui/chronicle_view.rb', line 191

def setCurrentTime(time)
    unless chronicle.base_time
        chronicle.update_base_time(history_widget.start_time)
        chronicle.update_current_time(history_widget.current_time)
    end
    @chronicle.setCurrentTime(time)
end

#setDisplayTime(time) ⇒ Object



182
183
184
185
186
187
188
# File 'lib/roby/gui/chronicle_view.rb', line 182

def setDisplayTime(time)
    unless chronicle.base_time
        chronicle.update_base_time(history_widget.start_time)
        chronicle.update_current_time(history_widget.current_time)
    end
    @chronicle.setDisplayTime(time)
end

#show_optionsObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/roby/gui/chronicle_view.rb', line 112

def show_options
    @mnu_show = Qt::Menu.new(self)
    @actgrp_show = Qt::ActionGroup.new(@mnu_show)

    @act_show = {}
    { "All" => :all, "Running" => :running, "Current" => :current }
        .each do |text, value|
            act = Qt::Action.new(text, self)
            act.checkable = true
            act.connect(SIGNAL("toggled(bool)")) do |onoff|
                if onoff
                    @chronicle.show_mode = value
                    @chronicle.setDisplayTime
                end
            end
            @actgrp_show.add_action(act)
            @mnu_show.add_action(act)
            @act_show[value] = act
        end

    @act_show[:all].checked = true
    @mnu_show
end

#sort_optionsObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/roby/gui/chronicle_view.rb', line 88

def sort_options
    @mnu_sort = Qt::Menu.new(self)
    @actgrp_sort = Qt::ActionGroup.new(@mnu_sort)

    @act_sort = {}
    { "Start time" => :start_time, "Last event" => :last_event }
        .each do |text, value|
            act = Qt::Action.new(text, self)
            act.checkable = true
            act.connect(SIGNAL("toggled(bool)")) do |onoff|
                if onoff
                    @chronicle.sort_mode = value
                    @chronicle.update
                end
            end
            @actgrp_sort.add_action(act)
            @mnu_sort.add_action(act)
            @act_sort[value] = act
        end

    @act_sort[:start_time].checked = true
    @mnu_sort
end

#stepObject



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/roby/gui/chronicle_view.rb', line 145

def step
    if chronicle.display_time == chronicle.current_time
        return
    end

    new_time = chronicle.display_time + PLAY_STEP
    if new_time >= chronicle.current_time
        new_time = chronicle.current_time
    end
    chronicle.setDisplayTime(new_time)
end

#stopObject



158
159
160
161
# File 'lib/roby/gui/chronicle_view.rb', line 158

def stop
    @play_timer.stop
    @play_timer = nil
end

#update_display_time(display_time) ⇒ Object



178
179
180
# File 'lib/roby/gui/chronicle_view.rb', line 178

def update_display_time(display_time)
    chronicle.update_display_time(display_time)
end

#update_time_range(start_time, current_time) ⇒ Object



174
175
176
# File 'lib/roby/gui/chronicle_view.rb', line 174

def update_time_range(start_time, current_time)
    chronicle.update_time_range(start_time, current_time)
end

#updateWindowTitleObject



164
165
166
167
168
169
170
171
# File 'lib/roby/gui/chronicle_view.rb', line 164

def updateWindowTitle
    self.window_title =
        if (parent_title = history_widget.window_title)
            "#{parent_title}: Chronicle"
        else
            "roby-display: Chronicle"
        end
end