timeline_menu.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2009, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 from python_qt_binding.QtGui import QVBoxLayout, QMenu, QWidget
00034 
00035 
00036 class TimelinePopupMenu(QMenu):
00037     """
00038     Custom popup menu displayed on rightclick from timeline
00039     """
00040     def __init__(self, timeline, event):
00041         super(TimelinePopupMenu, self).__init__()
00042 
00043         self.parent = timeline
00044         self.timeline = timeline
00045 
00046         self._reset_timeline = self.addAction('Reset Timeline')
00047 
00048         self._play_all = self.addAction('Play All Messages')
00049         self._play_all.setCheckable(True)
00050         self._play_all.setChecked(self.timeline.play_all)
00051 
00052         self.addSeparator()
00053 
00054         submenu = self.addMenu('Thumbnails...')
00055         self._thumbnail_show_action = submenu.addAction('Show All')
00056         self._thumbnail_hide_action = submenu.addAction('Hide All')
00057         submenu.addSeparator()
00058 
00059         self._renderers = self.timeline._timeline_frame.get_renderers()
00060         self._thumbnail_actions = []
00061         for topic, renderer in self._renderers:
00062             self._thumbnail_actions.append(submenu.addAction(topic))
00063             self._thumbnail_actions[-1].setCheckable(True)
00064             self._thumbnail_actions[-1].setChecked(self.timeline._timeline_frame.is_renderer_active(topic))
00065 
00066         self._topics = self.timeline._timeline_frame.topics
00067         view_topics_menu = self.addMenu('View (by Topic)')
00068         self._topic_actions = []
00069         for topic in self._topics:
00070             datatype = self.timeline.get_datatype(topic)
00071 
00072             # View... / topic
00073             topic_menu = QMenu(topic, self)
00074             viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
00075 
00076             # View... / topic / Viewer
00077             for viewer_type in viewer_types:
00078                 tempaction = topic_menu.addAction(viewer_type.name)
00079                 tempaction.setData(viewer_type)
00080                 self._topic_actions.append(tempaction)
00081             view_topics_menu.addMenu(topic_menu)
00082 
00083         view_type_menu = self.addMenu('View (by Type)')
00084         self._topics_by_type = self.timeline._timeline_frame._topics_by_datatype
00085         self._type_actions = []
00086         for datatype in self._topics_by_type:
00087             # View... / datatype
00088             datatype_menu = QMenu(datatype, self)
00089             datatype_topics = self._topics_by_type[datatype]
00090             viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
00091             for topic in [t for t in self._topics if t in datatype_topics]:   # use timeline ordering
00092                 topic_menu = QMenu(topic, datatype_menu)
00093                 # View... / datatype / topic / Viewer
00094                 for viewer_type in viewer_types:
00095                     tempaction = topic_menu.addAction(viewer_type.name)
00096                     tempaction.setData(viewer_type)
00097                     self._topic_actions.append(tempaction)
00098                 datatype_menu.addMenu(topic_menu)
00099             view_type_menu.addMenu(datatype_menu)
00100 
00101         self.addSeparator()
00102         submenu = self.addMenu('Publish...')
00103 
00104         self._publish_all = submenu.addAction('Publish All')
00105         self._publish_none = submenu.addAction('Publish None')
00106         submenu.addSeparator()
00107 
00108         self._publish_actions = []
00109         for topic in self._topics:
00110             self._publish_actions.append(submenu.addAction(topic))
00111             self._publish_actions[-1].setCheckable(True)
00112             self._publish_actions[-1].setChecked(self.timeline.is_publishing(topic))
00113 
00114         action = self.exec_(event.globalPos())
00115         if action is not None and action != 0:
00116             self.process(action)
00117 
00118     def process(self, action):
00119         """
00120         :param action: action to execute, ''QAction''
00121         :raises: when it doesn't recognice the action passed in, ''Exception''
00122         """
00123         if action == self._reset_timeline:
00124             self.timeline._timeline_frame.reset_timeline()
00125         elif action == self._play_all:
00126             self.timeline.toggle_play_all()
00127         elif action == self._publish_all:
00128             for topic in self.timeline._timeline_frame.topics:
00129                 if not self.timeline.start_publishing(topic):
00130                     break
00131         elif action == self._publish_none:
00132             for topic in self.timeline._timeline_frame.topics:
00133                 if not self.timeline.stop_publishing(topic):
00134                     break
00135         elif action == self._thumbnail_show_action:
00136             self.timeline._timeline_frame.set_renderers_active(True)
00137         elif action == self._thumbnail_hide_action:
00138             self.timeline._timeline_frame.set_renderers_active(False)
00139         elif action in self._thumbnail_actions:
00140             if self.timeline._timeline_frame.is_renderer_active(action.text()):
00141                 self.timeline._timeline_frame.set_renderer_active(action.text(), False)
00142             else:
00143                 self.timeline._timeline_frame.set_renderer_active(action.text(), True)
00144         elif action in self._topic_actions + self._type_actions:
00145             popup_name = action.parentWidget().title() + '__' + action.text()
00146             if popup_name not in self.timeline.popups:
00147                 frame = QWidget()
00148                 layout = QVBoxLayout()
00149                 frame.setLayout(layout)
00150                 frame.resize(640, 480)
00151                 viewer_type = action.data()
00152                 frame.setObjectName(popup_name)
00153                 view = viewer_type(self.timeline, frame)
00154                 self.timeline.popups.add(popup_name)
00155                 self.timeline.get_context().add_widget(frame)
00156                 self.timeline.add_view(action.parentWidget().title(), view, frame)
00157                 frame.show()
00158         elif action in self._publish_actions:
00159             if self.timeline.is_publishing(action.text()):
00160                 self.timeline.stop_publishing(action.text())
00161             else:
00162                 self.timeline.start_publishing(action.text())
00163         else:
00164             raise Exception('Unknown action in TimelinePopupMenu.process')


rqt_bag
Author(s): Aaron Blasdel
autogenerated on Fri Jan 3 2014 11:55:06