Merge pull request #228 from kra-mo/libadwaita-1.5
Port to Libadwaita 1.5 widgets
This commit is contained in:
@@ -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()
|
||||
@@ -40,7 +40,7 @@ class Importer(ErrorProducer):
|
||||
|
||||
progressbar: Gtk.ProgressBar
|
||||
import_statuspage: Adw.StatusPage
|
||||
import_dialog: Adw.MessageDialog
|
||||
import_dialog: Adw.AlertDialog
|
||||
summary_toast: Optional[Adw.Toast] = None
|
||||
|
||||
sources: set[Source]
|
||||
@@ -53,7 +53,7 @@ class Importer(ErrorProducer):
|
||||
removed_game_ids: set[str]
|
||||
imported_game_ids: set[str]
|
||||
|
||||
close_req_id: int
|
||||
close_attempt_id: int
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
@@ -145,20 +145,17 @@ class Importer(ErrorProducer):
|
||||
title=_("Importing Games…"),
|
||||
child=self.progressbar,
|
||||
)
|
||||
self.import_dialog = Adw.Window(
|
||||
content=self.import_statuspage,
|
||||
modal=True,
|
||||
default_width=350,
|
||||
default_height=-1,
|
||||
transient_for=shared.win,
|
||||
deletable=False,
|
||||
self.import_dialog = Adw.Dialog(
|
||||
child=self.import_statuspage,
|
||||
content_width=350,
|
||||
can_close=False,
|
||||
)
|
||||
|
||||
self.close_req_id = self.import_dialog.connect(
|
||||
"close-request", lambda *_: shared.win.close()
|
||||
self.close_attempt_id = self.import_dialog.connect(
|
||||
"close-attempt", lambda *_: shared.win.close()
|
||||
)
|
||||
|
||||
self.import_dialog.present()
|
||||
self.import_dialog.present(shared.win)
|
||||
|
||||
def source_task_thread_func(self, data: tuple) -> None:
|
||||
"""Source import task code"""
|
||||
@@ -282,9 +279,9 @@ class Importer(ErrorProducer):
|
||||
self.imported_game_ids = shared.store.new_game_ids
|
||||
shared.store.new_game_ids = set()
|
||||
shared.store.duplicate_game_ids = set()
|
||||
# Disconnect the close-request signal that closes the main window
|
||||
self.import_dialog.disconnect(self.close_req_id)
|
||||
self.import_dialog.close()
|
||||
# Disconnect the close-attempt signal that closes the main window
|
||||
self.import_dialog.disconnect(self.close_attempt_id)
|
||||
self.import_dialog.force_close()
|
||||
self.__class__.summary_toast = self.create_summary_toast()
|
||||
self.create_error_dialog()
|
||||
shared.win.get_application().lookup_action("import").set_enabled(True)
|
||||
@@ -317,13 +314,12 @@ class Importer(ErrorProducer):
|
||||
return
|
||||
|
||||
# Create error dialog
|
||||
dialog = Adw.MessageDialog()
|
||||
dialog = Adw.AlertDialog()
|
||||
dialog.set_heading(_("Warning"))
|
||||
dialog.add_response("close", _("Dismiss"))
|
||||
dialog.add_response("open_preferences_import", _("Preferences"))
|
||||
dialog.set_default_response("open_preferences_import")
|
||||
dialog.connect("response", self.dialog_response_callback)
|
||||
dialog.set_transient_for(shared.win)
|
||||
|
||||
if len(errors) == 1:
|
||||
dialog.set_heading((error := next(iter(errors)))[0])
|
||||
@@ -342,7 +338,7 @@ class Importer(ErrorProducer):
|
||||
dialog.set_body(_("The following errors occured during import:"))
|
||||
dialog.set_extra_child(list_box)
|
||||
|
||||
dialog.present()
|
||||
dialog.present(shared.win)
|
||||
|
||||
def undo_import(self, *_args: Any) -> None:
|
||||
for game_id in self.imported_game_ids:
|
||||
@@ -407,7 +403,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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
@@ -153,7 +153,6 @@ class CartridgesApplication(Adw.Application):
|
||||
("go_to_parent", ("<alt>Up",), shared.win),
|
||||
("go_home", ("<alt>Home",), shared.win),
|
||||
("toggle_search", ("<primary>f",), shared.win),
|
||||
("escape", ("Escape",), shared.win),
|
||||
("undo", ("<primary>z",), shared.win),
|
||||
("open_menu", ("F10",), shared.win),
|
||||
("close", ("<primary>w",), shared.win),
|
||||
@@ -246,10 +245,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.page",
|
||||
@@ -275,7 +273,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 +282,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 +298,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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
@@ -121,7 +121,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"))
|
||||
|
||||
@@ -28,12 +28,12 @@ def create_dialog(
|
||||
body: str,
|
||||
extra_option: Optional[str] = None,
|
||||
extra_label: Optional[str] = None,
|
||||
) -> Adw.MessageDialog:
|
||||
dialog = Adw.MessageDialog.new(win, heading, body)
|
||||
) -> Adw.AlertDialog:
|
||||
dialog = Adw.AlertDialog.new(heading, body)
|
||||
dialog.add_response("dismiss", _("Dismiss"))
|
||||
|
||||
if extra_option:
|
||||
dialog.add_response(extra_option, _(extra_label))
|
||||
|
||||
dialog.present()
|
||||
dialog.choose(win)
|
||||
return dialog
|
||||
|
||||
@@ -469,15 +469,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
search_entry.set_text("")
|
||||
|
||||
def on_escape_action(self, *_args: Any) -> None:
|
||||
if (
|
||||
self.get_focus() == self.search_entry.get_focus_child()
|
||||
or self.hidden_search_entry.get_focus_child()
|
||||
):
|
||||
self.on_toggle_search_action()
|
||||
else:
|
||||
self.navigation_view.pop()
|
||||
|
||||
def show_details_page_search(self, widget: Gtk.Widget) -> None:
|
||||
library = (
|
||||
self.hidden_library if widget == self.hidden_search_entry else self.library
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/game.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/preferences.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/details-window.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/details-dialog.ui</file>
|
||||
<file alias="style.css">gtk/style.css</file>
|
||||
<file alias="style-dark.css">gtk/style-dark.css</file>
|
||||
<file>library_placeholder.svg</file>
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $DetailsWindow : Adw.Window {
|
||||
default-width: 480; // Same as Nautilus' properties window
|
||||
default-height: -1;
|
||||
modal: true;
|
||||
|
||||
ShortcutController {
|
||||
Shortcut {
|
||||
trigger: "Escape";
|
||||
action: "action(window.close)";
|
||||
}
|
||||
}
|
||||
template $DetailsDialog : Adw.Dialog {
|
||||
content-width: 480;
|
||||
|
||||
Adw.ToolbarView {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $PreferencesWindow : Adw.PreferencesWindow {
|
||||
template $CartridgesPreferences : Adw.PreferencesDialog {
|
||||
search-enabled: true;
|
||||
|
||||
Adw.PreferencesPage general_page {
|
||||
name: "general";
|
||||
|
||||
@@ -45,7 +45,7 @@ Adw.StatusPage hidden_notice_empty {
|
||||
|
||||
template $CartridgesWindow : Adw.ApplicationWindow {
|
||||
title: _("Cartridges");
|
||||
width-request: 281;
|
||||
width-request: 360;
|
||||
height-request: 100;
|
||||
|
||||
Adw.Breakpoint {
|
||||
@@ -75,6 +75,8 @@ template $CartridgesWindow : Adw.ApplicationWindow {
|
||||
title: _("All Games");
|
||||
|
||||
Adw.OverlaySplitView overlay_split_view {
|
||||
sidebar-width-fraction: .2;
|
||||
|
||||
[sidebar]
|
||||
Adw.NavigationPage {
|
||||
title: _("Cartridges");
|
||||
@@ -199,6 +201,13 @@ template $CartridgesWindow : Adw.ApplicationWindow {
|
||||
SearchEntry search_entry {
|
||||
placeholder-text: _("Search");
|
||||
hexpand: true;
|
||||
|
||||
ShortcutController {
|
||||
Shortcut {
|
||||
trigger: "Escape";
|
||||
action: "action(win.toggle_search)";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,6 +268,11 @@ Adw.NavigationPage hidden_library_page {
|
||||
SearchEntry hidden_search_entry {
|
||||
placeholder-text: _("Search");
|
||||
hexpand: true;
|
||||
|
||||
Shortcut {
|
||||
trigger: "Escape";
|
||||
action: "action(win.toggle_search)";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<control>touch</control>
|
||||
</supports>
|
||||
<recommends>
|
||||
<display_length compare="gt">280</display_length>
|
||||
<display_length compare="ge">360</display_length>
|
||||
</recommends>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
|
||||
@@ -4,7 +4,7 @@ blueprints = custom_target('blueprints',
|
||||
'gtk/window.blp',
|
||||
'gtk/game.blp',
|
||||
'gtk/preferences.blp',
|
||||
'gtk/details-window.blp'
|
||||
'gtk/details-dialog.blp'
|
||||
),
|
||||
output: '.',
|
||||
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id" : "hu.kramo.Cartridges.Devel",
|
||||
"runtime" : "org.gnome.Platform",
|
||||
"runtime-version" : "45",
|
||||
"runtime-version" : "46",
|
||||
"sdk" : "org.gnome.Sdk",
|
||||
"command" : "cartridges",
|
||||
"finish-args" : [
|
||||
|
||||
Reference in New Issue
Block a user