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 import wx
00034
00035 from util.base_frame import BaseFrame
00036
00037 class TimelinePopupMenu(wx.Menu):
00038 """
00039 Timeline popup menu. Allows user to manipulate the timeline view, and open new message views.
00040 """
00041 def __init__(self, timeline):
00042 wx.Menu.__init__(self)
00043
00044 self.parent = timeline
00045 self.timeline = timeline
00046
00047
00048 self.reset_timeline_menu = wx.MenuItem(self, wx.NewId(), 'Reset Timeline')
00049 self.AppendItem(self.reset_timeline_menu)
00050 self.Bind(wx.EVT_MENU, lambda e: self.timeline.reset_timeline(), id=self.reset_timeline_menu.Id)
00051
00052
00053 self.play_all_menu = wx.MenuItem(self, wx.NewId(), 'Play All Messages', kind=wx.ITEM_CHECK)
00054 self.AppendItem(self.play_all_menu)
00055 self.play_all_menu.Check(self.timeline.play_all)
00056 self.Bind(wx.EVT_MENU, lambda e: self.timeline.toggle_play_all(), id=self.play_all_menu.Id)
00057
00058 topics = self.timeline.topics
00059
00060 if len(topics) == 0:
00061 return
00062
00063
00064 self.AppendSeparator()
00065
00066 renderers = self.timeline.get_renderers()
00067
00068
00069 if len(renderers) > 0:
00070 self.thumbnail_menu = wx.Menu()
00071 self.AppendSubMenu(self.thumbnail_menu, 'Thumbnails...', 'View message thumbnails')
00072
00073
00074 self.show_thumbnails_menu = wx.MenuItem(self.thumbnail_menu, wx.NewId(), 'Show All')
00075 self.thumbnail_menu.AppendItem(self.show_thumbnails_menu)
00076 self.thumbnail_menu.Bind(wx.EVT_MENU, lambda e: self.timeline.set_renderers_active(True), id=self.show_thumbnails_menu.Id)
00077
00078
00079 self.hide_thumbnails_menu = wx.MenuItem(self.thumbnail_menu, wx.NewId(), 'Hide All')
00080 self.thumbnail_menu.AppendItem(self.hide_thumbnails_menu)
00081 self.thumbnail_menu.Bind(wx.EVT_MENU, lambda e: self.timeline.set_renderers_active(False), id=self.hide_thumbnails_menu.Id)
00082
00083
00084 self.thumbnail_menu.AppendSeparator()
00085
00086
00087 for topic, renderer in renderers:
00088 renderer_item = self.TimelineRendererMenuItem(self.thumbnail_menu, wx.NewId(), topic.lstrip('/'), topic, renderer, self.timeline)
00089 self.thumbnail_menu.AppendItem(renderer_item)
00090
00091 renderer_item.Check(self.timeline.is_renderer_active(topic))
00092
00093
00094 self.view_topic_menu = wx.Menu()
00095 self.AppendSubMenu(self.view_topic_menu, 'View (by Topic)...', 'View message detail')
00096
00097 for topic in topics:
00098 datatype = self.timeline.get_datatype(topic)
00099
00100
00101 topic_menu = wx.Menu()
00102 self.view_topic_menu.AppendSubMenu(topic_menu, topic.lstrip('/'), topic)
00103
00104 viewer_types = self.timeline.get_viewer_types(datatype)
00105
00106
00107 for viewer_type in viewer_types:
00108 topic_menu.AppendItem(self.TopicViewMenuItem(topic_menu, wx.NewId(), viewer_type.name, topic, viewer_type, self.timeline))
00109
00110
00111 self.view_datatype_menu = wx.Menu()
00112 self.AppendSubMenu(self.view_datatype_menu, 'View (by Type)...', 'View message detail')
00113
00114 topics_by_datatype = self.timeline.topics_by_datatype
00115
00116 for datatype in sorted(topics_by_datatype):
00117
00118 datatype_menu = wx.Menu()
00119 self.view_datatype_menu.AppendSubMenu(datatype_menu, datatype, datatype)
00120
00121 datatype_topics = topics_by_datatype[datatype]
00122
00123 viewer_types = self.timeline.get_viewer_types(datatype)
00124
00125 for topic in [t for t in topics if t in datatype_topics]:
00126 topic_menu = wx.Menu()
00127 datatype_menu.AppendSubMenu(topic_menu, topic.lstrip('/'), topic)
00128
00129
00130 for viewer_type in viewer_types:
00131 topic_menu.AppendItem(self.TopicViewMenuItem(topic_menu, wx.NewId(), viewer_type.name, topic, viewer_type, self.timeline))
00132
00133
00134 self.AppendSeparator()
00135
00136
00137 self.publish_menu = wx.Menu()
00138 self.AppendSubMenu(self.publish_menu, 'Publish...', 'Publish Messages')
00139
00140
00141 self.publish_menu.AppendItem(self.PublishAllMenuItem(self.publish_menu, wx.NewId(), 'Publish All', True, self.timeline))
00142
00143
00144 self.publish_menu.AppendItem(self.PublishAllMenuItem(self.publish_menu, wx.NewId(), 'Publish None', False, self.timeline))
00145
00146
00147 self.publish_menu.AppendSeparator()
00148
00149 for topic in topics:
00150
00151 publish_topic_menu = self.PublishTopicMenuItem(self.publish_menu, wx.NewId(), topic, self.timeline)
00152 self.publish_menu.AppendItem(publish_topic_menu)
00153 publish_topic_menu.Check(self.timeline.is_publishing(topic))
00154
00155
00156 self.copy_region_menu = wx.MenuItem(self, wx.NewId(), 'Copy Region To Bag...')
00157 self.AppendItem(self.copy_region_menu)
00158 self.Bind(wx.EVT_MENU, lambda e: self.timeline.copy_region_to_bag(), id=self.copy_region_menu.Id)
00159 if self.timeline.selected_left is None or self.timeline.selected_right is None:
00160 self.copy_region_menu.Enable(False)
00161
00162 class PlayAllMenuItem(wx.MenuItem):
00163 def __init__(self, parent, id, label, timeline):
00164 wx.MenuItem.__init__(self, parent, id, label, kind=wx.ITEM_CHECK)
00165
00166 self.timeline = timeline
00167
00168 parent.Bind(wx.EVT_MENU, self.on_menu, id=self.Id)
00169
00170 def on_menu(self, event):
00171 self.timeline.play_all = not self.timeline.play_all
00172
00173 class TimelineRendererMenuItem(wx.MenuItem):
00174 def __init__(self, parent, id, label, topic, renderer, timeline):
00175 wx.MenuItem.__init__(self, parent, id, label, kind=wx.ITEM_CHECK)
00176
00177 self.topic = topic
00178 self.renderer = renderer
00179 self.timeline = timeline
00180
00181 parent.Bind(wx.EVT_MENU, self.on_menu, id=self.Id)
00182
00183 def on_menu(self, event):
00184 self.timeline.set_renderer_active(self.topic, not self.timeline.is_renderer_active(self.topic))
00185
00186 class TopicViewMenuItem(wx.MenuItem):
00187 def __init__(self, parent, id, label, topic, viewer_type, timeline):
00188 wx.MenuItem.__init__(self, parent, id, label)
00189
00190 self.topic = topic
00191 self.viewer_type = viewer_type
00192 self.timeline = timeline
00193
00194 parent.Bind(wx.EVT_MENU, self.on_menu, id=self.Id)
00195
00196 def on_menu(self, event):
00197 frame = BaseFrame(None, 'rxbag', self.topic, title='rxbag - %s [%s]' % (self.topic.lstrip('/'), self.viewer_type.name), pos=(4, 4), size=(640, 480))
00198 view = self.viewer_type(self.timeline, frame)
00199 self.timeline.add_view(self.topic, view)
00200 frame.Show()
00201
00202 class PublishTopicMenuItem(wx.MenuItem):
00203 def __init__(self, parent, id, topic, timeline):
00204 wx.MenuItem.__init__(self, parent, id, topic.lstrip('/'), kind=wx.ITEM_CHECK)
00205
00206 self.topic = topic
00207 self.timeline = timeline
00208
00209 parent.Bind(wx.EVT_MENU, self.on_menu, id=self.Id)
00210
00211 def on_menu(self, event):
00212 if self.timeline.is_publishing(self.topic):
00213 self.timeline.stop_publishing(self.topic)
00214 else:
00215 self.timeline.start_publishing(self.topic)
00216
00217 class PublishAllMenuItem(wx.MenuItem):
00218 def __init__(self, parent, id, label, start, timeline):
00219 wx.MenuItem.__init__(self, parent, id, label)
00220
00221 self.timeline = timeline
00222 self.start = start
00223
00224 parent.Bind(wx.EVT_MENU, self.on_menu, id=self.Id)
00225
00226 def on_menu(self, event):
00227 if self.start:
00228 for topic in self.timeline.topics:
00229 if not self.timeline.start_publishing(topic):
00230 break
00231 else:
00232 for topic in self.timeline.topics:
00233 self.timeline.stop_publishing(topic)