Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 from .message_view import MessageView
00033
00034 from python_qt_binding.QtGui import QAction, QIcon, QToolBar
00035
00036
00037 class TopicMessageView(MessageView):
00038 """
00039 A message view with a toolbar for navigating messages in a single topic.
00040 """
00041 def __init__(self, timeline, parent):
00042 MessageView.__init__(self, timeline)
00043
00044 self._parent = parent
00045 self._topic = None
00046 self._stamp = None
00047 self._name = parent.objectName()
00048 self.parent.destroyed.connect(self._on_close)
00049
00050 self.toolbar = QToolBar()
00051 self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar)
00052 self._first_action.triggered.connect(self.navigate_first)
00053 self.toolbar.addAction(self._first_action)
00054 self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar)
00055 self._prev_action.triggered.connect(self.navigate_previous)
00056 self.toolbar.addAction(self._prev_action)
00057 self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar)
00058 self._next_action.triggered.connect(self.navigate_next)
00059 self.toolbar.addAction(self._next_action)
00060 self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar)
00061 self._last_action.triggered.connect(self.navigate_last)
00062 self.toolbar.addAction(self._last_action)
00063 parent.layout().addWidget(self.toolbar)
00064
00065 @property
00066 def parent(self):
00067 return self._parent
00068
00069 @property
00070 def topic(self):
00071 return self._topic
00072
00073 @property
00074 def stamp(self):
00075 return self._stamp
00076
00077
00078
00079 def message_viewed(self, bag, msg_details):
00080 self._topic, _, self._stamp = msg_details[:3]
00081
00082
00083 def _on_close(self):
00084
00085 if self._topic:
00086 self.timeline.popups.remove(self._name)
00087 self.timeline.remove_view(self._topic, self)
00088
00089 def navigate_first(self):
00090 if not self.topic:
00091 return
00092
00093 for entry in self.timeline.get_entries(self._topic, *self.timeline._timeline_frame.play_region):
00094 self.timeline._timeline_frame.playhead = entry.time
00095 break
00096
00097 def navigate_previous(self):
00098 if not self.topic:
00099 return
00100
00101 last_entry = None
00102 for entry in self.timeline.get_entries(self._topic, self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead):
00103 if entry.time < self.timeline._timeline_frame.playhead:
00104 last_entry = entry
00105
00106 if last_entry:
00107 self.timeline._timeline_frame.playhead = last_entry.time
00108
00109 def navigate_next(self):
00110 if not self.topic:
00111 return
00112
00113 for entry in self.timeline.get_entries(self._topic, self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp):
00114 if entry.time > self.timeline._timeline_frame.playhead:
00115 self.timeline._timeline_frame.playhead = entry.time
00116 break
00117
00118 def navigate_last(self):
00119 if not self.topic:
00120 return
00121
00122 last_entry = None
00123 for entry in self.timeline.get_entries(self._topic, *self.timeline._timeline_frame.play_region):
00124 last_entry = entry
00125
00126 if last_entry:
00127 self.timeline._timeline_frame.playhead = last_entry.time