[gnome-music/wip/jfelder/gtk4-v3: 92/108] searchview: Rework album/artist sizing
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/gtk4-v3: 92/108] searchview: Rework album/artist sizing
- Date: Fri, 11 Feb 2022 11:10:32 +0000 (UTC)
commit e3ed0add958d1b8b6e3adecc80ab7910c718b928
Author: Marinus Schraal <mschraal gnome org>
Date: Thu Feb 10 14:15:58 2022 +0100
searchview: Rework album/artist sizing
FIXME: Initial sizing still off.
gnomemusic/views/searchview.py | 112 ++++++++---------------------------------
1 file changed, 21 insertions(+), 91 deletions(-)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 1395745ec..c3bfb7ce1 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -31,6 +31,7 @@ import typing
from gi.repository import Gdk, GObject, Gtk
from gnomemusic.search import Search
+from gnomemusic.utils import ArtSize
from gnomemusic.widgets.albumcover import AlbumCover
from gnomemusic.widgets.albumwidget import AlbumWidget
from gnomemusic.widgets.headerbar import HeaderBar
@@ -94,41 +95,32 @@ class SearchView(Gtk.Stack):
self._application = application
self._coremodel = application.props.coremodel
self._model = self._coremodel.props.songs_search
- self._album_model = self._coremodel.props.albums_search
- self._album_filter = self._coremodel.props.albums_search_filter
- # self._album_filter.set_filter_func(
- # self._core_filter, self._album_model, 12)
+ self._player = self._application.props.player
+ self._window = application.props.window
+ self._headerbar = self._window._headerbar
+ self._album_model = self._coremodel.props.albums_search
self._artist_model = self._coremodel.props.artists_search
- self._artist_filter = self._coremodel.props.artists_search_filter
- # self._artist_filter.set_filter_func(
- # self._core_filter, self._artist_model, 6)
+
+ self._album_slice = Gtk.SliceListModel.new(self._album_model, 0,8)
+ self._artist_slice = Gtk.SliceListModel.new(self._artist_model, 0, 6)
self._model.connect_after(
"items-changed", self._on_model_items_changed)
self._songs_listbox.bind_model(self._model, self._create_song_widget)
self._on_model_items_changed(self._model, 0, 0, 0)
- self._album_filter.connect_after(
+ self._album_slice.connect_after(
"items-changed", self._on_album_model_items_changed)
self._album_flowbox.bind_model(
- self._album_filter, self._create_album_cover)
- # self._album_flowbox.connect(
- # "size-allocate", self._on_album_flowbox_size_allocate)
- self._on_album_model_items_changed(self._album_filter, 0, 0, 0)
+ self._album_slice, self._create_album_cover)
+ self._application.props.window.connect(
+ "notify::default-width", self._on_window_width_change)
- self._artist_filter.connect_after(
+ self._artist_slice.connect_after(
"items-changed", self._on_artist_model_items_changed)
self._artist_flowbox.bind_model(
- self._artist_filter, self._create_artist_widget)
- # self._artist_flowbox.connect(
- # "size-allocate", self._on_artist_flowbox_size_allocate)
- self._on_artist_model_items_changed(self._artist_filter, 0, 0, 0)
-
- self._player = self._application.props.player
-
- self._window = application.props.window
- self._headerbar = self._window._headerbar
+ self._artist_slice, self._create_artist_widget)
self.connect("notify::selection-mode", self._on_selection_mode_changed)
@@ -267,76 +259,14 @@ class SearchView(Gtk.Stack):
return True
- def _on_album_flowbox_size_allocate(self, widget, allocation, data=None):
- nb_children = self._album_filter.get_n_items()
- if nb_children == 0:
- return
-
- first_child = self._album_flowbox.get_child_at_index(0)
- child_height = first_child.get_allocation().height
- if allocation.height > 2.5 * child_height:
- for i in range(nb_children - 1, -1, -1):
- child = self._album_flowbox.get_child_at_index(i)
- if child.props.visible is True:
- child.props.visible = False
- return
-
- children_hidden = False
- for idx in range(nb_children):
- child = self._album_flowbox.get_child_at_index(idx)
- if not child.props.visible:
- children_hidden = True
- break
- if children_hidden is False:
- return
-
- last_visible_child = self._album_flowbox.get_child_at_index(idx - 1)
- first_row_last = self._album_flowbox.get_child_at_index((idx - 1) // 2)
- second_row_pos = last_visible_child.get_allocation().x
- first_row_pos = first_row_last.get_allocation().x
- child_width = last_visible_child.get_allocation().width
- nb_children_to_add = (first_row_pos - second_row_pos) // child_width
- nb_children_to_add = min(nb_children_to_add + idx, nb_children)
- for i in range(idx, nb_children_to_add):
- child = self._album_flowbox.get_child_at_index(i)
- child.props.visible = True
-
- def _on_artist_flowbox_size_allocate(self, widget, allocation, data=None):
- nb_children = self._artist_filter.get_n_items()
- if nb_children == 0:
- return
-
- first_child = self._artist_flowbox.get_child_at_index(0)
- # FIXME: It looks like it is possible that the widget is not
- # yet created, resulting in a crash with first_child being
- # None.
- # Look for a cleaner solution.
- if first_child is None:
- return
-
- child_height = first_child.get_allocation().height
- if allocation.height > 1.5 * child_height:
- for i in range(nb_children - 1, -1, -1):
- child = self._artist_flowbox.get_child_at_index(i)
- if child.props.visible is True:
- child.props.visible = False
- return
-
- children_hidden = False
- for idx in range(nb_children):
- child = self._artist_flowbox.get_child_at_index(idx)
- if not child.props.visible:
- children_hidden = True
- break
- if children_hidden is False:
- return
+ def _on_window_width_change(self, widget, value):
+ allocation = self._album_flowbox.get_allocation()
+ # FIXME: Just a bit of guesswork here.
+ padding = 32
+ items_per_row = int(allocation.width / (ArtSize.MEDIUM.width + padding))
- last_child = self._artist_flowbox.get_child_at_index(idx - 1)
- last_child_allocation = last_child.get_allocation()
- child_width = last_child_allocation.width
- if (last_child_allocation.x + 2 * child_width) < allocation.width:
- child = self._artist_flowbox.get_child_at_index(idx)
- child.props.visible = True
+ self._album_slice.props.size = 2 * items_per_row
+ self._artist_slice.props.size = items_per_row
@Gtk.Template.Callback()
def _on_album_activated(self, widget, child, user_data=None):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]