39 from python_qt_binding
import loadUi
40 from python_qt_binding.QtCore
import qDebug, QFileInfo, Qt, qWarning, Signal
41 from python_qt_binding.QtGui
import QIcon, QResizeEvent
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 last_open_dir = os.getcwd()
64 set_status_text = Signal(str)
68 :param context: plugin context hook to enable adding widgets as a ROS_GUI pane, ''PluginContext'' 72 ui_file = os.path.join(rp.get_path(
'rqt_bag'),
'resource',
'bag_widget.ui')
73 loadUi(ui_file, self, {
'BagGraphicsView': BagGraphicsView})
75 self.setObjectName(
'BagWidget')
77 self.
_timeline = BagTimeline(context, publish_clock)
78 self.graphics_view.setScene(self.
_timeline)
81 self.graphics_view.setMouseTracking(
True)
83 self.
play_icon = QIcon.fromTheme(
'media-playback-start')
84 self.
pause_icon = QIcon.fromTheme(
'media-playback-pause')
86 self.begin_button.setIcon(QIcon.fromTheme(
'media-skip-backward'))
87 self.end_button.setIcon(QIcon.fromTheme(
'media-skip-forward'))
88 self.slower_button.setIcon(QIcon.fromTheme(
'media-seek-backward'))
89 self.faster_button.setIcon(QIcon.fromTheme(
'media-seek-forward'))
90 self.previous_button.setIcon(QIcon.fromTheme(
'go-previous'))
91 self.next_button.setIcon(QIcon.fromTheme(
'go-next'))
92 self.zoom_in_button.setIcon(QIcon.fromTheme(
'zoom-in'))
93 self.zoom_out_button.setIcon(QIcon.fromTheme(
'zoom-out'))
94 self.zoom_all_button.setIcon(QIcon.fromTheme(
'zoom-original'))
95 self.thumbs_button.setIcon(QIcon.fromTheme(
'insert-image'))
96 self.record_button.setIcon(QIcon.fromTheme(
'media-record'))
97 self.load_button.setIcon(QIcon.fromTheme(
'document-open'))
98 self.save_button.setIcon(QIcon.fromTheme(
'document-save'))
114 self.graphics_view.mousePressEvent = self._timeline.on_mouse_down
115 self.graphics_view.mouseReleaseEvent = self._timeline.on_mouse_up
116 self.graphics_view.mouseMoveEvent = self._timeline.on_mouse_move
117 self.graphics_view.wheelEvent = self._timeline.on_mousewheel
125 self.play_button.setEnabled(
False)
126 self.thumbs_button.setEnabled(
False)
127 self.zoom_in_button.setEnabled(
False)
128 self.zoom_out_button.setEnabled(
False)
129 self.zoom_all_button.setEnabled(
False)
130 self.previous_button.setEnabled(
False)
131 self.next_button.setEnabled(
False)
132 self.faster_button.setEnabled(
False)
133 self.slower_button.setEnabled(
False)
134 self.begin_button.setEnabled(
False)
135 self.end_button.setEnabled(
False)
136 self.save_button.setEnabled(
False)
145 if key
in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown):
151 QGraphicsView.keyPressEvent(self.graphics_view, event)
156 if key == Qt.Key_Space:
157 self._timeline.toggle_play()
158 elif key == Qt.Key_Home:
159 self._timeline.navigate_start()
160 elif key == Qt.Key_End:
162 elif key == Qt.Key_Plus
or key == Qt.Key_Equal:
164 elif key == Qt.Key_Minus:
166 elif key == Qt.Key_Left:
167 self._timeline.translate_timeline_left()
168 elif key == Qt.Key_Right:
169 self._timeline.translate_timeline_right()
170 elif key == Qt.Key_Up
or key == Qt.Key_PageUp:
172 elif key == Qt.Key_Down
or key == Qt.Key_PageDown:
176 self._timeline.handle_close()
188 self.graphics_view.scene().setSceneRect(
189 0, 0, self.graphics_view.width() - 2,
190 max(self.graphics_view.height() - 2, self._timeline._timeline_frame._history_bottom))
193 self._timeline.set_publishing_state(checked)
198 self._timeline.navigate_play()
201 self._timeline.navigate_stop()
204 self._timeline.navigate_next()
205 self.play_button.setChecked(
False)
209 self._timeline.navigate_previous()
210 self.play_button.setChecked(
False)
214 self._timeline.navigate_fastforward()
215 self.play_button.setChecked(
True)
219 self._timeline.navigate_rewind()
220 self.play_button.setChecked(
True)
224 self._timeline.navigate_start()
227 self._timeline.navigate_end()
230 self._timeline._timeline_frame.toggle_renderers()
233 self._timeline.reset_zoom()
236 self._timeline.zoom_out()
239 self._timeline.zoom_in()
243 self._timeline.toggle_recording()
254 proposed_filename = time.strftime(
'%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
255 filename = QFileDialog.getSaveFileName(
256 self, self.tr(
'Select name for new bag'), proposed_filename, self.tr(
'Bag files {.bag} (*.bag)'))[0]
259 filename = filename.strip()
260 if not filename.endswith(
'.bag'):
264 self.load_button.setEnabled(
False)
266 self._timeline.record_bag(filename, all_topics, selected_topics)
269 filenames = QFileDialog.getOpenFileNames(
270 self, self.tr(
'Load from Files'), self.
last_open_dir, self.tr(
'Bag files {.bag} (*.bag)'))
271 if filenames
and filenames[0]:
272 self.
last_open_dir = QFileInfo(filenames[0][0]).absoluteDir().absolutePath()
273 for filename
in filenames[0]:
279 self._timeline._timeline_frame._layout()
280 self.
_resizeEvent(QResizeEvent(self.size(), self.size()))
283 qDebug(
"Loading '%s'..." % filename.encode(errors=
'replace'))
289 self.set_status_text.emit(
"Loading '%s'..." % filename)
297 self.play_button.setEnabled(
True)
298 self.thumbs_button.setEnabled(
True)
299 self.zoom_in_button.setEnabled(
True)
300 self.zoom_out_button.setEnabled(
True)
301 self.zoom_all_button.setEnabled(
True)
302 self.next_button.setEnabled(
True)
303 self.previous_button.setEnabled(
True)
304 self.faster_button.setEnabled(
True)
305 self.slower_button.setEnabled(
True)
306 self.begin_button.setEnabled(
True)
307 self.end_button.setEnabled(
True)
308 self.save_button.setEnabled(
True)
309 self.record_button.setEnabled(
False)
310 self._timeline.add_bag(bag)
311 qDebug(
"Done loading '%s'" % filename.encode(errors=
'replace'))
313 self.set_status_text.emit(
"")
315 self._timeline.reset_zoom()
316 except rosbag.ROSBagException
as e:
317 qWarning(
"Loading '%s' failed due to: %s" % (filename.encode(errors=
'replace'), e))
318 self.set_status_text.emit(
"Loading '%s' failed due to: %s" % (filename, e))
327 proposed_filename = time.strftime(
'%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
328 filename = QFileDialog.getSaveFileName(
329 self, self.tr(
'Save selected region...'), proposed_filename, self.tr(
'Bag files {.bag} (*.bag)'))[0]
331 filename = filename.strip()
332 if not filename.endswith(
'.bag'):
336 self._timeline.copy_region_to_bag(filename)
340 self.progress_bar.setFormat(text)
341 self.progress_bar.setTextVisible(
True)
343 self.progress_bar.setTextVisible(
False)
346 if self._timeline._timeline_frame.playhead
is None or self._timeline._timeline_frame.start_stamp
is None:
352 self.progress_bar.setValue(self._timeline.background_progress)
355 self.stamp_label.setText(
'%.9fs' % self._timeline._timeline_frame.playhead.to_sec())
358 self.date_label.setText(
359 bag_helper.stamp_to_str(self._timeline._timeline_frame.playhead))
362 self.seconds_label.setText(
364 self._timeline._timeline_frame.playhead - self._timeline._timeline_frame.start_stamp).to_sec())
367 self.filesize_label.setText(bag_helper.filesize_to_str(self._timeline.file_size()))
370 spd = self._timeline.play_speed
373 spd_str =
'>> %.0fx' % spd
377 spd_str =
'> 1/%.0fx' % (1.0 / spd)
379 spd_str =
'< 1/%.0fx' % (1.0 / -spd)
383 spd_str =
'<< %.0fx' % -spd
384 self.playspeed_label.setText(spd_str)
386 self.playspeed_label.setText(
'')
392 self._timeline.handle_close()