[gnome-music/gnome-3-10] Skip special symbols when handling searchbar trigger on type



commit 9d8ef14d8ae7caf73e3230f254820ad799228951
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Mon Feb 10 15:13:04 2014 +0100

    Skip special symbols when handling searchbar trigger on type
    
    Partially fixes https://bugzilla.gnome.org/show_bug.cgi?id=723942

 gnomemusic/searchbar.py |   15 ++++++++++++++-
 gnomemusic/toolbar.py   |    4 ++--
 gnomemusic/window.py    |   31 +++++++++++++------------------
 3 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index d30fed0..9fb6bd8 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -3,9 +3,10 @@ from gi.repository import Gtk, Gd
 
 class Searchbar(Gd.Revealer):
 
-    def __init__(self, stack_switcher):
+    def __init__(self, stack_switcher, search_button):
         Gd.Revealer.__init__(self)
         self.stack_switcher = stack_switcher
+        self._search_button = search_button
         toolbar = Gtk.Toolbar()
         toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
         toolbar.show()
@@ -55,3 +56,15 @@ class Searchbar(Gd.Revealer):
         self.search_term = self._search_entry.get_text()
         if self.view:
             self.view.filter.refilter()
+
+    def show_bar(self, show):
+        self.set_reveal_child(show)
+        self._search_button.set_active(show)
+
+        if show:
+            self._search_entry.grab_focus()
+        else:
+            self._search_entry.set_text('')
+
+    def toggle_bar(self):
+        self.show_bar(not self.get_child_revealed())
diff --git a/gnomemusic/toolbar.py b/gnomemusic/toolbar.py
index e5b36f6..b991589 100644
--- a/gnomemusic/toolbar.py
+++ b/gnomemusic/toolbar.py
@@ -59,7 +59,8 @@ class Toolbar(GObject.GObject):
         self._ui = Gtk.Builder()
         self._ui.add_from_resource('/org/gnome/Music/headerbar.ui')
         self.header_bar = self._ui.get_object('header-bar')
-        self.searchbar = Searchbar(self._stack_switcher)
+        self._search_button = self._ui.get_object('search-button')
+        self.searchbar = Searchbar(self._stack_switcher, self._search_button)
         self._select_button = self._ui.get_object('select-button')
         self._cancel_button = self._ui.get_object('done-button')
         self._back_button = self._ui.get_object('back-button')
@@ -68,7 +69,6 @@ class Toolbar(GObject.GObject):
         self._selection_menu = self._ui.get_object('selection-menu')
         self._selection_menu_button = self._ui.get_object('selection-menu-button')
         self._selection_menu_button.set_relief(Gtk.ReliefStyle.NONE)
-        self._search_button = self._ui.get_object('search-button')
         if Gtk.Widget.get_default_direction() is Gtk.TextDirection.RTL:
             _back_button_image = self._ui.get_object('back-button-image')
             _back_button_image.set_property('icon-name', 'go-previous-rtl-symbolic')
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 16e1cb6..fc56021 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -71,8 +71,8 @@ class Window(Gtk.ApplicationWindow):
         if self.settings.get_value('window-maximized'):
             self.maximize()
 
-        self.connect("window-state-event", self.on_window_state_event)
-        self.connect("configure-event", self.on_configure_event)
+        self.connect("window-state-event", self._on_window_state_event)
+        self.connect("configure-event", self._on_configure_event)
         self._setup_view()
         self.proxy = Gio.DBusProxy.new_sync(Gio.bus_get_sync(Gio.BusType.SESSION, None),
                                             Gio.DBusProxyFlags.NONE,
@@ -88,14 +88,14 @@ class Window(Gtk.ApplicationWindow):
             # We cannot grab media keys if no settings daemon is running
             pass
 
-    def on_configure_event(self, widget, event):
+    def _on_configure_event(self, widget, event):
         size = widget.get_size()
         self.settings.set_value('window-size', GLib.Variant('ai', [size[0], size[1]]))
 
         position = widget.get_position()
         self.settings.set_value('window-position', GLib.Variant('ai', [position[0], position[1]]))
 
-    def on_window_state_event(self, widget, event):
+    def _on_window_state_event(self, widget, event):
         self.settings.set_boolean('window-maximized', 'GDK_WINDOW_STATE_MAXIMIZED' in 
event.new_window_state.value_names)
 
     def _grab_media_player_keys(self):
@@ -182,15 +182,18 @@ class Window(Gtk.ApplicationWindow):
 
     def _on_key_press(self, widget, event):
         modifiers = Gtk.accelerator_get_default_mod_mask()
+
         if (event.keyval == Gdk.KEY_f and
                 (event.state & modifiers) == Gdk.ModifierType.CONTROL_MASK):
-            self._show_searchbar(not self.toolbar.searchbar.get_child_revealed())
+            self.toolbar.searchbar.toggle_bar()
         elif (event.keyval == Gdk.KEY_Escape and (event.state & modifiers) == 0):
-            self._show_searchbar(False)
+            self.toolbar.searchbar.show_bar(False)
             if self.toolbar._selectionMode:
                 self.toolbar.set_selection_mode(False)
-        elif (event.state & modifiers) == 0 and not self.toolbar.searchbar.get_reveal_child():
-            self._show_searchbar(True)
+        elif (event.state & modifiers) == 0 and \
+                event.keyval in range(33, 126) and \
+                not self.toolbar.searchbar.get_reveal_child():
+            self.toolbar.searchbar.show_bar(True)
 
     def _notify_mode_disconnect(self, data=None):
         self._stack.disconnect(self._on_notify_model_id)
@@ -200,18 +203,10 @@ 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._show_searchbar(False)
+        self.toolbar.searchbar.show_bar(False)
 
     def _toggle_view(self, btn, i):
         self._stack.set_visible_child(self.views[i])
 
     def _on_search_toggled(self, button, data=None):
-        self._show_searchbar(button.get_active())
-
-    def _show_searchbar(self, show):
-        self.toolbar.searchbar.set_reveal_child(show)
-        self.toolbar._search_button.set_active(show)
-        if show:
-            self.toolbar.searchbar._search_entry.grab_focus()
-        else:
-            self.toolbar.searchbar._search_entry.set_text('')
+        self.toolbar.searchbar.show_bar(button.get_active())


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