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):
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
......
......@@ -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):
......
......@@ -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:
......
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