From c73c9a684f9604b7e91ea87a65887e7e1017c6c4 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 15 Aug 2024 12:16:17 +0200 Subject: [PATCH] Migrate SimpleDialog to Adw.Dialog --- melon/playlist/__init__.py | 4 ++-- melon/playlist/pick.py | 2 +- melon/widgets/preferencerow.py | 5 ++--- melon/widgets/simpledialog.py | 19 ++++++------------- melon/window.py | 5 ++--- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/melon/playlist/__init__.py b/melon/playlist/__init__.py index c64b8c1..f28b1f7 100644 --- a/melon/playlist/__init__.py +++ b/melon/playlist/__init__.py @@ -272,7 +272,7 @@ class LocalPlaylistScreen(Adw.NavigationPage): self.edit_diag.toolbar_view.add_bottom_bar(bottom_bar) self.edit_diag.set_widget(page) - self.edit_diag.show() + self.edit_diag.show(self) def save_details(self): self.playlist.title = self.input_title.get_text() @@ -323,7 +323,7 @@ class LocalPlaylistScreen(Adw.NavigationPage): bottom_bar.append(btn_confirm) self.dlt_diag.toolbar_view.add_bottom_bar(bottom_bar) - self.dlt_diag.show() + self.dlt_diag.show(self) def delete(self): # make sure that this widget does not receive an update notification diff --git a/melon/playlist/pick.py b/melon/playlist/pick.py index d3908d0..8394216 100644 --- a/melon/playlist/pick.py +++ b/melon/playlist/pick.py @@ -25,7 +25,7 @@ class PlaylistPickerDialog(SimpleDialog): def open_creator(self, video): diag = PlaylistCreatorDialog(video) self.hide() - diag.show() + diag.show(self) def display(self, video): page = Adw.PreferencesPage() diff --git a/melon/widgets/preferencerow.py b/melon/widgets/preferencerow.py index d6e3f2b..e7c051a 100644 --- a/melon/widgets/preferencerow.py +++ b/melon/widgets/preferencerow.py @@ -207,7 +207,7 @@ class MultiRow(Adw.PreferencesRow): bottom_bar.append(btn_confirm) diag.toolbar_view.add_bottom_bar(bottom_bar) - diag.show() + diag.show(self) def confirm_delete(self, w, item: str, counter: int): diag = SimpleDialog() @@ -249,8 +249,7 @@ class MultiRow(Adw.PreferencesRow): bottom_bar.append(btn_cancel) bottom_bar.append(btn_confirm) diag.toolbar_view.add_bottom_bar(bottom_bar) - diag.show() - pass + diag.show(self) def move_up(self, _, item: str, counter: int): val = self.values.pop(counter) diff --git a/melon/widgets/simpledialog.py b/melon/widgets/simpledialog.py index e7e1eeb..65ce89f 100644 --- a/melon/widgets/simpledialog.py +++ b/melon/widgets/simpledialog.py @@ -5,29 +5,22 @@ gi.require_version("Adw", "1") from gi.repository import Gtk, Adw, Gio, GLib -class SimpleDialog(Adw.Window): +class SimpleDialog(Adw.Dialog): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.toolbar_view = Adw.ToolbarView() self.header_bar = Adw.HeaderBar() - self.title = Adw.WindowTitle() - self.header_bar.set_title_widget(self.title) self.toolbar_view.add_top_bar(self.header_bar) - self.set_content(self.toolbar_view) - # this is a dialog and thus the main window should not be usable - # when the dialog is opened - self.set_modal(True) - - def set_title(self, text): - self.title.set_title(text) + self.set_child(self.toolbar_view) + self.set_follows_content_size(True) def set_widget(self, child, padding=12): self.toolbar_view.set_content(child) child.set_margin_end(padding) child.set_margin_start(padding) - def show(self): - self.set_visible(True) + def show(self, parent=None): + self.present(parent) def hide(self): - self.set_visible(False) + self.close() diff --git a/melon/window.py b/melon/window.py index 64f0909..3f654b8 100644 --- a/melon/window.py +++ b/melon/window.py @@ -17,7 +17,6 @@ from melon.settings import SettingsScreen from melon.importer import ImporterScreen from melon.player import PlayerScreen from melon.player.playlist import PlaylistPlayerScreen -from melon.widgets.simpledialog import SimpleDialog from melon.playlist import LocalPlaylistScreen from melon.playlist.pick import PlaylistPickerDialog from melon.playlist.create import PlaylistCreatorDialog @@ -58,7 +57,7 @@ class MainWindow(Adw.ApplicationWindow): servers = get_servers_list() video = (server_id, video_id) diag = PlaylistPickerDialog(video) - diag.show() + diag.show(self) def open_playlist_creator(self, action, prefs): act = action.get_name() @@ -71,7 +70,7 @@ class MainWindow(Adw.ApplicationWindow): video = (server_id, video_id) # create basic dialog diag = PlaylistCreatorDialog(video) - diag.show() + diag.show(self) def open_local_playlist_viewer(self, action, prefs): self.view.push(LocalPlaylistScreen(prefs.unpack())) -- 2.38.5