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 <gonzalo@laptop.org> Acked-by: Simon Schampijer <simon@laptop.org> [1] http://lists.sugarlabs.org/archive/sugar-devel/2012-September/039624.html
This commit is contained in:
parent
fe4667f0f5
commit
fe11a3aa23
@ -36,7 +36,7 @@ class RadioToolButton(Gtk.RadioToolButton):
|
|||||||
|
|
||||||
__gtype_name__ = 'SugarRadioToolButton'
|
__gtype_name__ = 'SugarRadioToolButton'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, icon_name=None, **kwargs):
|
||||||
self._accelerator = None
|
self._accelerator = None
|
||||||
self._tooltip = None
|
self._tooltip = None
|
||||||
self._xo_color = None
|
self._xo_color = None
|
||||||
@ -46,6 +46,9 @@ class RadioToolButton(Gtk.RadioToolButton):
|
|||||||
|
|
||||||
self._palette_invoker.attach_tool(self)
|
self._palette_invoker.attach_tool(self)
|
||||||
|
|
||||||
|
if icon_name:
|
||||||
|
self.set_icon_name(icon_name)
|
||||||
|
|
||||||
self.connect('destroy', self.__destroy_cb)
|
self.connect('destroy', self.__destroy_cb)
|
||||||
|
|
||||||
def __destroy_cb(self, icon):
|
def __destroy_cb(self, icon):
|
||||||
@ -115,21 +118,13 @@ class RadioToolButton(Gtk.RadioToolButton):
|
|||||||
accelerator = GObject.property(type=str, setter=set_accelerator,
|
accelerator = GObject.property(type=str, setter=set_accelerator,
|
||||||
getter=get_accelerator)
|
getter=get_accelerator)
|
||||||
|
|
||||||
def set_named_icon(self, named_icon):
|
def set_icon_name(self, icon_name):
|
||||||
icon = Icon(icon_name=named_icon,
|
icon = Icon(icon_name=icon_name,
|
||||||
xo_color=self._xo_color,
|
xo_color=self._xo_color)
|
||||||
icon_size=Gtk.IconSize.LARGE_TOOLBAR)
|
|
||||||
self.set_icon_widget(icon)
|
self.set_icon_widget(icon)
|
||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
def get_named_icon(self):
|
icon_name = GObject.property(type=str, setter=set_icon_name)
|
||||||
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)
|
|
||||||
|
|
||||||
def set_xo_color(self, xo_color):
|
def set_xo_color(self, xo_color):
|
||||||
if self._xo_color != xo_color:
|
if self._xo_color != xo_color:
|
||||||
|
@ -61,11 +61,13 @@ class ToggleToolButton(Gtk.ToggleToolButton):
|
|||||||
|
|
||||||
__gtype_name__ = 'SugarToggleToolButton'
|
__gtype_name__ = 'SugarToggleToolButton'
|
||||||
|
|
||||||
def __init__(self, named_icon=None):
|
def __init__(self, icon_name=None):
|
||||||
GObject.GObject.__init__(self)
|
GObject.GObject.__init__(self)
|
||||||
|
|
||||||
self._palette_invoker = ToolInvoker(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)
|
self.connect('destroy', self.__destroy_cb)
|
||||||
|
|
||||||
@ -73,11 +75,13 @@ class ToggleToolButton(Gtk.ToggleToolButton):
|
|||||||
if self._palette_invoker is not None:
|
if self._palette_invoker is not None:
|
||||||
self._palette_invoker.detach()
|
self._palette_invoker.detach()
|
||||||
|
|
||||||
def set_named_icon(self, named_icon):
|
def set_icon_name(self, icon_name):
|
||||||
icon = Icon(icon_name=named_icon)
|
icon = Icon(icon_name=icon_name)
|
||||||
self.set_icon_widget(icon)
|
self.set_icon_widget(icon)
|
||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
|
icon_name = GObject.property(type=str, setter=set_icon_name)
|
||||||
|
|
||||||
def create_palette(self):
|
def create_palette(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class ToolButton(Gtk.ToolButton):
|
|||||||
self._palette_invoker.attach_tool(self)
|
self._palette_invoker.attach_tool(self)
|
||||||
|
|
||||||
if icon_name:
|
if icon_name:
|
||||||
self.set_icon(icon_name)
|
self.set_icon_name(icon_name)
|
||||||
|
|
||||||
self.get_child().connect('can-activate-accel',
|
self.get_child().connect('can-activate-accel',
|
||||||
self.__button_can_activate_accel_cb)
|
self.__button_can_activate_accel_cb)
|
||||||
@ -114,12 +114,12 @@ class ToolButton(Gtk.ToolButton):
|
|||||||
accelerator = GObject.property(type=str, setter=set_accelerator,
|
accelerator = GObject.property(type=str, setter=set_accelerator,
|
||||||
getter=get_accelerator)
|
getter=get_accelerator)
|
||||||
|
|
||||||
def set_icon(self, icon_name):
|
def set_icon_name(self, icon_name):
|
||||||
icon = Icon(icon_name=icon_name)
|
icon = Icon(icon_name=icon_name)
|
||||||
self.set_icon_widget(icon)
|
self.set_icon_widget(icon)
|
||||||
icon.show()
|
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):
|
def create_palette(self):
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user