always select current album in AlbumList when possible

This commit is contained in:
Martin Wagner
2022-09-03 10:12:41 +02:00
parent 750a311327
commit f24f58e930

View File

@ -2055,9 +2055,12 @@ class AlbumLoadingThread(threading.Thread):
else: else:
main_thread_function(self._store.set_sort_column_id)(6, Gtk.SortType.ASCENDING) main_thread_function(self._store.set_sort_column_id)(6, Gtk.SortType.ASCENDING)
idle_add(self._iconview.set_model, self._store) idle_add(self._iconview.set_model, self._store)
# select first album # select album
idle_add(self._iconview.set_cursor, Gtk.TreePath(0), None, False) path=main_thread_function(self._iconview.get_current_album_path)()
idle_add(self._iconview.select_path, Gtk.TreePath(0)) if path is None:
path=Gtk.TreePath(0)
idle_add(self._iconview.set_cursor, path, None, False)
idle_add(self._iconview.select_path, path)
# load covers # load covers
total=2*len(self._store) total=2*len(self._store)
@main_thread_function @main_thread_function
@ -2153,19 +2156,24 @@ class AlbumList(Gtk.IconView):
else: else:
callback() callback()
def scroll_to_current_album(self): def get_current_album_path(self):
def callback(): if (song:=self._client.currentsong()) is not None:
song=self._client.currentsong() album=[song["albumartist"][0], song["album"][0], song["date"][0]]
album=song["album"][0]
self.unselect_all()
row_num=len(self._store) row_num=len(self._store)
for i in range(0, row_num): for i in range(0, row_num):
path=Gtk.TreePath(i) path=Gtk.TreePath(i)
if self._store[path][4] == album: if self._store[path][3:6] == album:
self.set_cursor(path, None, False) return path
self.select_path(path) return None
self.scroll_to_path(path, True, 0, 0) else:
break return None
def scroll_to_current_album(self):
def callback():
if (path:=self.get_current_album_path()) is not None:
self.set_cursor(path, None, False)
self.select_path(path)
self.scroll_to_path(path, True, 0, 0)
if self._cover_thread.is_alive(): if self._cover_thread.is_alive():
self._cover_thread.set_callback(callback) self._cover_thread.set_callback(callback)
else: else: