disabled gui stalls on album display

This commit is contained in:
Martin Wagner 2020-03-29 18:06:37 +02:00
parent e073c81438
commit be87be9923

View File

@ -1079,7 +1079,7 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
@GObject.Signal @GObject.Signal
def done(self): def done(self):
# print("done") self.stop_flag=True
pass pass
def tooltip_settings(self, *args): def tooltip_settings(self, *args):
@ -1093,14 +1093,43 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
self.store.set_sort_column_id(4, Gtk.SortType.ASCENDING) self.store.set_sort_column_id(4, Gtk.SortType.ASCENDING)
else: else:
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING) self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
return False
def add(self, row, cover, size): def add(self, row, cover, size):
row[0]=cover.get_pixbuf(size) row[0]=cover.get_pixbuf(size)
self.store.append(row) self.store.append(row)
return False return False
def display_albums(self, albums, music_lib, size): def populate(self, artists):
self.stop_flag=False
#prepare albmus list
self.store.clear()
albums=[]
genre=self.genre_select.get_value()
artist_type=self.settings.get_artist_type()
for artist in artists:
if not self.stop_flag:
if genre == None:
album_candidates=self.client.list("album", artist_type, artist)
else:
album_candidates=self.client.list("album", artist_type, artist, "genre", genre)
for album in album_candidates:
years=self.client.list("date", "album", album, artist_type, artist)
for year in years:
songs=self.client.find("album", album, "date", year, artist_type, artist)
albums.append({"artist": artist, "album": album, "year": year, "songs": songs})
while Gtk.events_pending():
Gtk.main_iteration_do(True)
else:
GLib.idle_add(self.emit, "done")
return
#display albums
self.store.set_sort_column_id(Gtk.TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, Gtk.SortType.ASCENDING)
music_lib=self.settings.get_value("paths")[self.settings.get_int("active-profile")]
size=self.settings.get_int("album-cover")
z=0
for album in albums: for album in albums:
if not self.stop_flag:
cover=Cover(lib_path=music_lib, song_file=album["songs"][0]["file"]) cover=Cover(lib_path=music_lib, song_file=album["songs"][0]["file"])
#tooltip #tooltip
length=float(0) length=float(0)
@ -1116,28 +1145,14 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
GLib.idle_add(self.add, [None, album["album"], tooltip, album["album"], album["year"], album["artist"]], cover, size) GLib.idle_add(self.add, [None, album["album"], tooltip, album["album"], album["year"], album["artist"]], cover, size)
else: else:
GLib.idle_add(self.add, [None, album["album"]+" ("+album["year"]+")", tooltip, album["album"], album["year"], album["artist"]], cover, size) GLib.idle_add(self.add, [None, album["album"]+" ("+album["year"]+")", tooltip, album["album"], album["year"], album["artist"]], cover, size)
GLib.idle_add(self.emit, "done") if z%16 == 0:
# print("end") while Gtk.events_pending():
Gtk.main_iteration_do(True)
def populate(self, artists): z=z+1
#prepare albmus list
self.store.clear()
albums=[]
genre=self.genre_select.get_value()
artist_type=self.settings.get_artist_type()
for artist in artists:
if genre == None:
album_candidates=self.client.list("album", artist_type, artist)
else: else:
album_candidates=self.client.list("album", artist_type, artist, "genre", genre) break
for album in album_candidates: GLib.idle_add(self.sort_settings)
years=self.client.list("date", "album", album, artist_type, artist) GLib.idle_add(self.emit, "done")
for year in years:
songs=self.client.find("album", album, "date", year, artist_type, artist)
albums.append({"artist": artist, "album": album, "year": year, "songs": songs})
#start thread
display_thread=threading.Thread(target=self.display_albums, kwargs={"albums": albums, "music_lib": self.settings.get_value("paths")[self.settings.get_int("active-profile")], "size": self.settings.get_int("album-cover")}, daemon=True)
display_thread.start()
def scroll_to_selected_album(self): def scroll_to_selected_album(self):
songid=self.client.status()["songid"] songid=self.client.status()["songid"]
@ -1205,7 +1220,7 @@ class AlbumView(Gtk.ScrolledWindow):
self.genre_select=genre_select self.genre_select=genre_select
self.window=window self.window=window
self.artists=[] self.artists=[]
self.done=False self.done=True
self.pending=[] self.pending=[]
self.iconview=AlbumIconView(self.client, self.settings, self.genre_select, self.window) self.iconview=AlbumIconView(self.client, self.settings, self.genre_select, self.window)
@ -1222,12 +1237,16 @@ class AlbumView(Gtk.ScrolledWindow):
self.iconview.store.clear() self.iconview.store.clear()
def refresh(self, artists): def refresh(self, artists):
self.done=False
self.artists=artists self.artists=artists
try: if self.done:
self.iconview.populate(artists) self.done=False
except: self.populate()
pass elif not self.populate in self.pending:
self.iconview.stop_flag=True
self.pending.append(self.populate)
def populate(self):
self.iconview.populate(self.artists)
def scroll_to_selected_album(self): def scroll_to_selected_album(self):
if self.done: if self.done:
@ -1247,9 +1266,7 @@ class AlbumView(Gtk.ScrolledWindow):
def on_settings_changed(self, *args): def on_settings_changed(self, *args):
if self.done: if self.done:
self.refresh(self.artists) self.populate()
elif not self.on_settings_changed in self.pending:
self.pending.append(self.on_settings_changed)
class MainCover(Gtk.EventBox): class MainCover(Gtk.EventBox):
def __init__(self, client, settings, emitter, window): def __init__(self, client, settings, emitter, window):