[pitivi] Use better formatting for durations in sourcelist and encodingdialog.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] Use better formatting for durations in sourcelist and encodingdialog.
- Date: Tue, 12 May 2009 11:08:16 -0400 (EDT)
commit a87bbc1712bc62914be72559bc60bb6d7a1f44d9
Author: Alessandro Decina <alessandro d gmail com>
Date: Tue May 12 15:12:23 2009 +0200
Use better formatting for durations in sourcelist and encodingdialog.
Based on a patch from Jean-François Fortin Tam <nekohayo at gmail dot com>.
Fixes #575955.
---
pitivi/ui/encodingdialog.py | 7 ++++-
pitivi/utils.py | 16 ++++++++++--
tests/test_utils.py | 54 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/pitivi/ui/encodingdialog.py b/pitivi/ui/encodingdialog.py
index 8f4bf77..65e3cfd 100644
--- a/pitivi/ui/encodingdialog.py
+++ b/pitivi/ui/encodingdialog.py
@@ -26,6 +26,7 @@ Encoding dialog
import os
import time
import gtk
+import gst
from gettext import gettext as _
@@ -37,6 +38,7 @@ from pitivi.action import render_action_for_uri, ViewAction
from pitivi.factories.base import SourceFactory
from pitivi.settings import export_settings_to_render_settings
from pitivi.stream import AudioStream, VideoStream
+from pitivi.utils import beautify_length
class EncodingDialog(GladeWindow, Loggable):
""" Encoding dialog box """
@@ -113,8 +115,9 @@ class EncodingDialog(GladeWindow, Loggable):
# 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
- self.progressbar.set_text(_("Finished in %dm%ds") % (int(totaltime) / 60,
- int(totaltime) % 60))
+ length = beautify_length(int(totaltime * gst.SECOND))
+ if length:
+ self.progressbar.set_text(_("About %s left") % length)
def _recordButtonClickedCb(self, unused_button):
self.debug("Rendering")
diff --git a/pitivi/utils.py b/pitivi/utils.py
index 6551315..8692029 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -28,6 +28,7 @@ import gst, bisect
import os
from pitivi.signalinterface import Signallable
import pitivi.log.log as log
+from gettext import ngettext
UNKNOWN_DURATION = 2 ** 63 - 1
@@ -57,11 +58,20 @@ def beautify_length(length):
sec = length / gst.SECOND
mins = sec / 60
sec = sec % 60
- if mins < 60:
- return "%02dm%02ds" % (mins, sec)
hours = mins / 60
mins = mins % 60
- return "%02dh%02dm%02ds" % (hours, mins, sec)
+
+ 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 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 """
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..c993a73
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+# PiTiVi , Non-linear video editor
+#
+# test_utils.py
+#
+# Copyright (c) 2009, Alessandro Decina <alessandro decina collabora co uk>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+from unittest import TestCase
+
+import gobject
+gobject.threads_init()
+import gst
+from pitivi.utils import beautify_length
+
+second = gst.SECOND
+minute = second * 60
+hour = minute * 60
+
+class TestBeautifyLength(TestCase):
+ def testBeautifySeconds(self):
+ self.failUnlessEqual(beautify_length(second), "1 second")
+ self.failUnlessEqual(beautify_length(second * 2), "2 seconds")
+
+ def testBeautifyMinutes(self):
+ self.failUnlessEqual(beautify_length(minute), "1 minute")
+ self.failUnlessEqual(beautify_length(minute * 2), "2 minutes")
+
+ def testBeautifyHours(self):
+ self.failUnlessEqual(beautify_length(hour), "1 hour")
+ self.failUnlessEqual(beautify_length(hour * 2), "2 hours")
+
+ def testBeautifyMinutesAndSeconds(self):
+ self.failUnlessEqual(beautify_length(minute + second),
+ "1 minute, 1 second")
+
+ def testBeautifyHoursAndMinutes(self):
+ self.failUnlessEqual(beautify_length(hour + minute + second),
+ "1 hour, 1 minute")
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]