Patchwork [bitbake-devel,2/9] lib/bb/ui/crumbs/hobwidget: HobAltButton different visual when insensitive

login
register
mail settings
Submitter Joshua Lock
Date March 24, 2012, 12:23 a.m.
Message ID <45f156daf8e6423f035a1d8bb3450b149d3096f0.1332545580.git.josh@linux.intel.com>
Download mbox | patch
Permalink /patch/24405/
State Accepted
Commit 53af6a962aa2f6b4d68d59792be9c7f33cf887b4
Headers show

Comments

Joshua Lock - March 24, 2012, 12:23 a.m.
Use an alternative, grey, colour when the button is insensitive so that
the insensitivity is easily noticed.

Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 lib/bb/ui/crumbs/hobwidget.py |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
Dongxiao Xu - March 24, 2012, 12:27 a.m.
On Fri, 2012-03-23 at 17:23 -0700, Joshua Lock wrote:
> Use an alternative, grey, colour when the button is insensitive so that
> the insensitivity is easily noticed.
> 
> Signed-off-by: Joshua Lock <josh@linux.intel.com>
Acked-by: Dongxiao Xu <dongxiao.xu@intel.com>

> ---
>  lib/bb/ui/crumbs/hobwidget.py |   27 +++++++++++++++++++++++++--
>  1 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/ui/crumbs/hobwidget.py b/lib/bb/ui/crumbs/hobwidget.py
> index 020c5e2..6b8fc1b 100644
> --- a/lib/bb/ui/crumbs/hobwidget.py
> +++ b/lib/bb/ui/crumbs/hobwidget.py
> @@ -221,9 +221,32 @@ 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, "<span color='%s'><b>%s</b></span>" % (HobColors.PALE_BLUE, gobject.markup_escape_text(label)))
> -        self.child.set_use_markup(True)
> +        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)
> +
> +    """
> +    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)
> +        else:
> +            self.set_text(True)
> +
> +    """
> +    Set the button label with an appropriate colour for the current widget state
> +    """
> +    def set_text(self, sensitive=True):
> +        if sensitive:
> +            colour = HobColors.PALE_BLUE
> +        else:
> +            colour = HobColors.LIGHT_GRAY
> +        self.set_label("<span color='%s'><b>%s</b></span>" % (colour, gobject.markup_escape_text(self.text)))
> +        self.child.set_use_markup(True)
>  
>  class HobImageButton(gtk.Button):
>      """

Patch

diff --git a/lib/bb/ui/crumbs/hobwidget.py b/lib/bb/ui/crumbs/hobwidget.py
index 020c5e2..6b8fc1b 100644
--- a/lib/bb/ui/crumbs/hobwidget.py
+++ b/lib/bb/ui/crumbs/hobwidget.py
@@ -221,9 +221,32 @@  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, "<span color='%s'><b>%s</b></span>" % (HobColors.PALE_BLUE, gobject.markup_escape_text(label)))
-        self.child.set_use_markup(True)
+        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)
+
+    """
+    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)
+        else:
+            self.set_text(True)
+
+    """
+    Set the button label with an appropriate colour for the current widget state
+    """
+    def set_text(self, sensitive=True):
+        if sensitive:
+            colour = HobColors.PALE_BLUE
+        else:
+            colour = HobColors.LIGHT_GRAY
+        self.set_label("<span color='%s'><b>%s</b></span>" % (colour, gobject.markup_escape_text(self.text)))
+        self.child.set_use_markup(True)
 
 class HobImageButton(gtk.Button):
     """