From patchwork Sat Mar 24 00:23:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel, 5/9] lib/bb/ui/crumbs/hobwidget: convert button styling logic to static methods Date: Sat, 24 Mar 2012 00:23:03 -0000 From: Joshua Lock X-Patchwork-Id: 24413 Message-Id: <6343e1553553426bf83318b8d74ecb0e1de39349.1332545580.git.josh@linux.intel.com> To: bitbake-devel@lists.openembedded.org 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. Signed-off-by: Joshua Lock Acked-by: Dongxiao Xu --- lib/bb/ui/crumbs/hobwidget.py | 53 +++++++++++++++++++++++++--------------- 1 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/bb/ui/crumbs/hobwidget.py b/lib/bb/ui/crumbs/hobwidget.py index 6b8fc1b..d6ed260 100644 --- a/lib/bb/ui/crumbs/hobwidget.py +++ b/lib/bb/ui/crumbs/hobwidget.py @@ -204,49 +204,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): """