fixup! Port UI to GTK 4
This commit is contained in:
parent
754556bb92
commit
3ee0ee73d5
6 changed files with 82 additions and 112 deletions
|
|
@ -29,13 +29,12 @@ class PlaylistPanel(Adw.Bin):
|
|||
'remove-multiple-albums': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
|
||||
'play': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
|
||||
'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)),
|
||||
|
||||
'select': (GObject.SIGNAL_RUN_FIRST, None, (bool,)),
|
||||
'clear-playlist': (GObject.SIGNAL_RUN_FIRST, None, ())
|
||||
}
|
||||
|
||||
|
||||
# Widgets
|
||||
playlist_stack = Gtk.Template.Child()
|
||||
panel_normal = Gtk.Template.Child()
|
||||
panel_standalone = Gtk.Template.Child()
|
||||
actionbar_revealer = Gtk.Template.Child()
|
||||
# Toolbar
|
||||
|
|
@ -69,17 +68,15 @@ class PlaylistPanel(Adw.Bin):
|
|||
self._is_selected = False
|
||||
|
||||
# Widgets
|
||||
# FIXME Toolbar signals
|
||||
#self._toolbar.connect('select', self.on_toolbar_select)
|
||||
#self._toolbar.connect('clear-playlist', self.on_toolbar_clear)
|
||||
# Header bar
|
||||
self._headerbar_standalone = AlbumHeaderbar()
|
||||
self._headerbar_standalone.connect('close', self.on_headerbar_close_clicked)
|
||||
# Playlist Grid: Model
|
||||
self._playlist_grid_model = Gio.ListStore()
|
||||
self._playlist_grid_selection = Gtk.MultiSelection.new(self._playlist_grid_model)
|
||||
self._playlist_grid_selection_multi = Gtk.MultiSelection.new(self._playlist_grid_model)
|
||||
self._playlist_grid_selection_single = Gtk.SingleSelection.new(self._playlist_grid_model)
|
||||
# Playlist Grid
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection)
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection_single)
|
||||
|
||||
|
||||
def get_headerbar_standalone(self):
|
||||
|
|
@ -94,32 +91,23 @@ class PlaylistPanel(Adw.Bin):
|
|||
self._is_selected = selected
|
||||
|
||||
|
||||
def on_toolbar_select(self, widget, active):
|
||||
if active:
|
||||
@Gtk.Template.Callback()
|
||||
def on_select_toggled(self, widget):
|
||||
if self.select_button.get_active():
|
||||
self.actionbar_revealer.set_reveal_child(True)
|
||||
self.playlist_grid.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection_multi)
|
||||
self.playlist_grid.set_single_click_activate(False)
|
||||
self.playlist_grid.get_style_context().add_class(Utils.CSS_SELECTION)
|
||||
else:
|
||||
self.actionbar_revealer.set_reveal_child(False)
|
||||
self.playlist_grid.set_selection_mode(Gtk.SelectionMode.SINGLE)
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection_single)
|
||||
self.playlist_grid.set_single_click_activate(True)
|
||||
self.playlist_grid.get_style_context().remove_class(Utils.CSS_SELECTION)
|
||||
|
||||
|
||||
def on_toolbar_clear(self, widget):
|
||||
self.emit('clear-playlist')
|
||||
|
||||
|
||||
# FIXME on_select_toggled()
|
||||
#@Gtk.Template.Callback()
|
||||
def on_select_toggled(self, widget):
|
||||
self.emit('select', widget.get_active())
|
||||
|
||||
|
||||
# FIXME on_clear_clicked()
|
||||
#@Gtk.Template.Callback()
|
||||
@Gtk.Template.Callback()
|
||||
def on_clear_clicked(self, widget):
|
||||
if widget is self.playlist_clear_button:
|
||||
self.emit('clear-playlist')
|
||||
self.emit('clear-playlist')
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
|
|
@ -131,9 +119,8 @@ class PlaylistPanel(Adw.Bin):
|
|||
self._selected_albums = [album]
|
||||
self.emit('albumart', id)
|
||||
|
||||
# FIXME Show standalone album
|
||||
return
|
||||
if widget.get_selection_mode() == Gtk.SelectionMode.SINGLE:
|
||||
# Show standalone album
|
||||
if widget.get_model() == self._playlist_grid_selection_single:
|
||||
# Set labels
|
||||
self._headerbar_standalone.set_album(album)
|
||||
|
||||
|
|
@ -145,46 +132,30 @@ class PlaylistPanel(Adw.Bin):
|
|||
self.standalone_spinner.start()
|
||||
|
||||
|
||||
# FIXME on_playlist_grid_selection_changed()
|
||||
#@Gtk.Template.Callback()
|
||||
def on_playlist_grid_selection_changed(self, widget):
|
||||
self._selected_albums = []
|
||||
for path in widget.get_selected_items():
|
||||
iter = self._playlist_grid_model.get_iter(path)
|
||||
hash = self._playlist_grid_model.get_value(iter, 2)
|
||||
self._selected_albums.append(self._playlist_albums[hash])
|
||||
|
||||
|
||||
#@Gtk.Template.Callback()
|
||||
@Gtk.Template.Callback()
|
||||
def on_selection_cancel_clicked(self, widget):
|
||||
self.select_button.set_active(False)
|
||||
|
||||
|
||||
#@Gtk.Template.Callback()
|
||||
@Gtk.Template.Callback()
|
||||
def on_selection_remove_clicked(self, widget):
|
||||
self.emit('remove-multiple-albums', self._selected_albums)
|
||||
self.emit('remove-multiple-albums', self._get_selected_albums())
|
||||
self.select_button.set_active(False)
|
||||
|
||||
|
||||
# FIXME on_standalone_scroll_size_allocate()
|
||||
#@Gtk.Template.Callback()
|
||||
def on_standalone_scroll_size_allocate(self, widget, allocation):
|
||||
self._resize_standalone_image()
|
||||
|
||||
|
||||
def on_headerbar_close_clicked(self, widget):
|
||||
self._close_standalone()
|
||||
|
||||
|
||||
#@Gtk.Template.Callback()
|
||||
@Gtk.Template.Callback()
|
||||
def on_standalone_remove_clicked(self, widget):
|
||||
self.emit('remove-album', self._selected_albums[0])
|
||||
self.emit('remove-album', self._get_selected_albums()[0])
|
||||
self._close_standalone()
|
||||
|
||||
|
||||
#@Gtk.Template.Callback()
|
||||
@Gtk.Template.Callback()
|
||||
def on_standalone_play_clicked(self, widget):
|
||||
self.emit('play', self._selected_albums[0])
|
||||
self.emit('play', self._get_selected_albums()[0])
|
||||
self._close_standalone()
|
||||
|
||||
|
||||
|
|
@ -240,8 +211,6 @@ class PlaylistPanel(Adw.Bin):
|
|||
for album in playlist:
|
||||
self._playlist_albums[album.get_id()] = album
|
||||
self._playlist_grid_model.remove_all()
|
||||
# FIXME Set item padding dynamically?
|
||||
#GObject.idle_add(self.playlist_grid.set_item_padding, size / 100)
|
||||
|
||||
cache = client.MCGCache(host, size)
|
||||
for album in playlist:
|
||||
|
|
@ -270,7 +239,7 @@ class PlaylistPanel(Adw.Bin):
|
|||
self._playlist_lock.release()
|
||||
return
|
||||
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection)
|
||||
self.playlist_grid.set_model(self._playlist_grid_selection_single)
|
||||
self._playlist_lock.release()
|
||||
|
||||
|
||||
|
|
@ -286,12 +255,12 @@ class PlaylistPanel(Adw.Bin):
|
|||
|
||||
|
||||
def _open_standalone(self):
|
||||
self.set_visible_child(self.panel_standalone)
|
||||
self.playlist_stack.set_visible_child(self.panel_standalone)
|
||||
self.emit('open-standalone')
|
||||
|
||||
|
||||
def _close_standalone(self):
|
||||
self.set_visible_child(self.get_children()[0])
|
||||
self.playlist_stack.set_visible_child(self.panel_normal)
|
||||
self.emit('close-standalone')
|
||||
|
||||
|
||||
|
|
@ -317,7 +286,6 @@ class PlaylistPanel(Adw.Bin):
|
|||
if width <= 0 or height <= 0:
|
||||
return
|
||||
# Pixelpuffer auf Oberfläche zeichnen
|
||||
self.standalone_image.set_allocation(self.standalone_scroll.get_allocation())
|
||||
self.standalone_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
||||
self.standalone_image.show()
|
||||
|
||||
|
|
@ -331,3 +299,11 @@ class PlaylistPanel(Adw.Bin):
|
|||
Gtk.TextDirection.LTR,
|
||||
Gtk.IconLookupFlags.FORCE_SYMBOLIC
|
||||
)
|
||||
|
||||
|
||||
def _get_selected_albums(self):
|
||||
albums = []
|
||||
for i in range(self.playlist_grid.get_model().get_n_items()):
|
||||
if self.playlist_grid.get_model().is_selected(i):
|
||||
albums.append(self.playlist_grid.get_model().get_item(i).get_album())
|
||||
return albums
|
||||
|
|
|
|||
Loading…
Reference in a new issue