[gnome-music/wip/mschraal/albumartists-cleanup] selectiontoolbar: Add items-selected property
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/albumartists-cleanup] selectiontoolbar: Add items-selected property
- Date: Sun, 17 Jun 2018 23:30:18 +0000 (UTC)
commit c68e6752b3bf3c0e56b30bd7797e9b02710d555a
Author: Marinus Schraal <mschraal gnome org>
Date: Sun Jun 17 21:03:48 2018 +0200
selectiontoolbar: Add items-selected property
Setting the property will influence the 'Add to Playlist' button
sensetivity.
gnomemusic/views/baseview.py | 11 +++--------
gnomemusic/widgets/albumwidget.py | 7 +++----
gnomemusic/widgets/artistalbumswidget.py | 4 +---
gnomemusic/widgets/selectiontoolbar.py | 13 ++++++++++++-
gnomemusic/window.py | 5 -----
5 files changed, 19 insertions(+), 21 deletions(-)
---
diff --git a/gnomemusic/views/baseview.py b/gnomemusic/views/baseview.py
index 67dd0430..f838b325 100644
--- a/gnomemusic/views/baseview.py
+++ b/gnomemusic/views/baseview.py
@@ -183,8 +183,7 @@ class BaseView(Gtk.Stack):
@log
def update_header_from_selection(self, n_items):
"""Updates header during item selection."""
- select_toolbar = self._selection_toolbar
- select_toolbar.add_to_playlist_button.set_sensitive(n_items > 0)
+ self._selection_toolbar.props.items_selected = n_items
self._header_bar.props.items_selected = n_items
@log
@@ -237,18 +236,14 @@ class BaseView(Gtk.Stack):
"""Select all the available songs."""
count = self._set_selection(True)
- if count > 0:
- select_toolbar = self._selection_toolbar
- select_toolbar.add_to_playlist_button.set_sensitive(True)
-
+ self._selection_toolbar.props.items_selected = count
self.update_header_from_selection(count)
@log
def unselect_all(self):
"""Unselects all the selected songs."""
self._set_selection(False)
- select_toolbar = self._selection_toolbar
- select_toolbar.add_to_playlist_button.set_sensitive(False)
+ self._selection_toolbar.props.items_selected = 0
self._header_bar.props.items_selected = 0
@log
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index b8f882b8..be2e5956 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -169,10 +169,9 @@ class AlbumWidget(Gtk.EventBox):
@Gtk.Template.Callback()
@log
def _on_selection_changed(self, widget):
- items = self._disc_listbox.get_selected_items()
- self.selection_toolbar.add_to_playlist_button.set_sensitive(
- len(items) > 0)
- self._header_bar.items_selected = len(items)
+ no_items = len(self._disc_listbox.get_selected_items())
+ self.selection_toolbar.props.items_selected = no_items
+ self._header_bar.items_selected = no_items
@log
def _on_header_cancel_button_clicked(self, button):
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index 609aca2e..48612bed 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -189,9 +189,7 @@ class ArtistAlbumsWidget(Gtk.Box):
if row[6]:
selected_items += 1
- add_button = self._selection_toolbar.add_to_playlist_button
- add_button.set_sensitive(selected_items > 0)
-
+ self._selection_toolbar.props.items_selected = selected_items
self._header_bar.props.items_selected = selected_items
@log
diff --git a/gnomemusic/widgets/selectiontoolbar.py b/gnomemusic/widgets/selectiontoolbar.py
index b3a4f17b..789e6a65 100644
--- a/gnomemusic/widgets/selectiontoolbar.py
+++ b/gnomemusic/widgets/selectiontoolbar.py
@@ -22,7 +22,7 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
-from gi.repository import Gtk
+from gi.repository import GObject, Gtk
from gnomemusic import log
@@ -34,9 +34,20 @@ class SelectionToolbar(Gtk.ActionBar):
add_to_playlist_button = Gtk.Template.Child()
+ items_selected = GObject.Property(type=int, default=0, minimum=0)
+
def __repr__(self):
return '<SelectionToolbar>'
@log
def __init__(self):
super().__init__()
+
+ self.connect('notify::items-selected', self._on_item_selection_changed)
+
+ @log
+ def _on_item_selection_changed(self, widget, data):
+ if self.props.items_selected > 0:
+ self.add_to_playlist_button.props.sensitive = True
+ else:
+ self.add_to_playlist_button.props.sensitive = False
\ No newline at end of file
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 8e801281..9866e06f 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -511,11 +511,6 @@ class Window(Gtk.ApplicationWindow):
def _on_selection_mode_changed(self, widget, data=None):
if self.headerbar.props.selection_mode == False:
self._on_changes_pending()
- else:
- child = self._stack.get_visible_child()
- in_playlist = (child == self.views[View.PLAYLIST])
- self.selection_toolbar.add_to_playlist_button.set_visible(
- not in_playlist)
@log
def _on_add_to_playlist_button_clicked(self, widget):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]