mirror of
https://github.com/SoongNoonien/mpdevil.git
synced 2023-08-10 21:12:44 +03:00
made displaying of albums a bit faster
This commit is contained in:
parent
e1b6883988
commit
1dfb744b60
126
bin/mpdevil.py
126
bin/mpdevil.py
|
@ -1071,7 +1071,8 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
|
||||||
self.connect("motion-notify-event", self.on_move_event)
|
self.connect("motion-notify-event", self.on_move_event)
|
||||||
|
|
||||||
@GObject.Signal
|
@GObject.Signal
|
||||||
def stopped(self):
|
def done(self):
|
||||||
|
# print("done")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def tooltip_settings(self, *args):
|
def tooltip_settings(self, *args):
|
||||||
|
@ -1086,55 +1087,50 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
|
||||||
else:
|
else:
|
||||||
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
||||||
|
|
||||||
def gen_tooltip(self, album, artist, year):
|
def add(self, row, cover, size):
|
||||||
songs=self.client.find("album", album, "date", year, self.settings.get_artist_type(), artist)
|
row[0]=cover.get_pixbuf(size)
|
||||||
length=float(0)
|
self.store.append(row)
|
||||||
for song in songs:
|
return False
|
||||||
try:
|
|
||||||
dura=float(song["duration"])
|
def display_albums(self, albums, music_lib, size):
|
||||||
except:
|
for album in albums:
|
||||||
dura=0.0
|
cover=Cover(lib_path=music_lib, song_file=album["songs"][0]["file"])
|
||||||
length=length+dura
|
#tooltip
|
||||||
length_human_readable=str(datetime.timedelta(seconds=int(length)))
|
length=float(0)
|
||||||
tooltip=(_("%(total_tracks)i titles (%(total_length)s)") % {"total_tracks": len(songs), "total_length": length_human_readable})
|
for song in album["songs"]:
|
||||||
return tooltip
|
try:
|
||||||
|
dura=float(song["duration"])
|
||||||
|
except:
|
||||||
|
dura=0.0
|
||||||
|
length=length+dura
|
||||||
|
length_human_readable=str(datetime.timedelta(seconds=int(length)))
|
||||||
|
tooltip=(_("%(total_tracks)i titles (%(total_length)s)") % {"total_tracks": len(album["songs"]), "total_length": length_human_readable})
|
||||||
|
if album["year"] == "":
|
||||||
|
GLib.idle_add(self.add, [None, album["album"], tooltip, album["album"], album["year"], album["artist"]], cover, size)
|
||||||
|
else:
|
||||||
|
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")
|
||||||
|
# print("end")
|
||||||
|
|
||||||
def populate(self, artists):
|
def populate(self, artists):
|
||||||
self.stop_flag=False
|
#prepare albmus list
|
||||||
size=self.settings.get_int("album-cover")
|
self.store.clear()
|
||||||
albums=[]
|
albums=[]
|
||||||
genre=self.genre_select.get_value()
|
genre=self.genre_select.get_value()
|
||||||
|
artist_type=self.settings.get_artist_type()
|
||||||
for artist in artists:
|
for artist in artists:
|
||||||
if genre == None:
|
if genre == None:
|
||||||
album_candidates=self.client.list("album", self.settings.get_artist_type(), artist)
|
album_candidates=self.client.list("album", artist_type, artist)
|
||||||
else:
|
else:
|
||||||
album_candidates=self.client.list("album", self.settings.get_artist_type(), artist, "genre", genre)
|
album_candidates=self.client.list("album", artist_type, artist, "genre", genre)
|
||||||
for album in album_candidates:
|
for album in album_candidates:
|
||||||
albums.append({"artist": artist, "album": album, "year": self.client.list("date", "album", album, self.settings.get_artist_type(), artist)[0]})
|
years=self.client.list("date", "album", album, artist_type, artist)
|
||||||
if self.settings.get_boolean("sort-albums-by-year"):
|
for year in years:
|
||||||
albums = sorted(albums, key=lambda k: k['year'])
|
songs=self.client.find("album", album, "date", year, artist_type, artist)
|
||||||
else:
|
albums.append({"artist": artist, "album": album, "year": year, "songs": songs})
|
||||||
albums = sorted(albums, key=lambda k: k['album'])
|
#start thread
|
||||||
for album in albums:
|
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)
|
||||||
if self.client.connected() and not self.stop_flag: #self.get_visible() and self.client.connected() and
|
display_thread.start()
|
||||||
songs=self.client.find("album", album["album"], "date", album["year"], self.settings.get_artist_type(), album["artist"])
|
|
||||||
if songs == []:
|
|
||||||
song_file=None
|
|
||||||
else:
|
|
||||||
song_file=songs[0]["file"]
|
|
||||||
cover=Cover(lib_path=self.settings.get_value("paths")[self.settings.get_int("active-profile")], song_file=song_file)
|
|
||||||
img=cover.get_pixbuf(size)
|
|
||||||
if album["year"] == "":
|
|
||||||
self.store.append([img, album["album"], self.gen_tooltip(album["album"], album["artist"], album["year"]), album["album"], album["year"], album["artist"]])
|
|
||||||
else:
|
|
||||||
self.store.append([img, album["album"]+" ("+album["year"]+")", self.gen_tooltip(album["album"], album["artist"], album["year"]), album["album"], album["year"], album["artist"]])
|
|
||||||
while Gtk.events_pending():
|
|
||||||
Gtk.main_iteration_do(True)
|
|
||||||
else:
|
|
||||||
self.store.clear()
|
|
||||||
self.emit("stopped")
|
|
||||||
break
|
|
||||||
self.stop_flag=True
|
|
||||||
|
|
||||||
def scroll_to_selected_album(self):
|
def scroll_to_selected_album(self):
|
||||||
songid=self.client.status()["songid"]
|
songid=self.client.status()["songid"]
|
||||||
|
@ -1204,42 +1200,50 @@ 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.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)
|
||||||
|
|
||||||
#connect
|
#connect
|
||||||
self.iconview.connect("stopped", self.on_iconview_stopped)
|
|
||||||
self.settings.connect("changed::album-cover", self.on_settings_changed)
|
self.settings.connect("changed::album-cover", self.on_settings_changed)
|
||||||
|
self.iconview.connect("done", self.on_done)
|
||||||
|
|
||||||
self.add(self.iconview)
|
self.add(self.iconview)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.artists=[]
|
self.artists=[]
|
||||||
if self.iconview.stop_flag:
|
self.iconview.store.clear()
|
||||||
self.iconview.store.clear()
|
|
||||||
else:
|
|
||||||
self.iconview.stop_flag=True
|
|
||||||
|
|
||||||
def refresh(self, artists):
|
def refresh(self, artists):
|
||||||
if artists != self.artists:
|
self.done=False
|
||||||
self.artists=artists
|
self.artists=artists
|
||||||
if self.iconview.stop_flag:
|
try:
|
||||||
self.iconview.store.clear()
|
self.iconview.populate(artists)
|
||||||
self.iconview.emit("stopped")
|
except:
|
||||||
else:
|
pass
|
||||||
self.iconview.stop_flag=True
|
|
||||||
|
|
||||||
def scroll_to_selected_album(self):
|
def scroll_to_selected_album(self):
|
||||||
self.iconview.scroll_to_selected_album()
|
if self.done:
|
||||||
|
self.iconview.scroll_to_selected_album()
|
||||||
|
elif not self.scroll_to_selected_album in self.pending:
|
||||||
|
self.pending.append(self.scroll_to_selected_album)
|
||||||
|
|
||||||
def on_iconview_stopped(self, *args):
|
def on_done(self, *args):
|
||||||
if self.client.connected():
|
self.done=True
|
||||||
self.iconview.populate(self.artists)
|
pending=self.pending
|
||||||
|
self.pending=[]
|
||||||
|
for p in pending:
|
||||||
|
try:
|
||||||
|
p()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def on_settings_changed(self, *args):
|
def on_settings_changed(self, *args):
|
||||||
artists=self.artists
|
if self.done:
|
||||||
self.artists=[]
|
self.refresh(self.artists)
|
||||||
self.refresh(artists)
|
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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user