[pitivi: 1/3] Do not show seconds unless the ETA is under 2 minutes.



commit 10e9fdbe91836188c8821c2356fde1857535458b
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Thu May 19 23:49:32 2011 -0400

    Do not show seconds unless the ETA is under 2 minutes.
    
    Seconds vary too much and generally do not make sense when waiting for a long render to finish.

 pitivi/actioner.py |    4 ++--
 pitivi/utils.py    |   25 +++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/pitivi/actioner.py b/pitivi/actioner.py
index 59123df..f23b69f 100644
--- a/pitivi/actioner.py
+++ b/pitivi/actioner.py
@@ -36,7 +36,7 @@ from pitivi.log.loggable import Loggable
 from pitivi.settings import export_settings_to_render_settings
 from pitivi.signalinterface import Signallable
 from pitivi.stream import AudioStream, VideoStream
-from pitivi.utils import beautify_length
+from pitivi.utils import beautify_ETA
 
 class Actioner(Loggable, Signallable):
     """ Previewer/Renderer helper methods """
@@ -202,7 +202,7 @@ class Renderer(Actioner):
             # only display ETA after 5s in order to have enough averaging and
             # if the position is non-null
             totaltime = (timediff * float(length) / float(position)) - timediff
-            text = beautify_length(int(totaltime * gst.SECOND))
+            text = beautify_ETA(int(totaltime * gst.SECOND))
         self.updatePosition(fraction, text)
 
     def updatePosition(self, fraction, text):
diff --git a/pitivi/utils.py b/pitivi/utils.py
index e94b2ef..697fb70 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -61,8 +61,6 @@ def time_to_string(value):
 def beautify_length(length):
     """
     Converts the given time in nanoseconds to a human readable string
-
-    Format HHhMMmSSs
     """
     sec = length / gst.SECOND
     mins = sec / 60
@@ -82,6 +80,29 @@ def beautify_length(length):
 
     return ", ".join(parts)
 
+def beautify_ETA(length):
+    """
+    Converts the given time in nanoseconds to a fuzzy estimate,
+    intended for progress ETAs, not to indicate a clip's duration.
+    """
+    sec = length / gst.SECOND
+    mins = sec / 60
+    sec = sec % 60
+    hours = mins / 60
+    mins = mins % 60
+
+    parts = []
+    if hours:
+        parts.append(ngettext("%d hour", "%d hours", hours) % hours)
+
+    if mins:
+        parts.append(ngettext("%d minute", "%d minutes", mins) % mins)
+
+    if not hours and mins < 2 and sec:
+        parts.append(ngettext("%d second", "%d seconds", sec) % sec)
+
+    return ", ".join(parts)
+
 def bin_contains(bin, element):
     """ Returns True if the bin contains the given element, the search is recursive """
     if not isinstance(bin, gst.Bin):



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