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
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
00073 topic_menu = QMenu(topic, self)
00074 viewer_types = self.timeline._timeline_frame.get_viewer_types(datatype)
00075
00076
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
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]:
00092 topic_menu = QMenu(topic, datatype_menu)
00093
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')