Port to libadwaita 1.5 widgets

This commit is contained in:
kramo
2024-01-27 08:52:50 +01:00
parent 124d2c8ec7
commit 3e1ef88a1f
12 changed files with 29 additions and 41 deletions

View File

@@ -36,9 +36,9 @@ from cartridges.utils.create_dialog import create_dialog
from cartridges.utils.save_cover import convert_cover, save_cover
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/details-window.ui")
class DetailsWindow(Adw.Window):
__gtype_name__ = "DetailsWindow"
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/details-dialog.ui")
class DetailsDialog(Adw.Dialog):
__gtype_name__ = "DetailsDialog"
cover_overlay = Gtk.Template.Child()
cover = Gtk.Template.Child()
@@ -61,12 +61,9 @@ class DetailsWindow(Adw.Window):
def __init__(self, game: Optional[Game] = None, **kwargs: Any):
super().__init__(**kwargs)
self.game: Game = game
self.game_cover: GameCover = GameCover({self.cover})
self.set_transient_for(shared.win)
if self.game:
self.set_title(_("Game Details"))
self.name.set_text(self.game.name)
@@ -152,7 +149,6 @@ class DetailsWindow(Adw.Window):
self.executable.connect("entry-activated", self.apply_preferences)
self.set_focus(self.name)
self.present()
def delete_pixbuf(self, *_args: Any) -> None:
self.game_cover.new_cover()

View File

@@ -407,7 +407,7 @@ class Importer(ErrorProducer):
self,
page_name: Optional[str] = None,
expander_row: Optional[Adw.ExpanderRow] = None,
) -> Adw.PreferencesWindow:
) -> Adw.PreferencesDialog:
return shared.win.get_application().on_preferences_action(
page_name=page_name, expander_row=expander_row
)

View File

@@ -34,7 +34,7 @@ gi.require_version("Adw", "1")
from gi.repository import Adw, Gio, GLib, Gtk
from cartridges import shared
from cartridges.details_window import DetailsWindow
from cartridges.details_dialog import DetailsDialog
from cartridges.game import Game
from cartridges.importer.bottles_source import BottlesSource
from cartridges.importer.desktop_source import DesktopSource
@@ -47,7 +47,7 @@ from cartridges.importer.lutris_source import LutrisSource
from cartridges.importer.retroarch_source import RetroarchSource
from cartridges.importer.steam_source import SteamSource
from cartridges.logging.setup import log_system_info, setup_logging
from cartridges.preferences import PreferencesWindow
from cartridges.preferences import CartridgesPreferences
from cartridges.store.managers.cover_manager import CoverManager
from cartridges.store.managers.display_manager import DisplayManager
from cartridges.store.managers.file_manager import FileManager
@@ -246,10 +246,9 @@ class CartridgesApplication(Adw.Application):
debug_str += log_file.read()
log_file.close()
about = Adw.AboutWindow.new_from_appdata(
about = Adw.AboutDialog.new_from_appdata(
shared.PREFIX + "/" + shared.APP_ID + ".metainfo.xml", shared.VERSION
)
about.set_transient_for(shared.win)
about.set_developers(
(
"kramo https://kramo.hu",
@@ -275,7 +274,7 @@ class CartridgesApplication(Adw.Application):
Gtk.License.CUSTOM,
"Steam and the Steam logo are trademarks and/or registered trademarks of Valve Corporation in the U.S. and/or other countries.", # pylint: disable=line-too-long
)
about.present()
about.present(shared.win)
def on_preferences_action(
self,
@@ -284,12 +283,12 @@ class CartridgesApplication(Adw.Application):
page_name: Optional[str] = None,
expander_row: Optional[str] = None,
) -> CartridgesWindow:
win = PreferencesWindow()
win = CartridgesPreferences()
if page_name:
win.set_visible_page_name(page_name)
if expander_row:
getattr(win, expander_row).set_expanded(True)
win.present()
win.present(shared.win)
return win
@@ -300,10 +299,10 @@ class CartridgesApplication(Adw.Application):
shared.win.active_game.toggle_hidden()
def on_edit_game_action(self, *_args: Any) -> None:
DetailsWindow(shared.win.active_game)
DetailsDialog(shared.win.active_game).present(shared.win)
def on_add_game_action(self, *_args: Any) -> None:
DetailsWindow()
DetailsDialog().present(shared.win)
def on_import_action(self, *_args: Any) -> None:
shared.importer = Importer()

View File

@@ -18,7 +18,7 @@ install_data(
'main.py',
'window.py',
'preferences.py',
'details_window.py',
'details_dialog.py',
'game.py',
'game_cover.py',
configure_file(
@@ -28,4 +28,4 @@ install_data(
)
],
install_dir: moduledir
)
)

View File

@@ -43,8 +43,8 @@ from cartridges.utils.create_dialog import create_dialog
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/preferences.ui")
class PreferencesWindow(Adw.PreferencesWindow):
__gtype_name__ = "PreferencesWindow"
class CartridgesPreferences(Adw.PreferencesDialog):
__gtype_name__ = "CartridgesPreferences"
general_page = Gtk.Template.Child()
import_page = Gtk.Template.Child()
@@ -123,7 +123,6 @@ class PreferencesWindow(Adw.PreferencesWindow):
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.file_chooser = Gtk.FileDialog()
self.set_transient_for(shared.win)
self.toast = Adw.Toast.new(_("All games removed"))
self.toast.set_button_label(_("Undo"))