[pitivi] widgets: Hide the zero hour in the time widget



commit 7734ff6cf2efe9067054665ad22c6c2b98656cea
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Jan 12 15:12:42 2014 +0100

    widgets: Hide the zero hour in the time widget

 pitivi/utils/widgets.py                   |   25 ++++++++++++++++---------
 tests/dogtail_scripts/helper_functions.py |    3 ++-
 tests/dogtail_scripts/test_base.py        |    6 ++++++
 tests/dogtail_scripts/test_project.py     |    7 ++-----
 tests/dogtail_scripts/test_timeline.py    |   13 +++++--------
 5 files changed, 31 insertions(+), 23 deletions(-)
---
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index b565835..271a0ca 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -284,12 +284,13 @@ class TimeWidget(TextWidget, DynamicWidget):
     # The "frame number" match rule is ^([0-9]+)$ (with a + to require 1 digit)
     # The "timecode" rule is ^([0-9]:[0-5][0-9]:[0-5][0-9])\.[0-9][0-9][0-9]$"
     # Combining the two, we get:
-    regex = re.compile("^([0-9]+)$|^([0-9]:[0-5][0-9]:[0-5][0-9])\.[0-9][0-9][0-9]$")
+    VALID_REGEX = re.compile("^([0-9]+)$|^([0-9]:)?([0-5][0-9]:[0-5][0-9])\.[0-9][0-9][0-9]$")
+
     __gtype_name__ = 'TimeWidget'
 
     def __init__(self, default=None):
         DynamicWidget.__init__(self, default)
-        TextWidget.__init__(self, self.regex)
+        TextWidget.__init__(self, self.VALID_REGEX)
         TextWidget.set_width_chars(self, 10)
         self._framerate = None
 
@@ -297,12 +298,17 @@ class TimeWidget(TextWidget, DynamicWidget):
         timecode = TextWidget.getWidgetValue(self)
 
         if ":" in timecode:
-            hh, mm, end = timecode.split(":")
-            ss, xxx = end.split(".")
+            parts = timecode.split(":")
+            if len(parts) == 2:
+                hh = 0
+                mm, end = parts
+            else:
+                hh, mm, end = parts
+            ss, millis = end.split(".")
             nanosecs = int(hh) * 3.6 * 10e12 \
                 + int(mm) * 6 * 10e10 \
                 + int(ss) * 10e9 \
-                + int(xxx) * 10e6
+                + int(millis) * 10e6
             nanosecs = nanosecs / 10  # Compensate the 10 factor of e notation
         else:
             # We were given a frame number. Convert from the project framerate.
@@ -311,11 +317,12 @@ class TimeWidget(TextWidget, DynamicWidget):
         # The seeker won't like floating point nanoseconds!
         return int(nanosecs)
 
-    def setWidgetValue(self, value, send_signal=True):
-        TextWidget.setWidgetValue(self, time_to_string(value),
-                                send_signal=send_signal)
+    def setWidgetValue(self, timeNanos, send_signal=True):
+        timecode = time_to_string(timeNanos)
+        if timecode.startswith("0:"):
+            timecode = timecode[2:]
+        TextWidget.setWidgetValue(self, timecode, send_signal=send_signal)
 
-    # No need to define connectValueChanged as it is inherited from DynamicWidget
     def connectActivateEvent(self, activateCb):
         return self.connect("activate", activateCb)
 
diff --git a/tests/dogtail_scripts/helper_functions.py b/tests/dogtail_scripts/helper_functions.py
index f14646d..7d05933 100644
--- a/tests/dogtail_scripts/helper_functions.py
+++ b/tests/dogtail_scripts/helper_functions.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python2
 # -*- coding: utf-8 -*-
+
 import os
 import re
 from dogtail.predicate import GenericPredicate
@@ -8,7 +9,7 @@ from test_base import BaseDogTail
 import dogtail.rawinput
 from time import sleep
 from pyatspi import Registry as registry
-from pyatspi import (KEY_SYM, KEY_PRESS, KEY_PRESSRELEASE, KEY_RELEASE)
+from pyatspi import KEY_PRESS, KEY_RELEASE
 
 
 class HelpFunc(BaseDogTail):
diff --git a/tests/dogtail_scripts/test_base.py b/tests/dogtail_scripts/test_base.py
index 4d3ce3e..1926750 100644
--- a/tests/dogtail_scripts/test_base.py
+++ b/tests/dogtail_scripts/test_base.py
@@ -6,6 +6,12 @@ import os
 from time import time, sleep
 
 
+# These are the timecodes we expect for "tears of steel.webm", depending on
+# if we insert it once in a blank timeline or twice in a blank timeline.
+DURATION_OF_ONE_CLIP = "00:01.999"
+DURATION_OF_TWO_CLIPS = "00:03.999"
+
+
 class BaseDogTail(unittest.TestCase):
     def setUp(self):
         # Force the locale/language to English.
diff --git a/tests/dogtail_scripts/test_project.py b/tests/dogtail_scripts/test_project.py
index b20f67c..7bac164 100644
--- a/tests/dogtail_scripts/test_project.py
+++ b/tests/dogtail_scripts/test_project.py
@@ -6,10 +6,7 @@ import dogtail.rawinput
 from time import time, sleep
 import os
 
-# These are the timecodes we expect for "tears of steel.webm", depending on
-# if we insert it once in a blank timeline or twice in a blank timeline.
-DURATION_OF_ONE_CLIP = "0:00:01.999"
-DURATION_OF_TWO_CLIPS = "0:00:03.999"
+from test_base import DURATION_OF_ONE_CLIP, DURATION_OF_TWO_CLIPS
 
 
 class ProjectPropertiesTest(HelpFunc):
@@ -332,7 +329,7 @@ class ProjectPropertiesTest(HelpFunc):
         # but this is better than nothing as a quick sanity check:
         self.goToEnd_button.click()
         sleep(0.5)
-        self.assertEqual(seektime.text, "0:00:00.000", "The timeline is not empty")
+        self.assertEqual(seektime.text, "00:00.000", "The timeline is not empty")
 
         # Create project #2 - 2 clips with 2 timeline instances of the first one
         # We use only the first one on the timeline because we know its duration
diff --git a/tests/dogtail_scripts/test_timeline.py b/tests/dogtail_scripts/test_timeline.py
index e8a23cf..73eaba0 100644
--- a/tests/dogtail_scripts/test_timeline.py
+++ b/tests/dogtail_scripts/test_timeline.py
@@ -1,16 +1,13 @@
 #!/usr/bin/env python2
+
 from helper_functions import HelpFunc
-from dogtail.predicate import GenericPredicate
 from dogtail.tree import SearchError
 import dogtail.rawinput
 from time import sleep
 from pyatspi import Registry as registry
-from pyatspi import (KEY_SYM, KEY_PRESS, KEY_PRESSRELEASE, KEY_RELEASE)
+from pyatspi import KEY_PRESS, KEY_RELEASE
 
-# These are the timecodes we expect for "tears of steel.webm", depending on
-# if we insert it once in a blank timeline or twice in a blank timeline.
-DURATION_OF_ONE_CLIP = "0:00:01.999"
-DURATION_OF_TWO_CLIPS = "0:00:03.999"
+from test_base import DURATION_OF_ONE_CLIP, DURATION_OF_TWO_CLIPS
 
 
 class TimelineTest(HelpFunc):
@@ -38,7 +35,7 @@ class TimelineTest(HelpFunc):
 
         self.improved_drag(self.center(sample), self.center(self.timeline))
         self.goToEnd_button.click()
-        self.assertNotEqual(timecode_widget.text, "0:00:00.000")
+        self.assertNotEqual(timecode_widget.text, "00:00.000")
 
     def test_multiple_drag(self):
         sample = self.import_media()
@@ -225,6 +222,6 @@ class TimelineTest(HelpFunc):
         dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
         registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
         self.goToEnd_button.click()
-        self.assertNotEqual(timecode_widget.text, "0:00:11.139")
+        self.assertNotEqual(timecode_widget.text, "00:11.139")
 
         #TODO: do something more with clips


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