39 from python_qt_binding
import loadUi
40 from python_qt_binding.QtCore
import qDebug, Qt, qWarning, Signal
41 from python_qt_binding.QtGui
import QIcon
42 from python_qt_binding.QtWidgets
import QFileDialog, QGraphicsView, QWidget
45 from rqt_bag
import bag_helper
46 from .bag_timeline
import BagTimeline
47 from .topic_selection
import TopicSelection
53 super(BagGraphicsView, self).
__init__()
59 Widget for use with Bag class to display and replay bag files 60 Handles all widget callbacks and contains the instance of BagTimeline for storing visualizing bag data 63 set_status_text = Signal(str)
67 :param context: plugin context hook to enable adding widgets as a ROS_GUI pane, ''PluginContext'' 71 ui_file = os.path.join(rp.get_path(
'rqt_bag'),
'resource',
'bag_widget.ui')
72 loadUi(ui_file, self, {
'BagGraphicsView': BagGraphicsView})
74 self.setObjectName(
'BagWidget')
76 self.
_timeline = BagTimeline(context, publish_clock)
77 self.graphics_view.setScene(self.
_timeline)
80 self.graphics_view.setMouseTracking(
True)
82 self.
play_icon = QIcon.fromTheme(
'media-playback-start')
83 self.
pause_icon = QIcon.fromTheme(
'media-playback-pause')
85 self.begin_button.setIcon(QIcon.fromTheme(
'media-skip-backward'))
86 self.end_button.setIcon(QIcon.fromTheme(
'media-skip-forward'))
87 self.slower_button.setIcon(QIcon.fromTheme(
'media-seek-backward'))
88 self.faster_button.setIcon(QIcon.fromTheme(
'media-seek-forward'))
89 self.previous_button.setIcon(QIcon.fromTheme(
'go-previous'))
90 self.next_button.setIcon(QIcon.fromTheme(
'go-next'))
91 self.zoom_in_button.setIcon(QIcon.fromTheme(
'zoom-in'))
92 self.zoom_out_button.setIcon(QIcon.fromTheme(
'zoom-out'))
93 self.zoom_all_button.setIcon(QIcon.fromTheme(
'zoom-original'))
94 self.thumbs_button.setIcon(QIcon.fromTheme(
'insert-image'))
95 self.record_button.setIcon(QIcon.fromTheme(
'media-record'))
96 self.load_button.setIcon(QIcon.fromTheme(
'document-open'))
97 self.save_button.setIcon(QIcon.fromTheme(
'document-save'))
113 self.graphics_view.mousePressEvent = self._timeline.on_mouse_down
114 self.graphics_view.mouseReleaseEvent = self._timeline.on_mouse_up
115 self.graphics_view.mouseMoveEvent = self._timeline.on_mouse_move
116 self.graphics_view.wheelEvent = self._timeline.on_mousewheel
124 self.play_button.setEnabled(
False)
125 self.thumbs_button.setEnabled(
False)
126 self.zoom_in_button.setEnabled(
False)
127 self.zoom_out_button.setEnabled(
False)
128 self.zoom_all_button.setEnabled(
False)
129 self.previous_button.setEnabled(
False)
130 self.next_button.setEnabled(
False)
131 self.faster_button.setEnabled(
False)
132 self.slower_button.setEnabled(
False)
133 self.begin_button.setEnabled(
False)
134 self.end_button.setEnabled(
False)
135 self.save_button.setEnabled(
False)
144 if key
in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown):
150 QGraphicsView.keyPressEvent(self.graphics_view, event)
155 if key == Qt.Key_Space:
156 self._timeline.toggle_play()
157 elif key == Qt.Key_Home:
158 self._timeline.navigate_start()
159 elif key == Qt.Key_End:
161 elif key == Qt.Key_Plus
or key == Qt.Key_Equal:
163 elif key == Qt.Key_Minus:
165 elif key == Qt.Key_Left:
166 self._timeline.translate_timeline_left()
167 elif key == Qt.Key_Right:
168 self._timeline.translate_timeline_right()
169 elif key == Qt.Key_Up
or key == Qt.Key_PageUp:
171 elif key == Qt.Key_Down
or key == Qt.Key_PageDown:
175 self._timeline.handle_close()
187 self.graphics_view.scene().setSceneRect(
188 0, 0, self.graphics_view.width() - 2,
189 max(self.graphics_view.height() - 2, self._timeline._timeline_frame._history_bottom))
192 self._timeline.set_publishing_state(checked)
197 self._timeline.navigate_play()
200 self._timeline.navigate_stop()
203 self._timeline.navigate_next()
204 self.play_button.setChecked(
False)
208 self._timeline.navigate_previous()
209 self.play_button.setChecked(
False)
213 self._timeline.navigate_fastforward()
214 self.play_button.setChecked(
True)
218 self._timeline.navigate_rewind()
219 self.play_button.setChecked(
True)
223 self._timeline.navigate_start()
226 self._timeline.navigate_end()
229 self._timeline._timeline_frame.toggle_renderers()
232 self._timeline.reset_zoom()
235 self._timeline.zoom_out()
238 self._timeline.zoom_in()
242 self._timeline.toggle_recording()
251 filename = QFileDialog.getSaveFileName(
252 self, self.tr(
'Select prefix for new Bag File'),
'.', self.tr(
'Bag files {.bag} (*.bag)'))
253 if filename[0] !=
'':
254 prefix = filename[0].strip()
257 record_filename = time.strftime(
'%Y-%m-%d-%H-%M-%S.bag', time.localtime(time.time()))
258 if prefix.endswith(
'.bag'):
259 prefix = prefix[:-len(
'.bag')]
261 record_filename =
'%s_%s' % (prefix, record_filename)
263 rospy.loginfo(
'Recording to %s.' % record_filename)
265 self.load_button.setEnabled(
False)
267 self._timeline.record_bag(record_filename, all_topics, selected_topics)
270 filenames = QFileDialog.getOpenFileNames(
271 self, self.tr(
'Load from Files'),
'.', self.tr(
'Bag files {.bag} (*.bag)'))
272 for filename
in filenames[0]:
276 qDebug(
"Loading '%s'..." % filename.encode(errors=
'replace'))
282 self.set_status_text.emit(
"Loading '%s'..." % filename)
290 self.play_button.setEnabled(
True)
291 self.thumbs_button.setEnabled(
True)
292 self.zoom_in_button.setEnabled(
True)
293 self.zoom_out_button.setEnabled(
True)
294 self.zoom_all_button.setEnabled(
True)
295 self.next_button.setEnabled(
True)
296 self.previous_button.setEnabled(
True)
297 self.faster_button.setEnabled(
True)
298 self.slower_button.setEnabled(
True)
299 self.begin_button.setEnabled(
True)
300 self.end_button.setEnabled(
True)
301 self.save_button.setEnabled(
True)
302 self.record_button.setEnabled(
False)
303 self._timeline.add_bag(bag)
304 qDebug(
"Done loading '%s'" % filename.encode(errors=
'replace'))
306 self.set_status_text.emit(
"")
307 except rosbag.ROSBagException
as e:
308 qWarning(
"Loading '%s' failed due to: %s" % (filename.encode(errors=
'replace'), e))
309 self.set_status_text.emit(
"Loading '%s' failed due to: %s" % (filename, e))
317 filename = QFileDialog.getSaveFileName(
318 self, self.tr(
'Save selected region to file...'),
'.', self.tr(
'Bag files {.bag} (*.bag)'))
319 if filename[0] !=
'':
320 self._timeline.copy_region_to_bag(filename[0])
324 self.progress_bar.setFormat(text)
325 self.progress_bar.setTextVisible(
True)
327 self.progress_bar.setTextVisible(
False)
330 if self._timeline._timeline_frame.playhead
is None or self._timeline._timeline_frame.start_stamp
is None:
336 self.progress_bar.setValue(self._timeline.background_progress)
339 self.stamp_label.setText(
'%.3fs' % self._timeline._timeline_frame.playhead.to_sec())
342 self.date_label.setText(
343 bag_helper.stamp_to_str(self._timeline._timeline_frame.playhead))
346 self.seconds_label.setText(
348 self._timeline._timeline_frame.playhead - self._timeline._timeline_frame.start_stamp).to_sec())
351 self.filesize_label.setText(bag_helper.filesize_to_str(self._timeline.file_size()))
354 spd = self._timeline.play_speed
357 spd_str =
'>> %.0fx' % spd
361 spd_str =
'> 1/%.0fx' % (1.0 / spd)
363 spd_str =
'< 1/%.0fx' % (1.0 / -spd)
367 spd_str =
'<< %.0fx' % -spd
368 self.playspeed_label.setText(spd_str)
370 self.playspeed_label.setText(
'')
376 self._timeline.handle_close()