Patchwork [bitbake-devel,01/10] ui/crumbs/hobwidget: add clear icon to search entries in HobNotebook

login
register
mail settings
Submitter Joshua Lock
Date March 22, 2012, 2:10 a.m.
Message ID <c794348a764a458d7ae3b5fee9849ba2f95bc724.1332381654.git.josh@linux.intel.com>
Download mbox | patch
Permalink /patch/24087/
State New
Headers show

Comments

Joshua Lock - March 22, 2012, 2:10 a.m.
It's a common pattern on Gtk+ desktops to be able to clear a search/filter
entry using an icon in that entry.

Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 lib/bb/ui/crumbs/hobwidget.py |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

Patch

diff --git a/lib/bb/ui/crumbs/hobwidget.py b/lib/bb/ui/crumbs/hobwidget.py
index 4b0a0cf..db52c47 100644
--- a/lib/bb/ui/crumbs/hobwidget.py
+++ b/lib/bb/ui/crumbs/hobwidget.py
@@ -622,6 +622,8 @@  class HobNotebook(gtk.VBox):
         self.search.set_style(style)
         self.search.set_text(name)
         self.search.set_editable(False)
+        self.search.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, gtk.STOCK_CLEAR)
+        self.search.connect("icon-release", self.set_search_entry_clear_cb)
         self.search.show()
         self.align = gtk.Alignment(xalign=1.0, yalign=0.7)
         self.align.add(self.search)
@@ -682,9 +684,16 @@  class HobNotebook(gtk.VBox):
         style.text[gtk.STATE_NORMAL] = self.get_colormap().alloc_color(HobColors.BLACK, False, False)
         search.set_style(style)
 
-    def set_search_entry_reset_cb(self, search, event):
-        style = search.get_style()
+    def reset_entry(self, entry):
+        style = entry.get_style()
         style.text[gtk.STATE_NORMAL] = self.get_colormap().alloc_color(HobColors.GRAY, False, False)
-        search.set_style(style)
-        search.set_text(self.search_name)
-        search.set_editable(False)
+        entry.set_style(style)
+        entry.set_text(self.search_name)
+        entry.set_editable(False)
+
+    def set_search_entry_reset_cb(self, search, event):
+        self.reset_entry(search)
+
+    def set_search_entry_clear_cb(self, search, icon_pos, event):
+        self.reset_entry(search)
+