From fe11a3aa23c0e7fbc3c0c498e147b0a20348cc12 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 19 Sep 2012 17:25:30 -0300 Subject: [PATCH] Make icon_name api consistent between the different toolbuttons As discused in the mailing list [1] the api to set the icon in sugar ToolButton, RadioToolButton and ToggleToolButton is inconsistent, and with the port to GTK+ 3 the differences are visible (SL #3849). This patch changes the API of ToolButton, RadioToolButton and ToggleToolButton to override the icon-name property and add an Icon instance with the set_icon_widget method. Signed-off-by: Gonzalo Odiard Acked-by: Simon Schampijer [1] http://lists.sugarlabs.org/archive/sugar-devel/2012-September/039624.html --- src/sugar3/graphics/radiotoolbutton.py | 21 ++++++++------------- src/sugar3/graphics/toggletoolbutton.py | 12 ++++++++---- src/sugar3/graphics/toolbutton.py | 6 +++--- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/sugar3/graphics/radiotoolbutton.py b/src/sugar3/graphics/radiotoolbutton.py index 006d167e..1059a51a 100644 --- a/src/sugar3/graphics/radiotoolbutton.py +++ b/src/sugar3/graphics/radiotoolbutton.py @@ -36,7 +36,7 @@ class RadioToolButton(Gtk.RadioToolButton): __gtype_name__ = 'SugarRadioToolButton' - def __init__(self, **kwargs): + def __init__(self, icon_name=None, **kwargs): self._accelerator = None self._tooltip = None self._xo_color = None @@ -46,6 +46,9 @@ class RadioToolButton(Gtk.RadioToolButton): self._palette_invoker.attach_tool(self) + if icon_name: + self.set_icon_name(icon_name) + self.connect('destroy', self.__destroy_cb) def __destroy_cb(self, icon): @@ -115,21 +118,13 @@ class RadioToolButton(Gtk.RadioToolButton): accelerator = GObject.property(type=str, setter=set_accelerator, getter=get_accelerator) - def set_named_icon(self, named_icon): - icon = Icon(icon_name=named_icon, - xo_color=self._xo_color, - icon_size=Gtk.IconSize.LARGE_TOOLBAR) + def set_icon_name(self, icon_name): + icon = Icon(icon_name=icon_name, + xo_color=self._xo_color) self.set_icon_widget(icon) icon.show() - def get_named_icon(self): - if self.props.icon_widget is not None: - return self.props.icon_widget.props.icon_name - else: - return None - - named_icon = GObject.property(type=str, setter=set_named_icon, - getter=get_named_icon) + icon_name = GObject.property(type=str, setter=set_icon_name) def set_xo_color(self, xo_color): if self._xo_color != xo_color: diff --git a/src/sugar3/graphics/toggletoolbutton.py b/src/sugar3/graphics/toggletoolbutton.py index f50d2fda..5f08a520 100644 --- a/src/sugar3/graphics/toggletoolbutton.py +++ b/src/sugar3/graphics/toggletoolbutton.py @@ -61,11 +61,13 @@ class ToggleToolButton(Gtk.ToggleToolButton): __gtype_name__ = 'SugarToggleToolButton' - def __init__(self, named_icon=None): + def __init__(self, icon_name=None): GObject.GObject.__init__(self) self._palette_invoker = ToolInvoker(self) - self.set_named_icon(named_icon) + + if icon_name: + self.set_icon_name(icon_name) self.connect('destroy', self.__destroy_cb) @@ -73,11 +75,13 @@ class ToggleToolButton(Gtk.ToggleToolButton): if self._palette_invoker is not None: self._palette_invoker.detach() - def set_named_icon(self, named_icon): - icon = Icon(icon_name=named_icon) + def set_icon_name(self, icon_name): + icon = Icon(icon_name=icon_name) self.set_icon_widget(icon) icon.show() + icon_name = GObject.property(type=str, setter=set_icon_name) + def create_palette(self): return None diff --git a/src/sugar3/graphics/toolbutton.py b/src/sugar3/graphics/toolbutton.py index da022120..37ed85cd 100644 --- a/src/sugar3/graphics/toolbutton.py +++ b/src/sugar3/graphics/toolbutton.py @@ -70,7 +70,7 @@ class ToolButton(Gtk.ToolButton): self._palette_invoker.attach_tool(self) if icon_name: - self.set_icon(icon_name) + self.set_icon_name(icon_name) self.get_child().connect('can-activate-accel', self.__button_can_activate_accel_cb) @@ -114,12 +114,12 @@ class ToolButton(Gtk.ToolButton): accelerator = GObject.property(type=str, setter=set_accelerator, getter=get_accelerator) - def set_icon(self, icon_name): + def set_icon_name(self, icon_name): icon = Icon(icon_name=icon_name) self.set_icon_widget(icon) icon.show() - icon_name = GObject.property(type=str, setter=set_icon) + icon_name = GObject.property(type=str, setter=set_icon_name) def create_palette(self): return None