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 try: # indigo
36  from python_qt_binding.QtGui import QAction, QToolBar
37 except ImportError: # kinetic+ (pyqt5)
38  from python_qt_binding.QtWidgets import QAction, QToolBar
39 
40 
41 class TopicMessageView(MessageView):
42  """
43  A message view with a toolbar for navigating messages in a single topic.
44  """
45  def __init__(self, timeline, parent, topic):
46  MessageView.__init__(self, timeline, topic)
47 
48  self._parent = parent
49  self._stamp = None
50  self._name = parent.objectName()
51 
52  self.toolbar = QToolBar()
53  self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar)
54  self._first_action.triggered.connect(self.navigate_first)
55  self.toolbar.addAction(self._first_action)
56  self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar)
57  self._prev_action.triggered.connect(self.navigate_previous)
58  self.toolbar.addAction(self._prev_action)
59  self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar)
60  self._next_action.triggered.connect(self.navigate_next)
61  self.toolbar.addAction(self._next_action)
62  self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar)
63  self._last_action.triggered.connect(self.navigate_last)
64  self.toolbar.addAction(self._last_action)
65  parent.layout().addWidget(self.toolbar)
66 
67  @property
68  def parent(self):
69  return self._parent
70 
71  @property
72  def stamp(self):
73  return self._stamp
74 
75  # MessageView implementation
76 
77  def message_viewed(self, bag, msg_details):
78  _, _, self._stamp = msg_details[:3]
79 
80  # Events
81  def navigate_first(self):
82  for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region):
83  self.timeline._timeline_frame.playhead = entry.time
84  break
85 
86  def navigate_previous(self):
87  last_entry = None
88  for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead):
89  if entry.time < self.timeline._timeline_frame.playhead:
90  last_entry = entry
91 
92  if last_entry:
93  self.timeline._timeline_frame.playhead = last_entry.time
94 
95  def navigate_next(self):
96  for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp):
97  if entry.time > self.timeline._timeline_frame.playhead:
98  self.timeline._timeline_frame.playhead = entry.time
99  break
100 
101  def navigate_last(self):
102  last_entry = None
103  for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region):
104  last_entry = entry
105 
106  if last_entry:
107  self.timeline._timeline_frame.playhead = last_entry.time


rqt_py_trees
Author(s): Thibault Kruse, Michal Staniaszek, Daniel Stonier, Naveed Usmani
autogenerated on Mon Jun 10 2019 14:55:56