[gnome-music/wip/jfelder/searchbar-child: 1/7] searchbar: Directly use search_mode_enabled property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchbar-child: 1/7] searchbar: Directly use search_mode_enabled property
- Date: Fri, 16 Nov 2018 00:39:05 +0000 (UTC)
commit 77737f87a7ea4d65ae2000519c7195e39db4e1b9
Author: Jean Felder <jfelder src gnome org>
Date: Thu Nov 15 22:02:00 2018 +0100
searchbar: Directly use search_mode_enabled property
Remove reveal and toggle methods.
The whole logic can be simplified by directly using
search_mode_enabled property in window.py and listening to its changes
in SearchBar.
gnomemusic/widgets/searchbar.py | 32 ++++++++++++--------------------
gnomemusic/window.py | 15 +++++++--------
2 files changed, 19 insertions(+), 28 deletions(-)
---
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index 9a763eb5..40b8d094 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -339,6 +339,8 @@ class Searchbar(Gtk.SearchBar):
self._dropdown = DropDown()
self._dropdown.initialize_filters(self)
self.connect('notify::search-state', self._search_state_changed)
+ self.connect(
+ 'notify::search-mode-enabled', self._on_search_mode_changed)
self._previous_search_state = Search.State.NONE
@Gtk.Template.Callback()
@@ -383,29 +385,24 @@ class Searchbar(Gtk.SearchBar):
return False
@log
- def reveal(self, show, clear=True):
- """Hides or reveals the searchbar
-
- :param bool show: Whether to show the searchbar
- :param bool clear: Whether to clear the search entry
- """
- self.props.search_mode_enabled = show
-
- if show:
+ def _on_search_mode_changed(self, klass, params):
+ if self.props.search_mode_enabled:
self._search_entry.realize()
- if clear:
- self._search_entry.set_text('')
self._search_entry.grab_focus()
else:
self._drop_down_button.set_active(False)
+ # reset search state when leaving search mode
+ if self.props.search_state != Search.State.CHILD:
+ self.props.search_state = Search.State.NONE
@log
def _search_state_changed(self, klass, data):
search_state = self.props.search_state
- if (search_state == Search.State.NONE
- or search_state == Search.State.CHILD):
- self.reveal(False)
+ if search_state == Search.State.NONE:
+ self._search_entry.props.text = ''
+ elif search_state == Search.State.CHILD:
+ self.props.search_mode_enabled = False
elif search_state == Search.State.NO_RESULT:
self._set_error_style(True)
self.props.stack.props.visible_child_name = 'emptyview'
@@ -414,7 +411,7 @@ class Searchbar(Gtk.SearchBar):
self.props.stack.props.visible_child_name = 'search'
# display searchbar when switching back to results
if self._previous_search_state == Search.State.CHILD:
- self.reveal(True, False)
+ self.props.search_mode_enabled = True
self._previous_search_state = search_state
@@ -429,8 +426,3 @@ class Searchbar(Gtk.SearchBar):
style_context.add_class('error')
else:
style_context.remove_class('error')
-
- @log
- def toggle(self):
- """Toggle the searchbar showing"""
- self.reveal(not self.get_search_mode())
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index aacfb9ed..2525e070 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -303,7 +303,8 @@ class Window(Gtk.ApplicationWindow):
if (keyval == Gdk.KEY_f
and not self.views[View.PLAYLIST].rename_active
and self._headerbar.props.state != HeaderBar.State.SEARCH):
- self._searchbar.toggle()
+ search_enabled = self._searchbar.props.search_mode_enabled
+ self._searchbar.props.search_mode_enabled = not search_enabled
# Play / Pause on Ctrl + SPACE
if keyval == Gdk.KEY_space:
self._player.play_pause()
@@ -374,19 +375,19 @@ class Window(Gtk.ApplicationWindow):
if keyval == Gdk.KEY_Escape:
if self.props.selection_mode:
self.props.selection_mode = False
- else:
- self._searchbar.reveal(False)
+ elif self._searchbar.props.search_mode_enabled:
+ self._searchbar.props.search_mode_enabled = False
# Open the search bar when typing printable chars.
key_unic = Gdk.keyval_to_unicode(keyval)
- if ((not self._searchbar.get_search_mode()
+ if ((not self._searchbar.props.search_mode_enabled
and not keyval == Gdk.KEY_space)
and GLib.unichar_isprint(chr(key_unic))
and (modifiers == shift_mask
or modifiers == 0)
and not self.views[View.PLAYLIST].rename_active
and self._headerbar.props.state != HeaderBar.State.SEARCH):
- self._searchbar.reveal(True)
+ self._searchbar.props.search_mode_enabled = True
@log
def do_button_release_event(self, event):
@@ -412,7 +413,7 @@ class Window(Gtk.ApplicationWindow):
if (self.curr_view != self.views[View.SEARCH]
and self.curr_view != self.views[View.EMPTY]):
- self._searchbar.reveal(False)
+ self._searchbar.props.search_mode_enabled = False
# Disable the selection button for the EmptySearch and Playlist
# view
@@ -442,8 +443,6 @@ class Window(Gtk.ApplicationWindow):
@log
def _on_search_toggled(self, button, data=None):
- self._searchbar.reveal(
- button.get_active(), self.curr_view != self.views[View.SEARCH])
if (not button.get_active()
and (self.curr_view == self.views[View.SEARCH]
or self.curr_view == self.views[View.EMPTY])):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]