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


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