topic_message_view.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 from .message_view import MessageView
33 
34 from python_qt_binding.QtGui import QIcon
35 from python_qt_binding.QtWidgets import QAction, QToolBar
36 
37 
38 class TopicMessageView(MessageView):
39 
40  """
41  A message view with a toolbar for navigating messages in a single topic.
42  """
43 
44  def __init__(self, timeline, parent, topic):
45  MessageView.__init__(self, timeline, topic)
46 
47  self._parent = parent
48  self._stamp = None
49  self._name = parent.objectName()
50 
51  self.toolbar = QToolBar()
52  self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar)
53  self._first_action.triggered.connect(self.navigate_first)
54  self.toolbar.addAction(self._first_action)
55  self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar)
56  self._prev_action.triggered.connect(self.navigate_previous)
57  self.toolbar.addAction(self._prev_action)
58  self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar)
59  self._next_action.triggered.connect(self.navigate_next)
60  self.toolbar.addAction(self._next_action)
61  self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar)
62  self._last_action.triggered.connect(self.navigate_last)
63  self.toolbar.addAction(self._last_action)
64  parent.layout().addWidget(self.toolbar)
65 
66  @property
67  def parent(self):
68  return self._parent
69 
70  @property
71  def stamp(self):
72  return self._stamp
73 
74  # MessageView implementation
75 
76  def message_viewed(self, bag, msg_details):
77  _, _, self._stamp = msg_details[:3]
78 
79  # Events
80  def navigate_first(self):
81  for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region):
82  self.timeline._timeline_frame.playhead = entry.time
83  break
84 
85  def navigate_previous(self):
86  last_entry = None
87  for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead):
88  if entry.time < self.timeline._timeline_frame.playhead:
89  last_entry = entry
90 
91  if last_entry:
92  self.timeline._timeline_frame.playhead = last_entry.time
93 
94  def navigate_next(self):
95  for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp):
96  if entry.time > self.timeline._timeline_frame.playhead:
97  self.timeline._timeline_frame.playhead = entry.time
98  break
99 
100  def navigate_last(self):
101  last_entry = None
102  for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region):
103  last_entry = entry
104 
105  if last_entry:
106  self.timeline._timeline_frame.playhead = last_entry.time


rqt_bag
Author(s): Aaron Blasdel, Tim Field
autogenerated on Fri Jun 7 2019 22:05:54