reworked 'AlbumIconView'

This commit is contained in:
Martin Wagner 2020-03-30 22:20:14 +02:00
parent 3d44f5e9a5
commit 9a3aa7ecad

View File

@ -845,6 +845,11 @@ class AlbumDialog(Gtk.Dialog):
self.client=client self.client=client
self.settings=settings self.settings=settings
#metadata
self.album=album
self.artist=artist
self.year=year
#scroll #scroll
scroll=Gtk.ScrolledWindow() scroll=Gtk.ScrolledWindow()
scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
@ -884,7 +889,7 @@ class AlbumDialog(Gtk.Dialog):
self.column_time.set_property("resizable", False) self.column_time.set_property("resizable", False)
self.treeview.append_column(self.column_time) self.treeview.append_column(self.column_time)
self.populate_treeview(album, artist, year) self.populate_treeview()
#connect #connect
self.treeview.connect("row-activated", self.on_row_activated) self.treeview.connect("row-activated", self.on_row_activated)
@ -918,8 +923,8 @@ class AlbumDialog(Gtk.Dialog):
self.client.add(self.store.get_value(treeiter, 4)) self.client.add(self.store.get_value(treeiter, 4))
self.treeview.handler_unblock(self.key_press_event) self.treeview.handler_unblock(self.key_press_event)
def populate_treeview(self, album, artist, year): def populate_treeview(self):
songs=self.client.find("album", album, "date", year, self.settings.get_artist_type(), artist) songs=self.client.find("album", self.album, "date", self.year, self.settings.get_artist_type(), self.artist)
if not songs == []: if not songs == []:
for song in songs: for song in songs:
try: try:
@ -941,6 +946,15 @@ class AlbumDialog(Gtk.Dialog):
duration=str(datetime.timedelta(seconds=int(dura))) duration=str(datetime.timedelta(seconds=int(dura)))
self.store.append([track, title, artist, duration, song["file"]] ) self.store.append([track, title, artist, duration, song["file"]] )
def open(self):
response = self.run()
if response == Gtk.ResponseType.OK:
self.client.album_to_playlist(self.album, self.artist, self.year, False)
elif response == Gtk.ResponseType.ACCEPT:
self.client.album_to_playlist(self.album, self.artist, self.year, True)
elif response == Gtk.ResponseType.YES:
self.client.album_to_playlist(self.album, self.artist, self.year, False, True)
class GenreSelect(Gtk.ComboBoxText): class GenreSelect(Gtk.ComboBoxText):
def __init__(self, client, settings): def __init__(self, client, settings):
Gtk.ComboBoxText.__init__(self) Gtk.ComboBoxText.__init__(self)
@ -1087,7 +1101,7 @@ class ArtistView(Gtk.ScrolledWindow):
def on_show_initials_settings_changed(self, *args): def on_show_initials_settings_changed(self, *args):
self.column_initials.set_visible(self.settings.get_boolean("show-initials")) self.column_initials.set_visible(self.settings.get_boolean("show-initials"))
class AlbumIconView(Gtk.IconView): #TODO function/var names class AlbumIconView(Gtk.IconView):
def __init__(self, client, settings, genre_select, window): def __init__(self, client, settings, genre_select, window):
Gtk.IconView.__init__(self) Gtk.IconView.__init__(self)
@ -1110,9 +1124,9 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
self.tooltip_settings() self.tooltip_settings()
#connect #connect
self.album_change=self.connect("selection-changed", self.on_album_selection_change) self.connect("item-activated", self.on_item_activated)
self.connect("item-activated", self.on_album_item_activated) self.connect("button-press-event", self.on_button_press_event)
self.connect("button-press-event", self.on_album_view_button_press_event) self.key_press_event=self.connect("key-press-event", self.on_key_press_event)
self.settings.connect("changed::show-album-view-tooltips", self.tooltip_settings) self.settings.connect("changed::show-album-view-tooltips", self.tooltip_settings)
self.settings.connect("changed::sort-albums-by-year", self.sort_settings) self.settings.connect("changed::sort-albums-by-year", self.sort_settings)
@ -1134,7 +1148,7 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING) self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
return False return False
def add(self, row, cover, size): def add_row(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
@ -1185,9 +1199,9 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
length_human_readable=str(datetime.timedelta(seconds=int(length))) 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}) tooltip=(_("%(total_tracks)i titles (%(total_length)s)") % {"total_tracks": len(album["songs"]), "total_length": length_human_readable})
if album["year"] == "": if album["year"] == "":
GLib.idle_add(self.add, [None, album["album"], tooltip, album["album"], album["year"], album["artist"]], cover, size) GLib.idle_add(self.add_row, [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_row, [None, album["album"]+" ("+album["year"]+")", tooltip, album["album"], album["year"], album["artist"]], cover, size)
if z%16 == 0: if z%16 == 0:
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration_do(True) Gtk.main_iteration_do(True)
@ -1200,7 +1214,6 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
def scroll_to_selected_album(self): def scroll_to_selected_album(self):
songid=self.client.status()["songid"] songid=self.client.status()["songid"]
song=self.client.playlistid(songid)[0] song=self.client.playlistid(songid)[0]
self.handler_block(self.album_change)
self.unselect_all() 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):
@ -1211,40 +1224,49 @@ class AlbumIconView(Gtk.IconView): #TODO function/var names
self.select_path(path) self.select_path(path)
self.scroll_to_path(path, True, 0, 0) self.scroll_to_path(path, True, 0, 0)
break break
self.handler_unblock(self.album_change)
def on_album_view_button_press_event(self, widget, event): def path_to_playlist(self, path, add, force=False):
album=self.store[path][3]
year=self.store[path][4]
artist=self.store[path][5]
self.client.album_to_playlist(album, artist, year, add, force)
def open_album_dialog(self, path):
if self.client.connected():
album=self.store[path][3]
year=self.store[path][4]
artist=self.store[path][5]
album_dialog = AlbumDialog(self.window, self.client, self.settings, album, artist, year)
album_dialog.open()
album_dialog.destroy()
def on_button_press_event(self, widget, event):
path = widget.get_path_at_pos(int(event.x), int(event.y)) path = widget.get_path_at_pos(int(event.x), int(event.y))
if not path == None: if not path == None:
if not event.button == 1: if event.button == 1 and event.type == Gdk.EventType.BUTTON_PRESS:
treeiter=self.store.get_iter(path) self.path_to_playlist(path, False)
selected_album=self.store.get_value(treeiter, 3) elif event.button == 2 and event.type == Gdk.EventType.BUTTON_PRESS:
selected_album_year=self.store.get_value(treeiter, 4) self.path_to_playlist(path, True)
selected_artist=self.store.get_value(treeiter, 5)
if event.button == 2 and event.type == Gdk.EventType.BUTTON_PRESS:
self.client.album_to_playlist(selected_album, selected_artist, selected_album_year, True)
elif event.button == 3 and event.type == Gdk.EventType.BUTTON_PRESS: elif event.button == 3 and event.type == Gdk.EventType.BUTTON_PRESS:
if self.client.connected(): self.open_album_dialog(path)
album = AlbumDialog(self.window, self.client, self.settings, selected_album, selected_artist, selected_album_year)
response = album.run()
if response == Gtk.ResponseType.OK:
self.select_path(path)
elif response == Gtk.ResponseType.ACCEPT:
self.client.album_to_playlist(selected_album, selected_artist, selected_album_year, True)
elif response == Gtk.ResponseType.YES:
self.client.album_to_playlist(selected_album, selected_artist, selected_album_year, False, True)
album.destroy()
def on_album_selection_change(self, widget): def on_key_press_event(self, widget, event):
paths=widget.get_selected_items() self.handler_block(self.key_press_event)
if event.keyval == 112: #p
paths=self.get_selected_items()
if not len(paths) == 0: if not len(paths) == 0:
treeiter=self.store.get_iter(paths[0]) self.path_to_playlist(paths[0], False)
selected_album=self.store.get_value(treeiter, 3) elif event.keyval == 97: #a
selected_album_year=self.store.get_value(treeiter, 4) paths=self.get_selected_items()
selected_artist=self.store.get_value(treeiter, 5) if not len(paths) == 0:
self.client.album_to_playlist(selected_album, selected_artist, selected_album_year, False) self.path_to_playlist(paths[0], True)
elif event.keyval == 65383: #menu key
paths=self.get_selected_items()
if not len(paths) == 0:
self.open_album_dialog(paths[0])
self.handler_unblock(self.key_press_event)
def on_album_item_activated(self, widget, path): def on_item_activated(self, widget, path):
treeiter=self.store.get_iter(path) treeiter=self.store.get_iter(path)
selected_album=self.store.get_value(treeiter, 3) selected_album=self.store.get_value(treeiter, 3)
selected_album_year=self.store.get_value(treeiter, 4) selected_album_year=self.store.get_value(treeiter, 4)
@ -1379,13 +1401,7 @@ class MainCover(Gtk.Frame):
self.client.album_to_playlist(album, artist, album_year, True) self.client.album_to_playlist(album, artist, album_year, True)
elif event.button == 3 and event.type == Gdk.EventType.BUTTON_PRESS: elif event.button == 3 and event.type == Gdk.EventType.BUTTON_PRESS:
album_dialog = AlbumDialog(self.window, self.client, self.settings, album, artist, album_year) album_dialog = AlbumDialog(self.window, self.client, self.settings, album, artist, album_year)
response = album_dialog.run() album_dialog.open()
if response == Gtk.ResponseType.OK:
self.client.album_to_playlist(album, artist, album_year, False)
elif response == Gtk.ResponseType.ACCEPT:
self.client.album_to_playlist(album, artist, album_year, True)
elif response == Gtk.ResponseType.YES:
self.client.album_to_playlist(album, artist, album_year, False, True)
album_dialog.destroy() album_dialog.destroy()
def on_settings_changed(self, *args): def on_settings_changed(self, *args):