[gnome-music/wip/jfelder/remove-gtk-dialog-run-usage: 24/25] playlistdialog: Use response signal instead of the run method
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/remove-gtk-dialog-run-usage: 24/25] playlistdialog: Use response signal instead of the run method
- Date: Wed, 2 Feb 2022 11:34:10 +0000 (UTC)
commit 8338ca1b1088b11cadcabdf0e8758f0d2085c740
Author: Jean Felder <jfelder src gnome org>
Date: Mon Jan 10 17:07:24 2022 +0100
playlistdialog: Use response signal instead of the run method
gtk_dialog_run has been removed in gtk4.
gnomemusic/widgets/albumwidget.py | 33 ++++++++++++++++++++++-----------
gnomemusic/widgets/songwidgetmenu.py | 27 +++++++++++++++++++--------
gnomemusic/window.py | 31 ++++++++++++++++++++++---------
3 files changed, 63 insertions(+), 28 deletions(-)
---
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 8bb52f2d3..1475f4104 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -80,6 +80,8 @@ class AlbumWidget(Handy.Clamp):
self._year_signal_id = 0
self._model_signal_id = 0
+ self._playlist_dialog: Optional[PlaylistDialog] = None
+
self._art_stack.props.size = ArtSize.LARGE
self._art_stack.props.art_type = DefaultIcon.Type.ALBUM
self._player = self._application.props.player
@@ -292,21 +294,30 @@ class AlbumWidget(Handy.Clamp):
def _on_add_playlist_action(
self, action: Gio.SimpleAction,
data: Optional[GLib.Variant]) -> None:
+
+ def on_response(dialog: PlaylistDialog, response_id: int) -> None:
+ if not self._playlist_dialog:
+ return
+
+ if response_id == Gtk.ResponseType.ACCEPT:
+ playlist = self._playlist_dialog.props.selected_playlist
+ coresongs = [
+ song
+ for disc in self._corealbum.props.model
+ for song in disc.props.model]
+ playlist.add_songs(coresongs)
+
+ self._playlist_dialog.destroy()
+ self._playlist_dialog = None
+
if not self._corealbum:
return
- playlist_dialog = PlaylistDialog(self._application)
+ self._playlist_dialog = PlaylistDialog(self._application)
active_window = self._application.props.active_window
- playlist_dialog.props.transient_for = active_window
- if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
- playlist = playlist_dialog.props.selected_playlist
- coresongs = [
- song
- for disc in self._corealbum.props.model
- for song in disc.props.model]
- playlist.add_songs(coresongs)
-
- playlist_dialog.destroy()
+ self._playlist_dialog.props.transient_for = active_window
+ self._playlist_dialog.connect("response", on_response)
+ self._playlist_dialog.present()
def _on_play_action(
self, action: Gio.SimpleAction,
diff --git a/gnomemusic/widgets/songwidgetmenu.py b/gnomemusic/widgets/songwidgetmenu.py
index fea83d1c8..9c4e75b5e 100644
--- a/gnomemusic/widgets/songwidgetmenu.py
+++ b/gnomemusic/widgets/songwidgetmenu.py
@@ -23,7 +23,7 @@
# delete this exception statement from your version.
from __future__ import annotations
-from typing import Union
+from typing import Optional, Union
import typing
from gi.repository import Gtk
@@ -66,6 +66,8 @@ class SongWidgetMenu(Gtk.PopoverMenu):
self._song_widget = song_widget
self._coresong = song_widget.props.coresong
+ self._playlist_dialog: Optional[PlaylistDialog] = None
+
if isinstance(self._coreobject, Playlist):
self._remove_from_playlist_button.props.visible = True
self._remove_from_playlist_button.props.sensitive = (
@@ -88,14 +90,23 @@ class SongWidgetMenu(Gtk.PopoverMenu):
@Gtk.Template.Callback()
def _on_add_to_playlist_clicked(self, widget: Gtk.Button) -> None:
- self.popdown()
- playlist_dialog = PlaylistDialog(self._application)
- playlist_dialog.props.transient_for = self._window
- if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
- playlist = playlist_dialog.props.selected_playlist
- playlist.add_songs([self._coresong])
- playlist_dialog.destroy()
+ def on_response(dialog: PlaylistDialog, response_id: int) -> None:
+ if not self._playlist_dialog:
+ return
+
+ if response_id == Gtk.ResponseType.ACCEPT:
+ playlist = self._playlist_dialog.props.selected_playlist
+ playlist.add_songs([self._coresong])
+
+ self._playlist_dialog.destroy()
+ self._playlist_dialog = None
+
+ self.popdown()
+ self._playlist_dialog = PlaylistDialog(self._application)
+ self._playlist_dialog.props.transient_for = self._window
+ self._playlist_dialog.connect("response", on_response)
+ self._playlist_dialog.present()
@Gtk.Template.Callback()
def _on_remove_from_playlist_clicked(self, widget: Gtk.Button) -> None:
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index f36549837..bf4a0b282 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -22,6 +22,8 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
+from typing import Optional
+
from gi.repository import Gtk, Gdk, Gio, GLib, GObject, Handy
from gettext import gettext as _
@@ -89,6 +91,8 @@ class Window(Handy.ApplicationWindow):
self._current_view = None
self._view_before_search = None
+ self._playlist_dialog: Optional[PlaylistDialog] = None
+
self._player = app.props.player
self._search = app.props.search
@@ -441,7 +445,20 @@ class Window(Handy.ApplicationWindow):
and self._player.state == Playback.STOPPED):
self._player_toolbar.hide()
- def _on_add_to_playlist(self, widget):
+ def _on_add_to_playlist(self, widget: SelectionToolbar) -> None:
+
+ def on_response(dialog: PlaylistDialog, response_id: int) -> None:
+ if not self._playlist_dialog:
+ return
+
+ if response_id == Gtk.ResponseType.ACCEPT:
+ playlist = self._playlist_dialog.props.selected_playlist
+ playlist.add_songs(selected_songs)
+
+ self.props.selection_mode = False
+ self._playlist_dialog.destroy()
+ self._playlist_dialog = None
+
if self.props.active_view == self.views[View.PLAYLIST]:
return
@@ -450,14 +467,10 @@ class Window(Handy.ApplicationWindow):
if len(selected_songs) < 1:
return
- playlist_dialog = PlaylistDialog(self._app)
- playlist_dialog.props.transient_for = self
- if playlist_dialog.run() == Gtk.ResponseType.ACCEPT:
- playlist = playlist_dialog.props.selected_playlist
- playlist.add_songs(selected_songs)
-
- self.props.selection_mode = False
- playlist_dialog.destroy()
+ self._playlist_dialog = PlaylistDialog(self._app)
+ self._playlist_dialog.props.transient_for = self
+ self._playlist_dialog.connect("response", on_response)
+ self._playlist_dialog.present()
def set_player_visible(self, visible):
"""Set PlayWidget action visibility
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]