[gnome-music/wip/jfelder/searchview-new-style: 10/13] Add ArtistSearchTile
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchview-new-style: 10/13] Add ArtistSearchTile
- Date: Sun, 4 Aug 2019 09:53:20 +0000 (UTC)
commit 16b86f1ba400b9e572d2a9d27063c7586d9dd674
Author: Marinus Schraal <mschraal gnome org>
Date: Fri Aug 2 12:01:38 2019 +0200
Add ArtistSearchTile
data/org.gnome.Music.gresource.xml | 1 +
data/ui/ArtistSearchTile.ui | 62 +++++++++++++++++++
data/ui/SearchView.ui | 1 +
gnomemusic/views/searchview.py | 49 +++++----------
gnomemusic/widgets/artistsearchtile.py | 109 +++++++++++++++++++++++++++++++++
5 files changed, 190 insertions(+), 32 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 8326914c..2b45aaf8 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -8,6 +8,7 @@
<file preprocess="xml-stripblanks">ui/AlbumCover.ui</file>
<file preprocess="xml-stripblanks">ui/AlbumWidget.ui</file>
<file preprocess="xml-stripblanks">ui/AlbumsView.ui</file>
+ <file preprocess="xml-stripblanks">ui/ArtistSearchTile.ui</file>
<file preprocess="xml-stripblanks">ui/AppMenu.ui</file>
<file preprocess="xml-stripblanks">ui/ArtistAlbumWidget.ui</file>
<file preprocess="xml-stripblanks">ui/ArtistTile.ui</file>
diff --git a/data/ui/ArtistSearchTile.ui b/data/ui/ArtistSearchTile.ui
new file mode 100644
index 00000000..7dbf788e
--- /dev/null
+++ b/data/ui/ArtistSearchTile.ui
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.18"/>
+ <template class="ArtistSearchTile" parent="GtkFlowBoxChild">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_tooltip">True</property>
+ <property name="valign">start</property>
+ <property name="orientation">vertical</property>
+ <signal name="query-tooltip" handler="_on_tooltip_query"/>
+ <child>
+ <object class="GtkOverlay">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_bottom">4</property>
+ <child>
+ <object class="GtkEventBox" id="_events">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="button-release-event" handler="_on_artist_event" swapped="no"/>
+ <child>
+ <object class="ArtistArtStack" id="_artistart_stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="vexpand">True</property>
+ <property name="valign">end</property>
+ <property name="halign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkCheckButton" id="_check">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">end</property>
+ <property name="valign">end</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="_artist_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ <property name="ellipsize">middle</property>
+ <property name="max_width_chars">20</property>
+ <property name="lines">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="tile"/>
+ </style>
+ </template>
+</interface>
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
index 0329bdf8..35460787 100644
--- a/data/ui/SearchView.ui
+++ b/data/ui/SearchView.ui
@@ -58,6 +58,7 @@
<property name="selection-mode">none</property>
<property name="valign">start</property>
<property name="visible">True</property>
+ <signal name="child-activated" handler="_on_artist_activated" swapped="no"/>
<style>
<class name="content-view"/>
</style>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index defe92ea..e51c1d73 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -32,7 +32,7 @@ from gnomemusic.widgets.albumcover import AlbumCover
from gnomemusic.widgets.albumwidget import AlbumWidget
from gnomemusic.widgets.headerbar import HeaderBar
from gnomemusic.widgets.artistalbumswidget import ArtistAlbumsWidget
-from gnomemusic.widgets.artisttile import ArtistTile
+from gnomemusic.widgets.artistsearchtile import ArtistSearchTile
from gnomemusic.widgets.songwidget import SongWidget
@@ -156,9 +156,7 @@ class SearchView(Gtk.Stack):
return album_widget
def _create_artist_widget(self, coreartist):
- artist_tile = ArtistTile(coreartist)
- artist_tile.props.text = coreartist.props.artist
- artist_tile.connect('button-release-event', self._artist_activated)
+ artist_tile = ArtistSearchTile(coreartist)
self.bind_property(
"selection-mode", artist_tile, "selection-mode",
@@ -205,40 +203,27 @@ class SearchView(Gtk.Stack):
self.set_visible_child(self._album_widget)
- def _artist_activated(self, widget, event):
+ @Gtk.Template.Callback()
+ def _on_artist_activated(self, widget, child, user_data=None):
coreartist = widget.coreartist
-
- mod_mask = Gtk.accelerator_get_default_mod_mask()
- if ((event.get_state() & mod_mask) == Gdk.ModifierType.CONTROL_MASK
- and not self.props.selection_mode):
- self.props.selection_mode = True
+ if self.props.selection_mode:
return
- (_, button) = event.get_button()
- if (button == Gdk.BUTTON_PRIMARY
- and not self.props.selection_mode):
- # self.emit('song-activated', widget)
+ self._artist_albums_widget = ArtistAlbumsWidget(
+ coreartist, self._application, False)
+ self.add(self._artist_albums_widget)
+ self._artist_albums_widget.show()
- self._artist_albums_widget = ArtistAlbumsWidget(
- coreartist, self._application, False)
- self.add(self._artist_albums_widget)
- self._artist_albums_widget.show()
-
- self.bind_property(
- 'selection-mode', self._artist_albums_widget, 'selection-mode',
- GObject.BindingFlags.BIDIRECTIONAL)
-
- self._headerbar.props.state = HeaderBar.State.SEARCH
- self._headerbar.props.title = coreartist.artist
- self._headerbar.props.subtitle = None
- self.set_visible_child(self._artist_albums_widget)
- self.props.search_mode_active = False
+ self.bind_property(
+ "selection-mode", self._artist_albums_widget, "selection-mode",
+ GObject.BindingFlags.BIDIRECTIONAL)
- # FIXME: Need to ignore the event from the checkbox.
- # if self.props.selection_mode:
- # widget.props.selected = not widget.props.selected
+ self._headerbar.props.state = HeaderBar.State.SEARCH
+ self._headerbar.props.title = coreartist.props.artist
+ self._headerbar.props.subtitle = None
+ self.props.search_mode_active = False
- return True
+ self.set_visible_child(self._artist_albums_widget)
def _select_all(self, value):
with self._model.freeze_notify():
diff --git a/gnomemusic/widgets/artistsearchtile.py b/gnomemusic/widgets/artistsearchtile.py
new file mode 100644
index 00000000..684d39e1
--- /dev/null
+++ b/gnomemusic/widgets/artistsearchtile.py
@@ -0,0 +1,109 @@
+# Copyright 2019 The GNOME Music developers
+#
+# GNOME Music is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNOME Music is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The GNOME Music authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and GNOME Music. This permission is above and beyond the permissions
+# granted by the GPL license by which GNOME Music is covered. If you
+# modify this code, you may extend this exception to your version of the
+# 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 Gdk, GObject, Gtk
+
+from gnomemusic.albumartcache import Art
+from gnomemusic.coreartist import CoreArtist
+from gnomemusic.widgets.artistartstack import ArtistArtStack # noqa: F401
+from gnomemusic.widgets.twolinetip import TwoLineTip
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/ArtistSearchTile.ui")
+class ArtistSearchTile(Gtk.FlowBoxChild):
+ """Artist search tile
+
+ Contains artist art and name
+ """
+
+ __gtype_name__ = "ArtistSearchTile"
+
+ _artist_label = Gtk.Template.Child()
+ _artistart_stack = Gtk.Template.Child()
+ _check = Gtk.Template.Child()
+ _events = Gtk.Template.Child()
+
+ coreartist = GObject.Property(
+ type=CoreArtist, default=None, flags=GObject.ParamFlags.READWRITE)
+ selected = GObject.Property(
+ type=bool, default=False, flags=GObject.ParamFlags.READWRITE)
+ selection_mode = GObject.Property(
+ type=bool, default=False, flags=GObject.ParamFlags.READWRITE)
+
+ def __repr__(self):
+ return "<ArtistSearchTile>"
+
+ def __init__(self, coreartist):
+ """Initialize the ArtistSearchTile
+
+ :param Grl.Media media: The media object to use
+ """
+ super().__init__()
+
+ self.props.coreartist = coreartist
+
+ self._artistart_stack.props.size = Art.Size.MEDIUM
+ self._artistart_stack.props.coreartist = self.props.coreartist
+
+ self._tooltip = TwoLineTip()
+ self._tooltip.props.subtitle_visible = False
+
+ artist = self.props.coreartist.props.artist
+ self._artist_label.props.label = artist
+ self._tooltip.props.title = artist
+
+ self.props.coreartist.connect(
+ "notify::thumbnail", self._on_thumbnail_changed)
+ # trigger
+ self.props.coreartist.props.thumbnail
+
+ self.bind_property(
+ "selected", self._check, "active",
+ GObject.BindingFlags.BIDIRECTIONAL
+ | GObject.BindingFlags.SYNC_CREATE)
+ self.bind_property(
+ "selection-mode", self._check, "visible",
+ GObject.BindingFlags.BIDIRECTIONAL)
+
+ self._events.add_events(Gdk.EventMask.TOUCH_MASK)
+
+ self.show()
+
+ def _on_thumbnail_changed(self, klass, data):
+ print("thumbnail changed", klass, data)
+
+ @Gtk.Template.Callback()
+ def _on_artist_event(self, evbox, event, data=None):
+ modifiers = Gtk.accelerator_get_default_mod_mask()
+ if ((event.get_state() & modifiers) == Gdk.ModifierType.CONTROL_MASK
+ and not self.props.selection_mode):
+ self.props.selection_mode = True
+
+ if self.props.selection_mode:
+ self.props.selected = not self.props.selected
+
+ @Gtk.Template.Callback()
+ def _on_tooltip_query(self, widget, x, y, kb, tooltip, data=None):
+ tooltip.set_custom(self._tooltip)
+ return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]