This commit is contained in:
Benjamin Schaaf
2021-02-01 18:38:18 +11:00
parent e1dcf8da4c
commit c612f31f42
3 changed files with 94 additions and 98 deletions

View File

@@ -1,5 +1,9 @@
from typing import List, Any
from .. import util
from ..common import IconButton, IconToggleButton, SpinnerImage, SpinnerPicture from ..common import IconButton, IconToggleButton, SpinnerImage, SpinnerPicture
from .manager import Manager from .manager import Manager
from ...util import resolve_path
from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, Pango, Handy from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, Pango, Handy
@@ -79,3 +83,59 @@ def create_label(manager: Manager, property: str, **kwargs):
label = Gtk.Label(**kwargs) label = Gtk.Label(**kwargs)
manager.bind_property(property, label, "label") manager.bind_property(property, label, "label")
return label return label
def show_play_queue_popover(manager: Manager, relative_to, paths: List[str], pos_x: int, pos_y: int):
song_ids = [manager.play_queue_store[p][-1] for p in paths]
remove_text = (
"Remove " + util.pluralize("song", len(song_ids)) + " from queue"
)
def on_download_state_change(song_id: str):
# Refresh the entire window (no force) because the song could
# be in a list anywhere in the window.
manager.emit("refresh-window", {}, False)
def on_remove_songs_click(_: Any):
manager.emit("songs-removed", [p.get_indices()[0] for p in paths])
util.show_song_popover(
song_ids,
pos_x,
pos_y,
relative_to,
manager.offline_mode,
on_download_state_change=on_download_state_change,
extra_menu_items=[
(Gtk.ModelButton(text=remove_text), on_remove_songs_click),
],
)
# Album Art column. This function defines what image to use for the play queue
# song icon.
def filename_to_pixbuf(
column: Any,
cell: Gtk.CellRendererPixbuf,
model: Gtk.ListStore,
tree_iter: Gtk.TreeIter,
flags: Any,
):
cell.set_property("sensitive", model.get_value(tree_iter, 0))
filename = model.get_value(tree_iter, 1)
if not filename:
cell.set_property("icon_name", "")
return
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename, 50, 50, True)
# If this is the playing song, then overlay the play icon.
if model.get_value(tree_iter, 3):
play_overlay_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
str(resolve_path("ui/images/play-queue-play.png"))
)
play_overlay_pixbuf.composite(
pixbuf, 0, 0, 50, 50, 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 200
)
cell.set_property("pixbuf", pixbuf)

View File

@@ -214,37 +214,13 @@ class Desktop(Gtk.Box):
store, paths = tree.get_selection().get_selected_rows() store, paths = tree.get_selection().get_selected_rows()
allow_deselect = False allow_deselect = False
def on_download_state_change(song_id: str):
# Refresh the entire window (no force) because the song could
# be in a list anywhere in the window.
self.state.emit("refresh-window", {}, False)
# Use the new selection instead of the old one for calculating what # Use the new selection instead of the old one for calculating what
# to do the right click on. # to do the right click on.
if clicked_path[0] not in paths: if clicked_path[0] not in paths:
paths = [clicked_path[0]] paths = [clicked_path[0]]
allow_deselect = True allow_deselect = True
song_ids = [self.play_queue_store[p][-1] for p in paths] common.show_play_queue_popover(self.state, tree, paths, event.x, event.y)
remove_text = (
"Remove " + util.pluralize("song", len(song_ids)) + " from queue"
)
def on_remove_songs_click(_: Any):
self.state.emit("songs-removed", [p.get_indices()[0] for p in paths])
util.show_song_popover(
song_ids,
event.x,
event.y,
tree,
self.offline_mode,
on_download_state_change=on_download_state_change,
extra_menu_items=[
(Gtk.ModelButton(text=remove_text), on_remove_songs_click),
],
)
# If the click was on a selected row, don't deselect anything. # If the click was on a selected row, don't deselect anything.
if not allow_deselect: if not allow_deselect:
@@ -405,39 +381,10 @@ class Desktop(Gtk.Box):
selection.set_mode(Gtk.SelectionMode.MULTIPLE) selection.set_mode(Gtk.SelectionMode.MULTIPLE)
selection.set_select_function(lambda _, model, path, current: model[path[0]][0]) selection.set_select_function(lambda _, model, path, current: model[path[0]][0])
# Album Art column. This function defines what image to use for the play queue
# song icon.
def filename_to_pixbuf(
column: Any,
cell: Gtk.CellRendererPixbuf,
model: Gtk.ListStore,
tree_iter: Gtk.TreeIter,
flags: Any,
):
cell.set_property("sensitive", model.get_value(tree_iter, 0))
filename = model.get_value(tree_iter, 1)
if not filename:
cell.set_property("icon_name", "")
return
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename, 50, 50, True)
# If this is the playing song, then overlay the play icon.
if model.get_value(tree_iter, 3):
play_overlay_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
str(resolve_path("ui/images/play-queue-play.png"))
)
play_overlay_pixbuf.composite(
pixbuf, 0, 0, 50, 50, 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 200
)
cell.set_property("pixbuf", pixbuf)
renderer = Gtk.CellRendererPixbuf() renderer = Gtk.CellRendererPixbuf()
renderer.set_fixed_size(55, 60) renderer.set_fixed_size(55, 60)
column = Gtk.TreeViewColumn("", renderer) column = Gtk.TreeViewColumn("", renderer)
column.set_cell_data_func(renderer, filename_to_pixbuf) column.set_cell_data_func(renderer, common.filename_to_pixbuf)
column.set_resizable(True) column.set_resizable(True)
self.play_queue_list.append_column(column) self.play_queue_list.append_column(column)

View File

@@ -248,67 +248,56 @@ class MobileFlap(Handy.Flap):
play_queue_scrollbox = Gtk.ScrolledWindow(vexpand=True) play_queue_scrollbox = Gtk.ScrolledWindow(vexpand=True)
self.play_queue_list = Gtk.TreeView( play_queue_list = Gtk.TreeView(
model=self.state.play_queue_store, model=self.state.play_queue_store,
reorderable=True, reorderable=True,
headers_visible=False, headers_visible=False,
) )
self.play_queue_list.get_style_context().add_class("background") play_queue_list.get_style_context().add_class("background")
# Album Art column. This function defines what image to use for the play queue
# song icon.
def filename_to_pixbuf(
column: Any,
cell: Gtk.CellRendererPixbuf,
model: Gtk.ListStore,
tree_iter: Gtk.TreeIter,
flags: Any,
):
cell.set_property("sensitive", model.get_value(tree_iter, 0))
filename = model.get_value(tree_iter, 1)
if not filename:
cell.set_property("icon_name", "")
return
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename, 50, 50, True)
# If this is the playing song, then overlay the play icon.
if model.get_value(tree_iter, 3):
play_overlay_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
str(resolve_path("ui/images/play-queue-play.png"))
)
play_overlay_pixbuf.composite(
pixbuf, 0, 0, 50, 50, 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 200
)
cell.set_property("pixbuf", pixbuf)
renderer = Gtk.CellRendererPixbuf() renderer = Gtk.CellRendererPixbuf()
renderer.set_fixed_size(55, 60) renderer.set_fixed_size(55, 60)
column = Gtk.TreeViewColumn("", renderer) column = Gtk.TreeViewColumn("", renderer)
column.set_cell_data_func(renderer, filename_to_pixbuf) column.set_cell_data_func(renderer, common.filename_to_pixbuf)
column.set_resizable(True) column.set_resizable(True)
self.play_queue_list.append_column(column) play_queue_list.append_column(column)
renderer = Gtk.CellRendererText(markup=True, ellipsize=Pango.EllipsizeMode.END) renderer = Gtk.CellRendererText(markup=True, ellipsize=Pango.EllipsizeMode.END)
column = Gtk.TreeViewColumn("", renderer, markup=2, sensitive=0) column = Gtk.TreeViewColumn("", renderer, markup=2, sensitive=0)
column.set_expand(True) column.set_expand(True)
self.play_queue_list.append_column(column) play_queue_list.append_column(column)
renderer = Gtk.CellRendererPixbuf(icon_name="view-more-symbolic") renderer = Gtk.CellRendererPixbuf(icon_name="view-more-symbolic")
renderer.set_fixed_size(30, 24) renderer.set_fixed_size(45, 60)
column = Gtk.TreeViewColumn("", renderer) view_more_column = Gtk.TreeViewColumn("", renderer)
column.set_resizable(True) view_more_column.set_resizable(True)
self.play_queue_list.append_column(column) play_queue_list.append_column(view_more_column)
renderer = Gtk.CellRendererPixbuf(icon_name="window-close-symbolic") renderer = Gtk.CellRendererPixbuf(icon_name="window-close-symbolic")
renderer.set_fixed_size(30, 24) renderer.set_fixed_size(45, 60)
column = Gtk.TreeViewColumn("", renderer) close_column = Gtk.TreeViewColumn("", renderer)
column.set_resizable(True) close_column.set_resizable(True)
self.play_queue_list.append_column(column) play_queue_list.append_column(close_column)
play_queue_scrollbox.add(self.play_queue_list) def on_play_queue_button_press(tree: Any, event: Gdk.EventButton) -> bool:
if event.button == 1:
clicked_path = tree.get_path_at_pos(event.x, event.y)[0]
song_idx = clicked_path.get_indices()[0]
tree_width = tree.get_allocation().width
if event.x > tree_width - close_column.get_width():
self.state.emit("songs-removed", [song_idx])
elif event.x > tree_width - close_column.get_width() - view_more_column.get_width():
common.show_play_queue_popover(self.state, play_queue_list, [clicked_path], event.x, event.y)
else:
self.state.emit("song-clicked", song_idx, [m[-1] for m in self.state.play_queue_store], {"no_reshuffle": True})
return True
return False
play_queue_list.connect("button-press-event", on_play_queue_button_press)
play_queue_scrollbox.add(play_queue_list)
self.set_flap(play_queue_scrollbox) self.set_flap(play_queue_scrollbox)
def on_play_queue_open(*_): def on_play_queue_open(*_):