[pitivi] widgets: Show FractionWidget values as decimals always
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] widgets: Show FractionWidget values as decimals always
- Date: Tue, 31 Jan 2017 23:20:44 +0000 (UTC)
commit eb8522a159e9a6f9cc697f352b8a17222a1ced14
Author: namanyadav12 <namanyadav128 gmail com>
Date: Sun Jan 29 02:19:24 2017 +0530
widgets: Show FractionWidget values as decimals always
Show the FractionWidget values as decimals instead of
scientific e notation to make it easier to read.
Fixes https://phabricator.freedesktop.org/T2721
Reviewed-by: Alex Băluț <alexandru balut gmail com>
Differential Revision: https://phabricator.freedesktop.org/D1632
pitivi/utils/widgets.py | 6 +++---
tests/test_widgets.py | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index acca35e..c1a538a 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -401,10 +401,10 @@ class FractionWidget(TextWidget, DynamicWidget):
value = self._parseText(value)
elif not hasattr(value, "denom"):
value = Gst.Fraction(value)
- if (value.denom / 1001) == 1:
- text = "%gM" % (value.num / 1000)
+ if value.denom == 1001:
+ text = "%dM" % (value.num / 1000)
else:
- text = "%g:%g" % (value.num, value.denom)
+ text = "%d:%d" % (value.num, value.denom)
self.text.set_text(text)
diff --git a/tests/test_widgets.py b/tests/test_widgets.py
index af88897..d598a04 100644
--- a/tests/test_widgets.py
+++ b/tests/test_widgets.py
@@ -18,9 +18,12 @@
# Boston, MA 02110-1301, USA.
from unittest import TestCase
+from gi.repository import Gst
+
from pitivi.utils.widgets import ChoiceWidget
from pitivi.utils.widgets import ColorWidget
from pitivi.utils.widgets import FontWidget
+from pitivi.utils.widgets import FractionWidget
from pitivi.utils.widgets import NumericWidget
from pitivi.utils.widgets import PathWidget
from pitivi.utils.widgets import TextWidget
@@ -58,3 +61,18 @@ class TestWidgets(TestCase):
widget = TextWidget("^\d+$", ("12", "14"))
bad_value = "non-digits"
self.assertNotEqual(bad_value, widget.getWidgetValue())
+
+
+class TestFractionWidget(TestCase):
+
+ def test_widget_text(self):
+ widget = FractionWidget()
+ widget.setWidgetValue(Gst.Fraction(1000000, 1))
+ self.assertEqual(widget.text.get_text(), "1000000:1")
+ widget.setWidgetValue(Gst.Fraction(7504120000000001, 4503600000000002))
+ self.assertEqual(widget.text.get_text(), "7504120000000001:4503600000000002")
+
+ def test_widget_text_magic_M(self):
+ widget = FractionWidget()
+ widget.setWidgetValue(Gst.Fraction(1000000000, 1001))
+ self.assertEqual(widget.text.get_text(), "1000000M")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]