[gnome-music/freeze-break: 40/107] Port Gtk.SearchBar to Gd.Revealer with toolbar



commit 750aa60bec77e2b40021e5ca686dbe3b60e388f3
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Sat Sep 7 22:55:13 2013 +0800

    Port Gtk.SearchBar to Gd.Revealer with toolbar

 gnomemusic/searchbar.py |   21 ++++++++++++++-------
 gnomemusic/window.py    |    9 +++++++--
 2 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index 4ae714b..27d8648 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -1,17 +1,24 @@
-from gi.repository import Gtk
+from gi.repository import Gtk, Gd
 
 
-class Searchbar(Gtk.SearchBar):
+class Searchbar(Gd.Revealer):
 
     def __init__(self, stack_switcher):
-        Gtk.SearchBar.__init__(self)
+        Gd.Revealer.__init__(self)
         self.stack_switcher = stack_switcher
-        self._search_entry = Gtk.SearchEntry()
-        self.connect_entry(self._search_entry)
+        toolbar = Gtk.Toolbar()
+        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
+        toolbar.show()
+        self.add(toolbar)
+        item = Gtk.ToolItem()
+        item.set_expand(True)
+        item.show()
+        toolbar.insert(item, 0)
+        self._search_entry = Gtk.SearchEntry(width_request=500, halign=Gtk.Align.CENTER)
         self._search_entry.connect("changed", self.search_entry_changed)
         self._search_entry.show()
-        self.add(self._search_entry)
-        self.connect("notify::search-mode-enabled", self.prepare_search_filter)
+        item.add(self._search_entry)
+        self.connect("notify::child-revealed", self.prepare_search_filter)
 
     def set_view_filter(self, model, itr, user_data):
         if self._search_entry.get_property("visible"):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index d122174..f303b19 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -145,7 +145,7 @@ class Window(Gtk.ApplicationWindow):
 
     def _on_key_press(self, widget, event):
         if event.keyval == 102:  # Ctrl-f
-            self.toolbar.searchbar.set_property('search-mode-enabled', True)
+            self._show_searchbar(not self.toolbar.searchbar.get_child_revealed())
 
     def _notify_mode_disconnect(self, data=None):
         self._stack.disconnect(self._on_notify_model_id)
@@ -155,7 +155,12 @@ class Window(Gtk.ApplicationWindow):
         if stack.get_visible_child() == self.views[1]:
             stack.get_visible_child().stack.set_visible_child_name('dummy')
             stack.get_visible_child().stack.set_visible_child_name('artists')
-        self.toolbar.searchbar.set_property('search-mode-enabled', False)
+        self._show_searchbar(False)
 
     def _toggle_view(self, btn, i):
         self._stack.set_visible_child(self.views[i])
+
+    def _show_searchbar(self, show):
+        self.toolbar.searchbar.set_reveal_child(show)
+        if show:
+            self.toolbar.searchbar._search_entry.grab_focus()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]