$search
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 PKG = 'rxbag' 00034 import roslib; roslib.load_manifest(PKG) 00035 00036 import wx 00037 00038 class TimelineToolBar(wx.ToolBar): 00039 def __init__(self, parent, timeline): 00040 wx.ToolBar.__init__(self, parent, -1, style=wx.TB_TEXT) 00041 00042 self.timeline = timeline 00043 00044 self._state = None 00045 00046 self._setup() 00047 00048 def _setup(self): 00049 # If state of toolbar hasn't changed, don't recreate the tools 00050 new_state = TimelineToolBarState(self.timeline) 00051 if new_state == self._state: 00052 return 00053 00054 self._state = new_state 00055 00056 self.ClearTools() 00057 00058 icons_dir = roslib.packages.get_pkg_dir(PKG) + '/icons/' 00059 00060 start_icon = wx.Bitmap(icons_dir + 'start.png') 00061 rewind_icon = wx.Bitmap(icons_dir + 'rewind.png') 00062 play_icon = wx.Bitmap(icons_dir + 'play.png') 00063 fastforward_icon = wx.Bitmap(icons_dir + 'fastforward.png') 00064 end_icon = wx.Bitmap(icons_dir + 'end.png') 00065 stop_icon = wx.Bitmap(icons_dir + 'stop.png') 00066 00067 if self.timeline._play_speed > 1.0: 00068 fastforward_icon = wx.Bitmap(icons_dir + 'fastforward_active.png') 00069 elif self.timeline._play_speed > 0.0: 00070 play_icon = wx.Bitmap(icons_dir + 'play_active.png') 00071 elif self.timeline._play_speed == 0.0: 00072 stop_icon = wx.Bitmap(icons_dir + 'stop_active.png') 00073 elif self.timeline._play_speed < 0.0: 00074 rewind_icon = wx.Bitmap(icons_dir + 'rewind_active.png') 00075 00076 idle_renderers = len(self.timeline._rendered_topics) < len(self.timeline.topics) 00077 if idle_renderers: 00078 thumbnails_icon = wx.Bitmap(icons_dir + 'thumbnails.png') 00079 else: 00080 thumbnails_icon = wx.Bitmap(icons_dir + 'thumbnails_off.png') 00081 00082 # Create the tools 00083 00084 start_tool = self.AddLabelTool(wx.ID_ANY, '', start_icon, shortHelp='Start (Home)', longHelp='Move playhead to start of timeline') 00085 rewind_tool = self.AddLabelTool(wx.ID_ANY, '', rewind_icon, shortHelp='Rewind (Numpad -)', longHelp='Rewind') 00086 play_tool = self.AddLabelTool(wx.ID_ANY, '', play_icon, shortHelp='Play (Space)', longHelp='Play') 00087 fastforward_tool = self.AddLabelTool(wx.ID_ANY, '', fastforward_icon, shortHelp='Fastforward (Numpad +)', longHelp='Fastforward') 00088 end_tool = self.AddLabelTool(wx.ID_ANY, '', end_icon, shortHelp='End (End)', longHelp='Move playhead to end of timeline') 00089 stop_tool = self.AddLabelTool(wx.ID_ANY, '', stop_icon, shortHelp='Stop (Space)', longHelp='Stop') 00090 if self.timeline._recorder: 00091 if self.timeline._recorder.paused: 00092 record_icon = 'record_inactive.png' 00093 else: 00094 record_icon = 'record.png' 00095 record_tool = self.AddLabelTool(wx.ID_ANY, '', wx.Bitmap(icons_dir + record_icon), shortHelp='Record (Pause)', longHelp='Toggle recording') 00096 self.AddSeparator() 00097 zoom_in_tool = self.AddLabelTool(wx.ID_ANY, '', wx.Bitmap(icons_dir + 'zoom_in.png'), shortHelp='Zoom in (Page Up)', longHelp='Zoom in timeline') 00098 zoom_out_tool = self.AddLabelTool(wx.ID_ANY, '', wx.Bitmap(icons_dir + 'zoom_out.png'), shortHelp='Zoom out (Page Down)', longHelp='Zoom out timeline') 00099 zoom_tool = self.AddLabelTool(wx.ID_ANY, '', wx.Bitmap(icons_dir + 'zoom.png'), shortHelp='Reset zoom', longHelp='View entire timeline') 00100 self.AddSeparator() 00101 thumbnails_tool = self.AddLabelTool(wx.ID_ANY, '', thumbnails_icon, shortHelp='Thumbnails', longHelp='Toggle thumbnails') 00102 00103 # Bind tools to events 00104 00105 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_start(), start_tool) 00106 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_rewind(), rewind_tool) 00107 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_play(), play_tool) 00108 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_fastforward(), fastforward_tool) 00109 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_end(), end_tool) 00110 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.navigate_stop(), stop_tool) 00111 if self.timeline._recorder: 00112 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.toggle_recording(), record_tool) 00113 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.zoom_in(), zoom_in_tool) 00114 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.zoom_out(), zoom_out_tool) 00115 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.reset_zoom(), zoom_tool) 00116 self.Bind(wx.EVT_TOOL, lambda e: self.timeline.toggle_renderers(), thumbnails_tool) 00117 00118 # Set the enabled flag 00119 00120 if self.timeline._stamp_left is None: 00121 for tool in [start_tool, rewind_tool, play_tool, fastforward_tool, end_tool, stop_tool, zoom_in_tool, zoom_out_tool, zoom_tool, thumbnails_tool]: 00122 self.EnableTool(tool.Id, False) 00123 else: 00124 self.EnableTool(zoom_in_tool.Id, self.timeline.can_zoom_in()) 00125 self.EnableTool(zoom_out_tool.Id, self.timeline.can_zoom_out()) 00126 00127 # Realize the toolbar 00128 00129 self.Realize() 00130 00131 class TimelineToolBarState(object): 00132 def __init__(self, timeline): 00133 self._fastforward_active = timeline._play_speed > 1.0 00134 self._play_active = timeline._play_speed > 0.0 00135 self._stop_active = timeline._play_speed == 0.0 00136 self._rewind_active = timeline._play_speed < 0.0 00137 self._idle_renderers = len(timeline._rendered_topics) < len(timeline.topics) 00138 self._recorder_visible = timeline._recorder is not None 00139 self._recorder_paused = timeline._recorder is not None and timeline._recorder.paused 00140 self._timeline_visible = timeline._stamp_left is not None 00141 self._can_zoom_in = timeline._stamp_left is not None and timeline.can_zoom_in() 00142 self._can_zoom_out = timeline._stamp_left is not None and timeline.can_zoom_out() 00143 00144 def __eq__(self, other): 00145 if other is None: 00146 return False 00147 00148 return self._fastforward_active == other._fastforward_active \ 00149 and self._play_active == other._play_active \ 00150 and self._stop_active == other._stop_active \ 00151 and self._rewind_active == other._rewind_active \ 00152 and self._idle_renderers == other._idle_renderers \ 00153 and self._recorder_visible == other._recorder_visible \ 00154 and self._recorder_paused == other._recorder_paused \ 00155 and self._timeline_visible == other._timeline_visible \ 00156 and self._can_zoom_in == other._can_zoom_in \ 00157 and self._can_zoom_out == other._can_zoom_out