Commit 764ea6af authored by Fabián Orccón's avatar Fabián Orccón Committed by Alexandru Băluț

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

parent 817d885a
...@@ -188,10 +188,10 @@ class PreferencesDialog(Loggable): ...@@ -188,10 +188,10 @@ class PreferencesDialog(Loggable):
widgets.ToggleWidget) widgets.ToggleWidget)
@classmethod @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.""" """Adds a user preference for a color."""
cls._add_preference(attrname, label, description, section, cls._add_preference(attrname, label, description, section,
widgets.ColorWidget, value_type=value_type) widgets.ColorWidget)
@classmethod @classmethod
def addFontPreference(cls, attrname, label, description, section=None): def addFontPreference(cls, attrname, label, description, section=None):
...@@ -446,9 +446,7 @@ class PreferencesDialog(Loggable): ...@@ -446,9 +446,7 @@ class PreferencesDialog(Loggable):
self.restart_warning.show() self.restart_warning.show()
self.revert_button.set_sensitive(True) self.revert_button.set_sensitive(True)
# convert the value of the widget to whatever type it is currently value = real_widget.getWidgetValue()
if value is not None:
value = type(value)(real_widget.getWidgetValue())
setattr(self.settings, attrname, value) setattr(self.settings, attrname, value)
# adjust controls as appropriate # adjust controls as appropriate
......
...@@ -555,42 +555,18 @@ class PathWidget(Gtk.FileChooserButton, DynamicWidget): ...@@ -555,42 +555,18 @@ class PathWidget(Gtk.FileChooserButton, DynamicWidget):
class ColorWidget(Gtk.ColorButton, DynamicWidget): class ColorWidget(Gtk.ColorButton, DynamicWidget):
def __init__(self, value_type=str, default=None): def __init__(self, default=None):
Gtk.ColorButton.__init__(self) Gtk.ColorButton.__init__(self)
DynamicWidget.__init__(self, default) DynamicWidget.__init__(self, default)
self.value_type = value_type
self.set_use_alpha(True)
def connectValueChanged(self, callback, *args): def connectValueChanged(self, callback, *args):
self.connect("color-set", callback, *args) self.connect("color-set", callback, *args)
def setWidgetValue(self, value): def setWidgetValue(self, value):
type_ = type(value) self.set_rgba(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)
def getWidgetValue(self): def getWidgetValue(self):
color = self.get_color() return self.get_rgba()
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()
class FontWidget(Gtk.FontButton, DynamicWidget): class FontWidget(Gtk.FontButton, DynamicWidget):
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# License along with this program; if not, write to the # License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
from gi.repository import Gdk
from gi.repository import Gst from gi.repository import Gst
from pitivi.utils.widgets import ChoiceWidget from pitivi.utils.widgets import ChoiceWidget
...@@ -41,7 +42,7 @@ class TestWidgets(common.TestCase): ...@@ -41,7 +42,7 @@ class TestWidgets(common.TestCase):
("banana", "banana"), ("banana", "banana"),
("apple", "apple"), ("apple", "apple"),
("pear", "pear")),)), ("pear", "pear")),)),
(ColorWidget, 0x336699FF, (int,)), (ColorWidget, Gdk.RGBA(0.5, 0.5, 0.3, 0.8), ()),
(FontWidget, "Sans 9", ())) (FontWidget, "Sans 9", ()))
for widget_class, default, args in widgets: for widget_class, default, args in widgets:
......
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