WIP
This commit is contained in:
@@ -11,16 +11,11 @@ from .icon_button import IconButton
|
||||
from .load_error import LoadError
|
||||
from .song_list_column import SongListColumn
|
||||
from .spinner_image import SpinnerImage
|
||||
from ..actions import run_action
|
||||
|
||||
|
||||
class AlbumWithSongs(Gtk.Box):
|
||||
__gsignals__ = {
|
||||
# "song-selected": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ()),
|
||||
"song-clicked": (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(int, object, object),
|
||||
),
|
||||
"back-clicked": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ()),
|
||||
}
|
||||
|
||||
@@ -166,8 +161,7 @@ class AlbumWithSongs(Gtk.Box):
|
||||
margin_bottom=10,
|
||||
)
|
||||
selection = self.album_songs.get_selection()
|
||||
selection.set_mode(Gtk.SelectionMode.MULTIPLE)
|
||||
selection.set_select_function(lambda _, model, path, current: model[path[0]][0])
|
||||
selection.set_mode(Gtk.SelectionMode.SINGLE)
|
||||
|
||||
# Song status column.
|
||||
renderer = Gtk.CellRendererPixbuf()
|
||||
@@ -188,20 +182,19 @@ class AlbumWithSongs(Gtk.Box):
|
||||
|
||||
# Event Handlers
|
||||
# =========================================================================
|
||||
def on_song_selection_change(self, event: Any):
|
||||
if not self.album_songs.has_focus():
|
||||
self.emit("song-selected")
|
||||
def on_song_selection_change(self, selection: Gtk.TreeSelection):
|
||||
paths = selection.get_selected_rows()[1]
|
||||
if not paths:
|
||||
return
|
||||
|
||||
assert len(paths) == 1
|
||||
self.play_song(paths[0].get_indices()[0], {})
|
||||
|
||||
def on_song_activated(self, treeview: Any, idx: Gtk.TreePath, column: Any):
|
||||
if not self.album_song_store[idx[0]][0]:
|
||||
return
|
||||
# The song ID is in the last column of the model.
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
idx.get_indices()[0],
|
||||
[m[-1] for m in self.album_song_store],
|
||||
{},
|
||||
)
|
||||
|
||||
self.play_song(idx.get_indices()[0], {})
|
||||
|
||||
def on_song_button_press(self, tree: Any, event: Gdk.EventButton) -> bool:
|
||||
if event.button == 3: # Right click
|
||||
@@ -250,22 +243,14 @@ class AlbumWithSongs(Gtk.Box):
|
||||
)
|
||||
|
||||
def play_btn_clicked(self, btn: Any):
|
||||
song_ids = [x[-1] for x in self.album_song_store]
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
0,
|
||||
song_ids,
|
||||
{"force_shuffle_state": False},
|
||||
)
|
||||
self.play_song(0, {"force_shuffle_state": False})
|
||||
|
||||
def shuffle_btn_clicked(self, btn: Any):
|
||||
song_ids = [x[-1] for x in self.album_song_store]
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
randint(0, len(self.album_song_store) - 1),
|
||||
song_ids,
|
||||
{"force_shuffle_state": True},
|
||||
)
|
||||
self.play_song(randint(0, len(self.album_song_store) - 1),
|
||||
{"force_shuffle_state": True})
|
||||
|
||||
def play_song(self, index: int, metadata: Any):
|
||||
run_action(self, 'app.play-song', index, [m[-1] for m in self.album_song_store], metadata)
|
||||
|
||||
# Helper Methods
|
||||
# =========================================================================
|
||||
@@ -403,8 +388,8 @@ class AlbumWithSongs(Gtk.Box):
|
||||
if any_song_playable:
|
||||
self.play_next_btn.set_action_target_value(GLib.Variant("as", song_ids))
|
||||
self.add_to_queue_btn.set_action_target_value(GLib.Variant("as", song_ids))
|
||||
self.play_next_btn.set_action_name("app.play-next")
|
||||
self.add_to_queue_btn.set_action_name("app.add-to-queue")
|
||||
self.play_next_btn.set_action_name("app.queue-next-songs")
|
||||
self.add_to_queue_btn.set_action_name("app.queue-songs")
|
||||
else:
|
||||
self.play_next_btn.set_action_name("")
|
||||
self.add_to_queue_btn.set_action_name("")
|
||||
|
Reference in New Issue
Block a user