[Sugar-devel] [sugar-toolkit-gtk3] Make icon_name api consistent between the different toolbuttons

godiard at sugarlabs.org godiard at sugarlabs.org
Wed Sep 19 16:25:30 EDT 2012


From: Gonzalo Odiard <godiard at gmail.com>

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 gtk3 differences are visible as a wrong size (SL #3849)

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>

[1] http://lists.sugarlabs.org/archive/sugar-devel/2012-September/039624.html
---
 src/sugar3/graphics/radiotoolbutton.py  | 20 +++++++-------------
 src/sugar3/graphics/toggletoolbutton.py | 11 +++++++----
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/sugar3/graphics/radiotoolbutton.py b/src/sugar3/graphics/radiotoolbutton.py
index 006d167..290e7c2 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
@@ -45,6 +45,8 @@ class RadioToolButton(Gtk.RadioToolButton):
         GObject.GObject.__init__(self, **kwargs)
 
         self._palette_invoker.attach_tool(self)
+        if icon_name:
+            self.set_icon(icon_name)
 
         self.connect('destroy', self.__destroy_cb)
 
@@ -115,21 +117,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(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)
 
     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 56d461d..39ba0c8 100644
--- a/src/sugar3/graphics/toggletoolbutton.py
+++ b/src/sugar3/graphics/toggletoolbutton.py
@@ -30,11 +30,12 @@ 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(icon_name)
 
         self.connect('destroy', self.__destroy_cb)
 
@@ -42,11 +43,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(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)
+
     def create_palette(self):
         return None
 
-- 
1.7.11.4



More information about the Sugar-devel mailing list