From b326913ac940e7167a40b4cad0d4e4aea8eaccbe Mon Sep 17 00:00:00 2001 From: Heliguy Date: Wed, 9 Oct 2024 12:03:33 -0400 Subject: [PATCH] Implement installation chooser --- src/gtk/installation_chooser.blp | 34 ++++++++++++++ src/gtk/installation_chooser.py | 59 ++++++++++++++++++++++-- src/install_page/file_install_dialog.blp | 37 +-------------- src/install_page/file_install_dialog.py | 45 ++++-------------- 4 files changed, 101 insertions(+), 74 deletions(-) diff --git a/src/gtk/installation_chooser.blp b/src/gtk/installation_chooser.blp index 33cb088..16de977 100644 --- a/src/gtk/installation_chooser.blp +++ b/src/gtk/installation_chooser.blp @@ -3,4 +3,38 @@ using Adw 1; template $InstallationChooser : Adw.PreferencesGroup { title: _("Choose Installation"); + Adw.ActionRow user_row { + [prefix] + CheckButton user_check { + active: true; + } + title: _("User"); + activatable-widget: user_check; + } + Adw.ActionRow system_row { + [prefix] + CheckButton system_check { + group: user_check; + } + title: _("System"); + activatable-widget: system_check; + } + Adw.ActionRow single_row { + visible: false; + [prefix] + CheckButton single_check { + group: user_check; + } + subtitle: _("Custom installation"); + activatable-widget: single_check; + } + Adw.ComboRow choice_row { + visible: false; + [prefix] + CheckButton choice_check { + group: user_check; + } + title: _("Other Installation"); + subtitle: _("Choose a custom installation"); + } } \ No newline at end of file diff --git a/src/gtk/installation_chooser.py b/src/gtk/installation_chooser.py index 1363447..cf3eb1c 100644 --- a/src/gtk/installation_chooser.py +++ b/src/gtk/installation_chooser.py @@ -2,6 +2,59 @@ from gi.repository import Adw, Gtk from .host_info import HostInfo @Gtk.Template(resource_path="/io/github/flattool/Warehouse/gtk/installation_chooser.ui") -class InstallationChooser(Adw.ActionRow): - __gtype_name__ = 'InstallationChooser' - gtc = Gtk.Template.Child \ No newline at end of file +class InstallationChooser(Adw.PreferencesGroup): + __gtype_name__ = 'InstallationChooser' + gtc = Gtk.Template.Child + + user_row = gtc() + system_row = gtc() + single_row = gtc() + choice_row = gtc() + user_check = gtc() + system_check = gtc() + single_check = gtc() + choice_check = gtc() + + def get_installation(self): + for button, func in self.check_buttons.items(): + if button.get_active(): + HostInfo.main_window.toast_overlay.add_toast(Adw.Toast(title=func())) + return func() + + return "" # Case for when no button is active (which shouldn't happen) + + def set_content_strings(self, content_name, is_plural): + if is_plural: + self.user_row.set_subtitle(_("These {} will only be available to you").format(content_name)) + self.system_row.set_subtitle(_("These {} will be available to everyone").format(content_name)) + else: + self.user_row.set_subtitle(_("This {} will only be available to you").format(content_name)) + self.system_row.set_subtitle(_("This {} will be available to everyone").format(content_name)) + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.check_buttons = { + self.user_check : lambda: "user", + self.system_check: lambda: "system", + self.single_check: self.single_row.get_title, + self.choice_check: lambda: self.choice_row.get_selected_item().get_string(), + } + + # Apply + custom_installations = [] + for installation in HostInfo.installations + ['extra', 'something']: + if installation.startswith("user") or installation.startswith("system"): + continue + + custom_installations.append(installation) + + if len(custom_installations) == 1: + self.single_row.set_visible(True) + self.single_row.set_title(custom_installations[0]) + elif len(custom_installations) > 1: + self.choice_row.set_visible(True) + self.choice_row.set_model(Gtk.StringList(strings=custom_installations)) + + # Connections + self.choice_row.connect("notify::css-classes", lambda *_: self.choice_check.activate()) \ No newline at end of file diff --git a/src/install_page/file_install_dialog.blp b/src/install_page/file_install_dialog.blp index ffe2ca1..e936390 100644 --- a/src/install_page/file_install_dialog.blp +++ b/src/install_page/file_install_dialog.blp @@ -8,42 +8,7 @@ template $FileInstallDialog : Adw.AlertDialog { spacing: 12; Adw.PreferencesGroup packages_group { } - Adw.PreferencesGroup installation_group { - title: _("Choose Installation Type"); - Adw.ActionRow user_row { - [prefix] - CheckButton user_check { - active: true; - } - title: _("User"); - activatable-widget: user_check; - } - Adw.ActionRow system_row { - [prefix] - CheckButton system_check { - group: user_check; - } - title: _("System"); - activatable-widget: system_check; - } - Adw.ActionRow single_installation_row { - visible: false; - [prefix] - CheckButton single_check { - group: user_check; - } - subtitle: _("Custom installation"); - activatable-widget: single_check; - } - Adw.ComboRow installation_choice_row { - visible: false; - [prefix] - CheckButton choice_check { - group: user_check; - } - title: _("Other Installation"); - subtitle: _("Choose a custom installation"); - } + $InstallationChooser installation_chooser { } } responses [ diff --git a/src/install_page/file_install_dialog.py b/src/install_page/file_install_dialog.py index 3e6f46b..454ecb9 100644 --- a/src/install_page/file_install_dialog.py +++ b/src/install_page/file_install_dialog.py @@ -1,6 +1,7 @@ from gi.repository import Adw, Gtk, GLib, Gio from .host_info import HostInfo from .error_toast import ErrorToast +from .installation_chooser import InstallationChooser @Gtk.Template(resource_path="/io/github/flattool/Warehouse/install_page/file_install_dialog.ui") class FileInstallDialog(Adw.AlertDialog): @@ -8,14 +9,7 @@ class FileInstallDialog(Adw.AlertDialog): gtc = Gtk.Template.Child packages_group = gtc() - user_row = gtc() - system_row = gtc() - single_installation_row = gtc() - installation_choice_row = gtc() - user_check = gtc() - system_check = gtc() - single_check = gtc() - choice_check = gtc() + installation_chooser = gtc() def generate_list(self): for file in self.files: @@ -28,7 +22,7 @@ class FileInstallDialog(Adw.AlertDialog): return # self.installation_row.get_selected_item().get_string() - self.on_add("user", self.files) + self.on_add(self.installation_chooser.get_installation(), self.files) def __init__(self, parent_page, files, on_add, **kwargs): super().__init__(**kwargs) @@ -40,33 +34,14 @@ class FileInstallDialog(Adw.AlertDialog): # Apply self.generate_list() - # self.installation_row.set_model(Gtk.StringList(strings=HostInfo.installations)) - if len(files) > 1: - self.set_heading(_("Add These Packages?")) - self.set_body(_("Queue these packages to be installed")) - self.user_row.set_subtitle(_("These packages will only be available to you")) - self.system_row.set_subtitle(_("These packages will be available to everyone")) + self.set_heading(_("Review Packages")) + self.set_body(_("The following packages will be added to the queue")) + self.installation_chooser.set_content_strings(_("Packages"), True) else: - self.set_heading(_("Add This Package?")) - self.set_body(_("Queue this package to be installed")) - self.user_row.set_subtitle(_("This package will only be available to you")) - self.system_row.set_subtitle(_("This package will be available to everyone")) - - custom_installations = [] - for installation in HostInfo.installations: - if installation.startswith("user") or installation.startswith("system"): - continue - - custom_installations.append(installation) - - if len(custom_installations) == 1: - self.single_installation_row.set_visible(True) - self.single_installation_row.set_title(custom_installations[0]) - elif len(custom_installations) > 1: - self.installation_choice_row.set_visible(True) - self.installation_choice_row.set_model(Gtk.StringList(strings=custom_installations)) - + self.set_heading(_("Review Package")) + self.set_body(_("The following package will be added to the queue")) + self.installation_chooser.set_content_strings(_("package"), False) + # Connections self.connect("response", self.on_response) - self.installation_choice_row.connect("notify::css-classes", lambda *_: self.choice_check.activate())