diff options
Diffstat (limited to 'gnomemusic/views/artistsview.py')
-rw-r--r-- | gnomemusic/views/artistsview.py | 125 |
1 files changed, 60 insertions, 65 deletions
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py index 3a8fec28..e7a7c1c2 100644 --- a/gnomemusic/views/artistsview.py +++ b/gnomemusic/views/artistsview.py @@ -23,31 +23,37 @@ # delete this exception statement from your version. from gettext import gettext as _ -from gi.repository import Gdk, Gtk +from gi.repository import GObject, Gtk -from gnomemusic.views.baseview import BaseView from gnomemusic.widgets.artistalbumswidget import ArtistAlbumsWidget from gnomemusic.widgets.artisttile import ArtistTile -class ArtistsView(BaseView): +@Gtk.Template(resource_path="/org/gnome/Music/ui/ArtistsView.ui") +class ArtistsView(Gtk.Box): """Main view of all available artists Consists of a list of artists on the left side and an overview of all albums by this artist on the right side. """ + __gtype_name__ = "ArtistsView" + + title = GObject.Property( + type=str, default=_("Artists"), flags=GObject.ParamFlags.READABLE) + + _artist_container = Gtk.Template.Child() + _artist_view = Gtk.Template.Child() + _sidebar = Gtk.Template.Child() + def __init__(self, application): """Initialize :param GtkApplication application: The application object """ - self._sidebar = Gtk.ListBox() - sidebar_container = Gtk.ScrolledWindow() - sidebar_container.add(self._sidebar) + super().__init__() - super().__init__( - 'artists', _("Artists"), application, sidebar_container) + self.props.name = "artists" self._application = application self._artists = {} @@ -69,24 +75,16 @@ class ArtistsView(BaseView): "items-changed", self._on_model_items_changed) self._on_model_items_changed(self._model, 0, 0, 0) - sidebar_container.props.width_request = 220 - sidebar_container.get_style_context().add_class('sidebar') - self._sidebar.props.selection_mode = Gtk.SelectionMode.SINGLE - self._sidebar.connect('row-activated', self._on_artist_activated) - - self._ctrl = Gtk.GestureMultiPress().new(self._sidebar) - self._ctrl.props.propagation_phase = Gtk.PropagationPhase.CAPTURE - self._ctrl.props.button = Gdk.BUTTON_PRIMARY - self._ctrl.connect("released", self._on_sidebar_clicked) + self._selection_mode = False - self.show_all() + self._window.bind_property( + "selection-mode", self, "selection-mode", + GObject.BindingFlags.BIDIRECTIONAL) def _create_widget(self, coreartist): row = ArtistTile(coreartist) row.props.text = coreartist.props.artist - self.bind_property("selection-mode", row, "selection-mode") - return row def _on_model_items_changed(self, model, position, removed, added): @@ -116,25 +114,18 @@ class ArtistsView(BaseView): return self._loaded_artists.remove(removed_artist) - if self._view.get_visible_child_name() == removed_artist: + if self._artist_view.get_visible_child_name() == removed_artist: row_next = (self._sidebar.get_row_at_index(position) or self._sidebar.get_row_at_index(position - 1)) if row_next: self._sidebar.select_row(row_next) self._on_artist_activated(self._sidebar, row_next, True) - removed_frame = self._view.get_child_by_name(removed_artist) - self._view.remove(removed_frame) - - def _setup_view(self): - self._view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True) - self._box.pack_start(self._view_container, True, True, 0) - - self._view = Gtk.Stack( - transition_type=Gtk.StackTransitionType.CROSSFADE, - vhomogeneous=False) - self._view_container.add(self._view) + removed_artist_page = self._artist_view.get_child_by_name( + removed_artist) + self._artist_view.remove(removed_artist_page) + @Gtk.Template.Callback() def _on_artist_activated(self, sidebar, row, data=None, untouched=False): """Initializes new artist album widgets""" # On application start the first row of ArtistView is activated @@ -145,7 +136,6 @@ class ArtistsView(BaseView): # ArtistsView, to circumvent this issue. if (self.props.selection_mode and self._window.props.active_view is self): - row.props.selected = not row.props.selected return if untouched is False: @@ -157,42 +147,50 @@ class ArtistsView(BaseView): # Prepare a new artist_albums_widget here coreartist = row.props.coreartist if coreartist.props.artist in self._loaded_artists: - scroll_vadjustment = self._view_container.props.vadjustment + scroll_vadjustment = self._artist_container.props.vadjustment scroll_vadjustment.props.value = 0. - self._view.set_visible_child_name(coreartist.props.artist) + self._artist_view.set_visible_child_name(coreartist.props.artist) return - self._artist_albums = ArtistAlbumsWidget( - coreartist, self._application, False) - artist_albums_frame = Gtk.Frame( - shadow_type=Gtk.ShadowType.NONE, hexpand=True) - artist_albums_frame.add(self._artist_albums) - artist_albums_frame.show() + artist_albums = ArtistAlbumsWidget(coreartist, self._application) + + self.bind_property( + "selection-mode", artist_albums, "selection-mode", + GObject.BindingFlags.SYNC_CREATE + | GObject.BindingFlags.BIDIRECTIONAL) - self._view.add_named(artist_albums_frame, coreartist.props.artist) - scroll_vadjustment = self._view_container.props.vadjustment + self._artist_view.add_named(artist_albums, coreartist.props.artist) + scroll_vadjustment = self._artist_container.props.vadjustment scroll_vadjustment.props.value = 0. - self._view.set_visible_child(artist_albums_frame) + self._artist_view.set_visible_child(artist_albums) self._loaded_artists.append(coreartist.props.artist) - def _on_sidebar_clicked(self, gesture, n_press, x, y): - success, state = Gtk.get_current_event_state() - modifiers = Gtk.accelerator_get_default_mod_mask() - if ((state & modifiers) == Gdk.ModifierType.CONTROL_MASK - and not self.props.selection_mode): - self.props.selection_mode = True + @GObject.Property(type=bool, default=False) + def selection_mode(self): + """selection mode getter - def _on_selection_mode_changed(self, widget, data=None): - if self.get_parent().get_visible_child() != self: - return + :returns: If selection mode is active + :rtype: bool + """ + return self._selection_mode - super()._on_selection_mode_changed(widget, data) + @selection_mode.setter + def selection_mode(self, value): + """selection-mode setter + + :param bool value: Activate selection mode + """ + if (value == self._selection_mode + or self.get_parent().get_visible_child() != self): + return - self._view.props.sensitive = not self.props.selection_mode - if self.props.selection_mode: + self._selection_mode = value + self._sidebar.props.sensitive = not self._selection_mode + if self._selection_mode: self._sidebar.props.selection_mode = Gtk.SelectionMode.NONE else: + self.deselect_all() self._sidebar.props.selection_mode = Gtk.SelectionMode.SINGLE selected_row = self._sidebar.get_row_at_index(0) if selected_row is None: @@ -207,15 +205,12 @@ class ArtistsView(BaseView): self._sidebar.select_row(selected_row) self._selected_artist = None - def _toggle_all_selection(self, selected): - - def toggle_selection(child): - child.props.selected = selected - - self._sidebar.foreach(toggle_selection) - def select_all(self): - self._toggle_all_selection(True) + artist_albums = self._artist_view.get_visible_child() + for row in artist_albums: + row.get_child().select_all() def deselect_all(self): - self._toggle_all_selection(False) + artist_albums = self._artist_view.get_visible_child() + for row in artist_albums: + row.get_child().deselect_all() |