timeline_popup_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 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         # Reset Timeline
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         # Play All Messages
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         # Thumbnails...
00069         if len(renderers) > 0:
00070             self.thumbnail_menu = wx.Menu()
00071             self.AppendSubMenu(self.thumbnail_menu, 'Thumbnails...', 'View message thumbnails')
00072 
00073             # Thumbnails... / Show All
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             # Thumbnails... / Hide All
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             # Thumbnails... / ---
00084             self.thumbnail_menu.AppendSeparator()
00085 
00086             # Thumbnails... / topic
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         # View (by topic)...
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             # View... / topic
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             # View... / topic / Viewer
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         # View (by datatype)...
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             # View... / datatype
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]:   # use timeline ordering
00126                 topic_menu = wx.Menu()
00127                 datatype_menu.AppendSubMenu(topic_menu, topic.lstrip('/'), topic)
00128     
00129                 # View... / datatype / topic / Viewer
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         # Publish...       
00137         self.publish_menu = wx.Menu()
00138         self.AppendSubMenu(self.publish_menu, 'Publish...', 'Publish Messages')
00139 
00140         # Publish... / Publish All
00141         self.publish_menu.AppendItem(self.PublishAllMenuItem(self.publish_menu, wx.NewId(), 'Publish All',  True,  self.timeline))
00142 
00143         # Publish... / Publish None
00144         self.publish_menu.AppendItem(self.PublishAllMenuItem(self.publish_menu, wx.NewId(), 'Publish None', False, self.timeline))
00145 
00146         # Publish... / ---
00147         self.publish_menu.AppendSeparator()
00148 
00149         for topic in topics:
00150             # Publish... / topic
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         # Copy region to bag...
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)


rxbag
Author(s): Tim Field
autogenerated on Mon Oct 6 2014 07:26:07