Commit eb8522a1 authored by namanyadav12's avatar namanyadav12 Committed by Alexandru Băluț

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/T2721Reviewed-by: Alexandru Băluț's avatarAlex Băluț <alexandru.balut@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D1632
parent f936b001
......@@ -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)
......
......@@ -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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment