[gnome-music/wip/jfelder/search-selection-reset: 18/24] search: Add state GObject Property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/search-selection-reset: 18/24] search: Add state GObject Property
- Date: Tue, 2 Apr 2019 16:13:56 +0000 (UTC)
commit 57b087a3b12992a2ab78c808eee1d0afae2579b3
Author: Jean Felder <jfelder src gnome org>
Date: Tue Feb 26 23:29:03 2019 +0100
search: Add state GObject Property
This should help simplify search-mode interactions between the main
views and the searchbar.
gnomemusic/search.py | 11 +++++++++++
gnomemusic/views/searchview.py | 10 +++++-----
gnomemusic/widgets/searchbar.py | 6 ++----
gnomemusic/window.py | 9 ++++++---
4 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/search.py b/gnomemusic/search.py
index 2c77646a..b93e8108 100644
--- a/gnomemusic/search.py
+++ b/gnomemusic/search.py
@@ -50,3 +50,14 @@ class Search(GObject.GObject):
@log
def __init__(self):
super().__init__()
+ self._state = Search.State.NONE
+
+ @GObject.Property(type=int, default=State.NONE)
+ def state(self):
+ return self._state
+
+ @state.setter
+ def state(self, state):
+ self._state = state
+ none_state = (self._state == Search.State.NONE)
+ self.props.search_mode_enabled = not none_state
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index a088a515..58b2824c 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -55,9 +55,6 @@ class SearchView(BaseView):
def __init__(self, window, player):
super().__init__('search', None, window)
- # FIXME: Searchbar handling does not belong here.
- self._searchbar = window._searchbar
-
self._add_list_renderers()
self.player = player
self._head_iters = [None, None, None, None]
@@ -81,6 +78,8 @@ class SearchView(BaseView):
self._items_found = None
+ self._previous_search_state = Search.State.NONE
+
@log
def _setup_view(self):
view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
@@ -103,8 +102,6 @@ class SearchView(BaseView):
@log
def _back_button_clicked(self, widget, data=None):
- self._searchbar.props.search_mode_enabled = True
-
if self.get_visible_child() == self._artist_albums_widget:
self._artist_albums_widget.destroy()
self._artist_albums_widget = None
@@ -113,6 +110,7 @@ class SearchView(BaseView):
self._window.views[View.ALBUM]._grid)
self.set_visible_child(self._grid)
+ self.props.search_state = self._previous_search_state
self._headerbar.props.state = HeaderBar.State.MAIN
@log
@@ -141,6 +139,7 @@ class SearchView(BaseView):
self._headerbar.props.title = title
self._headerbar.props.subtitle = artist
self.set_visible_child(self._album_widget)
+ self._previous_search_state = self.props.search_state
self.props.search_state = Search.State.NONE
elif self.model[_iter][12] == 'artist':
@@ -162,6 +161,7 @@ class SearchView(BaseView):
self._headerbar.props.title = artist
self._headerbar.props.subtitle = None
self.set_visible_child(self._artist_albums_widget)
+ self._previous_search_state = self.props.search_state
self.props.search_state = Search.State.NONE
elif self.model[_iter][12] == 'song':
if self.model[_iter][11] != ValidationStatus.FAILED:
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index b0930024..6ca5ba27 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -404,12 +404,10 @@ class Searchbar(Gtk.SearchBar):
def _search_state_changed(self, klass, data):
search_state = self.props.search_state
- if search_state == Search.State.NONE:
- self.props.search_mode_enabled = False
- elif search_state == Search.State.NO_RESULT:
+ if search_state == Search.State.NO_RESULT:
self._set_error_style(True)
self.props.stack.props.visible_child_name = 'emptyview'
- else:
+ elif search_state == Search.State.RESULT:
self._set_error_style(False)
self.props.stack.props.visible_child_name = 'search'
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 174c035a..79dbf70a 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -129,8 +129,10 @@ class Window(Gtk.ApplicationWindow):
| GObject.BindingFlags.SYNC_CREATE)
self._search.bind_property(
"search-mode-enabled", self._searchbar, "search-mode-enabled",
- GObject.BindingFlags.BIDIRECTIONAL
- | GObject.BindingFlags.SYNC_CREATE)
+ GObject.BindingFlags.SYNC_CREATE)
+ self._search.bind_property(
+ "state", self._searchbar, "search-state",
+ GObject.BindingFlags.SYNC_CREATE)
self._player = Player(self)
self._player_toolbar = PlayerToolbar(self._player, self)
@@ -277,7 +279,8 @@ class Window(Gtk.ApplicationWindow):
self._stack.set_visible_child(self.views[View.ALBUM])
self.views[View.SEARCH].bind_property(
- 'search-state', self._searchbar, 'search-state')
+ "search-state", self._search, "state",
+ GObject.BindingFlags.SYNC_CREATE)
@log
def _select_all(self, action=None, param=None):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]