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