$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 import wx.lib.newevent 00038 00039 import bag_helper 00040 00041 PlayheadChangedEvent, EVT_PLAYHEAD_CHANGED = wx.lib.newevent.NewEvent() 00042 00043 class TimelineStatusBar(wx.StatusBar): 00044 def __init__(self, parent, timeline): 00045 wx.StatusBar.__init__(self, parent, -1) 00046 00047 self.timeline = timeline 00048 00049 self.progress_field = 1 00050 self.timestamp_field = 2 00051 self.human_readable_field = 3 00052 self.elapsed_field = 4 00053 self.playspeed_field = 5 00054 00055 self.progress_width = 150 00056 self.timestamp_width = 125 00057 self.human_readable_width = 180 00058 self.elapsed_width = 110 00059 self.playspeed_width = 80 00060 00061 self.SetFieldsCount(6) 00062 00063 self.gauge = wx.Gauge(self, range=100) 00064 self.gauge.Hide() 00065 00066 self._reposition_progress() 00067 00068 parent.Bind(EVT_PLAYHEAD_CHANGED, lambda e: self._update()) 00069 parent.Bind(wx.EVT_SIZE, self.on_size) 00070 00071 self._update() 00072 00073 # property: progress 00074 00075 def _get_progress(self): 00076 return self.gauge.Value 00077 00078 def _set_progress(self, value): 00079 self.gauge.Value = value 00080 00081 progress = property(_get_progress, _set_progress) 00082 00083 def on_size(self, event): 00084 main_width = self.Size[0] - (self.progress_width + self.timestamp_width + self.human_readable_width + self.elapsed_width + self.playspeed_width) 00085 self.SetStatusWidths([main_width, self.progress_width, self.timestamp_width, self.human_readable_width, self.elapsed_width, self.playspeed_width]) 00086 00087 self._reposition_progress() 00088 00089 event.Skip() 00090 00091 def _reposition_progress(self): 00092 rect = self.GetFieldRect(self.progress_field) 00093 00094 self.gauge.SetPosition((rect.x + 1, rect.y + 1)) 00095 self.gauge.SetSize((rect.width - 2, rect.height - 2)) 00096 00097 def _update(self): 00098 if self.timeline.playhead is None or self.timeline.start_stamp is None: 00099 return 00100 00101 # Raw timestamp 00102 self.SetStatusText('%d.%s' % (self.timeline.playhead.secs, str(self.timeline.playhead.nsecs)[:3]), self.timestamp_field) 00103 00104 # Human-readable time 00105 self.SetStatusText(bag_helper.stamp_to_str(self.timeline.playhead), self.human_readable_field) 00106 00107 # Elapsed time (in seconds) 00108 self.SetStatusText('%.3fs' % (self.timeline.playhead - self.timeline.start_stamp).to_sec(), self.elapsed_field) 00109 00110 # Play speed 00111 spd = self.timeline.play_speed 00112 if spd != 0.0: 00113 if spd > 1.0: 00114 spd_str = '>> %.0fx' % spd 00115 elif spd == 1.0: 00116 spd_str = '>' 00117 elif spd > 0.0: 00118 spd_str = '> 1/%.0fx' % (1.0 / spd) 00119 elif spd > -1.0: 00120 spd_str = '< 1/%.0fx' % (1.0 / -spd) 00121 elif spd == 1.0: 00122 spd_str = '<' 00123 else: 00124 spd_str = '<< %.0fx' % -spd 00125 00126 self.SetStatusText(spd_str, self.playspeed_field) 00127 else: 00128 self.SetStatusText('', self.playspeed_field)