Class: Ui::ReplayControls

Inherits:
Ui_ReplayControls show all
Defined in:
lib/roby/log/gui/replay_controls.rb,
lib/roby/log/gui/replay_controls_ui.rb

Constant Summary collapse

KEY_GOTO =
Qt::KeySequence.new('g')

Instance Attribute Summary collapse

Attributes inherited from Ui_ReplayControls

#actionBookmarksAdd, #actionBookmarksLoad, #actionBookmarksSave, #actionBookmarksSaveAs, #actionBookmarksSetMark, #actionGoto, #bookmarks, #faster, #goto, #grp_play, #hboxLayout, #hboxLayout1, #hboxLayout2, #play, #play_step, #progress, #seek_start, #slower, #spacerItem, #speed, #textLabel1, #time_lcd, #vboxLayout, #vboxLayout1

Instance Method Summary collapse

Methods inherited from Ui_ReplayControls

#retranslateUi, #retranslate_ui, #setup_ui

Instance Attribute Details

#bookmarks_actionsObject (readonly)

Returns the value of attribute bookmarks_actions.



7
8
9
# File 'lib/roby/log/gui/replay_controls.rb', line 7

def bookmarks_actions
  @bookmarks_actions
end

#bookmarks_fileObject (readonly)

Returns the value of attribute bookmarks_file.



8
9
10
# File 'lib/roby/log/gui/replay_controls.rb', line 8

def bookmarks_file
  @bookmarks_file
end

#bookmarks_menuObject (readonly)

Returns the value of attribute bookmarks_menu.



6
7
8
# File 'lib/roby/log/gui/replay_controls.rb', line 6

def bookmarks_menu
  @bookmarks_menu
end

#bookmarks_start_markObject (readonly)

Returns the value of attribute bookmarks_start_mark.



9
10
11
# File 'lib/roby/log/gui/replay_controls.rb', line 9

def bookmarks_start_mark
  @bookmarks_start_mark
end

#replayObject (readonly)

Returns the value of attribute replay.



4
5
6
# File 'lib/roby/log/gui/replay_controls.rb', line 4

def replay
  @replay
end

Instance Method Details

#handleGotoObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/roby/log/gui/replay_controls.rb', line 166

def handleGoto
	user_time = begin
			user_time = Qt::InputDialog.get_text nil, 'Going to ...', 
	"<html><b>Go to time</b><ul><li>use \'+\' for a relative jump forward</li><li>'-' for a relative jump backwards</li></ul></html>", 
	Qt::LineEdit::Normal, (user_time || @last_goto || "")
			return unless user_time && !user_time.empty?

			@last_goto = user_time
			if user_time =~ /^\s*([\+\-@])(.*)/
   op = $1
   user_time = $2
			end
			user_time = Time.from_hms(user_time)

  rescue ArgumentError
			Qt::MessageBox.warning nil, "Invalid user_time", "Invalid user_time: #{$!.message}", "OK"
			retry
  end

	unless replay.first_sample
 replay.seek(nil)
	end

	user_time = if !op
			replay.first_sample + (user_time - Time.at(0))
  elsif op != "@"
			replay.time.send(op, user_time - Time.at(0))
  else
			user_time
  end

	replay.seek(user_time)
end

#load_bookmarks(file = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/roby/log/gui/replay_controls.rb', line 13

def load_bookmarks(file = nil)
	file ||= Qt::FileDialog.get_open_file_name replay, "Load bookmarks"
	unless !file || file.empty?
 replay.bookmarks.clear

 list = File.open(file) { |io| YAML.load(io) }
 list.each do |name, times|
		replay.bookmarks[name] = times.map { |t| Time.from_hms(t) if t }
 end
 update_bookmarks_menu

 @bookmarks_file = file
 actionBookmarksSave.enabled = true
	end
end

#save_bookmarksObject



38
39
40
41
42
43
44
45
46
# File 'lib/roby/log/gui/replay_controls.rb', line 38

def save_bookmarks
	data = replay.bookmarks.inject(Hash.new) do |data, (name, times)|
 data[name] = times.map { |t| t.to_hms if t }
 data
	end
	File.open(bookmarks_file, 'w') do |io|
 YAML.dump(data, io)
	end
end

#save_bookmarks_asObject



29
30
31
32
33
34
35
36
# File 'lib/roby/log/gui/replay_controls.rb', line 29

def save_bookmarks_as
	file = Qt::FileDialog.get_save_file_name replay, "Save bookmarks"
	unless !file || file.empty?
 @bookmarks_file = file
 actionBookmarksSave.enabled = true
 save_bookmarks
	end
end

#setupUi(replay, widget) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/roby/log/gui/replay_controls.rb', line 85

def setupUi(replay, widget)
	@replay = replay
	super(widget)

	@bookmarks_actions = []
	bookmarks.menu = @bookmarks_menu = Qt::Menu.new
	bookmarks_menu.add_action actionBookmarksSave
	bookmarks_menu.add_action actionBookmarksSaveAs
	bookmarks_menu.add_action actionBookmarksLoad
	bookmarks_menu.add_separator
	bookmarks_menu.add_action actionBookmarksSetMark
	bookmarks_menu.add_action actionBookmarksAdd
	bookmarks_menu.add_separator
	actionBookmarksLoad.connect(SIGNAL(:triggered)) { load_bookmarks }
	actionBookmarksSaveAs.connect(SIGNAL(:triggered)) { save_bookmarks_as }
	actionBookmarksSave.connect(SIGNAL(:triggered)) { save_bookmarks }
	actionBookmarksSetMark.connect(SIGNAL(:triggered)) do
 @bookmarks_start_mark = replay.time
 update_bookmarks_menu
	end
	actionBookmarksAdd.connect(SIGNAL(:triggered)) do
 new_name = Qt::InputDialog.get_text widget, "New bookmark", "Name: "
 unless new_name && new_name.empty?
		replay.bookmarks[new_name] = [bookmarks_start_mark, replay.time]
		update_bookmarks_menu
 end
	end
	update_bookmarks_menu

	goto.connect(SIGNAL(:clicked)) do
 handleGoto
	end
	shortcut = Qt::Shortcut.new(KEY_GOTO, widget)
	shortcut.context = Qt::ApplicationShortcut
	shortcut.connect(SIGNAL(:activated)) do
 handleGoto
	end

	seek_start.connect(SIGNAL(:clicked)) do
 replay.seek(nil)
	end
	faster.connect(SIGNAL('clicked()')) do
 speed = replay.play_speed
 factor = speed < 1 ? 10 : 1
 speed = Float(Integer(factor * speed) + 1.0) / factor
 slower.enabled = (speed > 0.1)
 replay.play_speed = speed
	end
	slower.connect(SIGNAL('clicked()')) do
 speed = replay.play_speed
 factor = speed <= 1 ? 10 : 1
 speed = Float(Integer(factor * speed) - 1.0) / factor
 slower.enabled = (speed > 0.1)
 replay.play_speed = speed
	end
	speed.connect(SIGNAL('editingFinished()')) do
 begin
		new_speed = Float(speed.text)
		if new_speed <= 0
  raise ArgumentError, "negative values are not allowed for speed"
		end
		replay.play_speed = new_speed
 rescue ArgumentError
		Qt::MessageBox.warning nil, "Invalid speed", "Invalid value for speed \"#{ui_controls.speed.text}\": #{$!.message}"
		self.play_speed = play_speed
 end
	end

	play.connect(SIGNAL("clicked()")) do
 if play.checked?
		replay.play
 else
		replay.stop
 end
 seek_start.enabled = play_step.enabled = !play.checked?
	end
	play_step.connect(SIGNAL("clicked()")) do
 replay.play_step
	end
end

#update_bookmarks_menuObject



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
82
83
# File 'lib/roby/log/gui/replay_controls.rb', line 49

def update_bookmarks_menu
	bookmarks_actions.each do |action|
 bookmarks_menu.remove_action action
	end
	bookmarks_actions.clear

	bookmarks = replay.bookmarks.sort_by { |name, time| time }
	bookmarks.unshift(["Mark", [bookmarks_start_mark, nil]]) if bookmarks_start_mark

	bookmarks.each do |name, range|
 start_time, end_time = if replay.first_sample
       # Handle sub-millisecond rounding effects
       range.map do |t| 
	   if t
	       ((t - replay.first_sample) * 1000).round / 1000.0
	   end
       end
   else 
       range.map { |t| t.to_hms if t }
   end

 display = if start_time && end_time
 "#{start_time} - #{end_time}"
    else
 (start_time || end_time).to_s
    end

 action = Qt::Action.new "#{name} (#{display})", bookmarks_menu
 action.connect(SIGNAL(:triggered)) do
		range.each { |t| replay.seek(t) if t }
 end
 bookmarks_actions << action
 bookmarks_menu.add_action action
	end
end