[pitivi] widgets: Remove usage of deprecated Gdk.Color and unused types in ColorWidget



commit 764ea6af27c0a38fdee648f55b129f4e88dc73ca
Author: Fabian Orccon <cfoch fabian gmail com>
Date:   Mon Jul 10 15:31:49 2017 -0500

    widgets: Remove usage of deprecated Gdk.Color and unused types in ColorWidget

 pitivi/dialogs/prefs.py |  8 +++-----
 pitivi/utils/widgets.py | 30 +++---------------------------
 tests/test_widgets.py   |  3 ++-
 3 files changed, 8 insertions(+), 33 deletions(-)
---
diff --git a/pitivi/dialogs/prefs.py b/pitivi/dialogs/prefs.py
index 17c524d9..ef14961b 100644
--- a/pitivi/dialogs/prefs.py
+++ b/pitivi/dialogs/prefs.py
@@ -188,10 +188,10 @@ class PreferencesDialog(Loggable):
                             widgets.ToggleWidget)
 
     @classmethod
-    def addColorPreference(cls, attrname, label, description, section=None, value_type=int):
+    def addColorPreference(cls, attrname, label, description, section=None):
         """Adds a user preference for a color."""
         cls._add_preference(attrname, label, description, section,
-                            widgets.ColorWidget, value_type=value_type)
+                            widgets.ColorWidget)
 
     @classmethod
     def addFontPreference(cls, attrname, label, description, section=None):
@@ -446,9 +446,7 @@ class PreferencesDialog(Loggable):
                 self.restart_warning.show()
             self.revert_button.set_sensitive(True)
 
-        # convert the value of the widget to whatever type it is currently
-        if value is not None:
-            value = type(value)(real_widget.getWidgetValue())
+        value = real_widget.getWidgetValue()
         setattr(self.settings, attrname, value)
 
         # adjust controls as appropriate
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index fc04d1e2..36f41886 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -555,42 +555,18 @@ class PathWidget(Gtk.FileChooserButton, DynamicWidget):
 
 class ColorWidget(Gtk.ColorButton, DynamicWidget):
 
-    def __init__(self, value_type=str, default=None):
+    def __init__(self, default=None):
         Gtk.ColorButton.__init__(self)
         DynamicWidget.__init__(self, default)
-        self.value_type = value_type
-        self.set_use_alpha(True)
 
     def connectValueChanged(self, callback, *args):
         self.connect("color-set", callback, *args)
 
     def setWidgetValue(self, value):
-        type_ = type(value)
-        alpha = 0xFFFF
-
-        if type_ is str:
-            color = Gdk.Color(value)
-        elif (type_ is int) or (type_ is int):
-            red, green, blue, alpha = unpack_color(value)
-            color = Gdk.Color(red, green, blue)
-        elif type_ is Gdk.Color:
-            color = value
-        else:
-            raise TypeError("%r is not something we can convert to a color" %
-                            value)
-        self.set_color(color)
-        self.set_alpha(alpha)
+        self.set_rgba(value)
 
     def getWidgetValue(self):
-        color = self.get_color()
-        alpha = self.get_alpha()
-        if self.value_type is int:
-            return pack_color_32(color.red, color.green, color.blue, alpha)
-        if self.value_type is int:
-            return pack_color_64(color.red, color.green, color.blue, alpha)
-        elif self.value_type is Gdk.Color:
-            return color
-        return color.to_string()
+        return self.get_rgba()
 
 
 class FontWidget(Gtk.FontButton, DynamicWidget):
diff --git a/tests/test_widgets.py b/tests/test_widgets.py
index 9c8739a2..04fff43c 100644
--- a/tests/test_widgets.py
+++ b/tests/test_widgets.py
@@ -16,6 +16,7 @@
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
+from gi.repository import Gdk
 from gi.repository import Gst
 
 from pitivi.utils.widgets import ChoiceWidget
@@ -41,7 +42,7 @@ class TestWidgets(common.TestCase):
                 ("banana", "banana"),
                 ("apple", "apple"),
                 ("pear", "pear")),)),
-            (ColorWidget, 0x336699FF, (int,)),
+            (ColorWidget, Gdk.RGBA(0.5, 0.5, 0.3, 0.8), ()),
             (FontWidget, "Sans 9", ()))
 
         for widget_class, default, args in widgets:


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