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 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
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
00102 self.SetStatusText('%d.%s' % (self.timeline.playhead.secs, str(self.timeline.playhead.nsecs)[:3]), self.timestamp_field)
00103
00104
00105 self.SetStatusText(bag_helper.stamp_to_str(self.timeline.playhead), self.human_readable_field)
00106
00107
00108 self.SetStatusText('%.3fs' % (self.timeline.playhead - self.timeline.start_stamp).to_sec(), self.elapsed_field)
00109
00110
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)