From 61f039d57cbd26f1119cce281f32a72a5e149816 Mon Sep 17 00:00:00 2001 From: Joshua Lock Date: Fri, 23 Mar 2012 17:23:03 -0700 Subject: lib/bb/ui/crumbs/hobwidget: convert button styling logic to static methods The design calls for all buttons to match the style of either the HobButton or HobAltButton classes, therefore implement the styling logic as static methods of the implementing classes so that we can more easily set styles for the buttons created by a gtk.Dialog (or subclass) without having to modify too much of the dialog instantiation code. (Bitbake rev: ccb8f5cd52ee7833129583b9201c65d93cb87d56) Signed-off-by: Joshua Lock Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/crumbs/hobwidget.py | 53 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'bitbake/lib') diff --git a/bitbake/lib/bb/ui/crumbs/hobwidget.py b/bitbake/lib/bb/ui/crumbs/hobwidget.py index 7988975621..8936f0a42a 100644 --- a/bitbake/lib/bb/ui/crumbs/hobwidget.py +++ b/bitbake/lib/bb/ui/crumbs/hobwidget.py @@ -205,49 +205,62 @@ class HobButton(gtk.Button): label: the text to display as the button's label """ def __init__(self, label): - gtk.Button.__init__(self, "%s" % gobject.markup_escape_text(label)) - self.child.set_use_markup(True) + gtk.Button.__init__(self, label) + HobButton.style_button(self) - style = self.get_style() + @staticmethod + def style_button(button): + style = button.get_style() button_color = gtk.gdk.Color(HobColors.ORANGE) - self.modify_bg(gtk.STATE_NORMAL, button_color) - self.modify_bg(gtk.STATE_PRELIGHT, button_color) - self.modify_bg(gtk.STATE_SELECTED, button_color) + button.modify_bg(gtk.STATE_NORMAL, button_color) + button.modify_bg(gtk.STATE_PRELIGHT, button_color) + button.modify_bg(gtk.STATE_SELECTED, button_color) + + button.set_flags(gtk.CAN_DEFAULT) + button.grab_default() - self.set_flags(gtk.CAN_DEFAULT) - self.grab_default() + label = "%s" % gobject.markup_escape_text(button.get_label()) + button.set_label(label) + button.child.set_use_markup(True) class HobAltButton(gtk.Button): """ A gtk.Button subclass which has no relief, and so is more discrete """ def __init__(self, label): - gtk.Button.__init__(self) - self.text = label - self.set_text() - self.set_relief(gtk.RELIEF_NONE) - self.connect("state-changed", self.desensitise_on_state_change_cb) + gtk.Button.__init__(self, label) + HobAltButton.style_button(self) """ A callback for the state-changed event to ensure the text is displayed differently when the widget is not sensitive """ - def desensitise_on_state_change_cb(self, widget, state): - if widget.get_state() == gtk.STATE_INSENSITIVE: - self.set_text(False) + @staticmethod + def desensitise_on_state_change_cb(button, state): + if button.get_state() == gtk.STATE_INSENSITIVE: + HobAltButton.set_text(button, False) else: - self.set_text(True) + HobAltButton.set_text(button, True) """ Set the button label with an appropriate colour for the current widget state """ - def set_text(self, sensitive=True): + @staticmethod + def set_text(button, sensitive=True): if sensitive: colour = HobColors.PALE_BLUE else: colour = HobColors.LIGHT_GRAY - self.set_label("%s" % (colour, gobject.markup_escape_text(self.text))) - self.child.set_use_markup(True) + button.set_label("%s" % (colour, gobject.markup_escape_text(button.text))) + button.child.set_use_markup(True) + + @staticmethod + def style_button(button): + button.text = button.get_label() + button.connect("state-changed", HobAltButton.desensitise_on_state_change_cb) + HobAltButton.set_text(button) + button.child.set_use_markup(True) + button.set_relief(gtk.RELIEF_NONE) class HobImageButton(gtk.Button): """ -- cgit v1.2.3-54-g00ecf