[pitivi: 15/27] Connect to a new utility method for converting timecodes to nanoseconds



commit e6d8463141cebf62beb9a39680af039e77eb1277
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Fri Dec 24 16:12:45 2010 -0500

    Connect to a new utility method for converting timecodes to nanoseconds

 pitivi/ui/viewer.py |   10 +++++++++-
 pitivi/utils.py     |   18 ++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/pitivi/ui/viewer.py b/pitivi/ui/viewer.py
index 2226d9c..fc10727 100644
--- a/pitivi/ui/viewer.py
+++ b/pitivi/ui/viewer.py
@@ -31,7 +31,7 @@ from gettext import gettext as _
 from pitivi.action import ViewAction
 
 from pitivi.stream import VideoStream
-from pitivi.utils import time_to_string, Seeker
+from pitivi.utils import time_to_string, string_to_time, Seeker
 from pitivi.log.loggable import Loggable
 from pitivi.pipeline import PipelineError
 from pitivi.ui.common import SPACING
@@ -329,6 +329,7 @@ class PitiviViewer(gtk.VBox, Loggable):
         # current time
         self.timecode_entry = gtk.Entry()
         self.timecode_entry.set_text("00:00:00.000")
+        self.timecode_entry.connect("activate", self._jumpToTimecodeCb)
         bbox.pack_start(self.timecode_entry, expand=False, padding=10)
         self._haveUI = True
 
@@ -488,6 +489,13 @@ class PitiviViewer(gtk.VBox, Loggable):
         except:
             self.warning("couldn't get duration")
 
+    ## Callback for jumping to a specific timecode
+
+    def _jumpToTimecodeCb(self, widget):
+        nanoseconds = string_to_time(widget.get_text())
+        if nanoseconds:
+            pass # TODO: seek
+
     ## public methods for controlling playback
 
     def play(self):
diff --git a/pitivi/utils.py b/pitivi/utils.py
index f0309ad..ec63900 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -58,6 +58,24 @@ def time_to_string(value):
     mins = mins % 60
     return "%02d:%02d:%02d.%03d" % (hours, mins, sec, ms)
 
+def string_to_time(timecode):
+    """
+    Converts the given timecode string to nanoseconds.
+    Format must be HH:MM:SS.XXX
+    
+    Returns the time in nanoseconds, or False if the format is incorrect.
+    """
+    try:
+        hh, mm, foo = timecode.split(":")
+        ss, xxx = foo.split(".")
+        nanosecs = int(hh) * 3.6 * 10e12 \
+            + int(mm) * 6 * 10e10 \
+            + int(ss) * 10e9 \
+            + int(xxx) * 10e6
+        return int(nanosecs)
+    except:
+        return False
+
 def beautify_length(length):
     """
     Converts the given time in nanoseconds to a human readable string



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]