From 7f86aa153053a18097c867ff27c0f2bf2fd0fe01 Mon Sep 17 00:00:00 2001 From: Heliguy Date: Tue, 7 Nov 2023 17:00:59 -0500 Subject: [PATCH] Uninstall in main list progress bar reports status --- src/common.py | 16 ++++++------- src/orphans.blp | 2 +- src/window.blp | 64 ++++++++++++++++++++++++++++++++++++++++++------- src/window.py | 26 +++++++++++--------- 4 files changed, 79 insertions(+), 29 deletions(-) diff --git a/src/common.py b/src/common.py index ddc18fd..f6e0db2 100644 --- a/src/common.py +++ b/src/common.py @@ -205,8 +205,8 @@ class myUtils: try: subprocess.run(command, capture_output=False, check=True, env=self.new_env) if progress_bar: - progress_bar.set_visible(True) - progress_bar.set_fraction((i + 1.0) / len(app_arr)) + GLib.idle_add(progress_bar.set_visible, True) + GLib.idle_add(progress_bar.set_fraction, (i + 1.0) / len(ref_arr)) except subprocess.CalledProcessError: fails.append(apps[i]) @@ -223,8 +223,8 @@ class myUtils: try: print(pk_command) if progress_bar: - progress_bar.set_visible(True) - progress_bar.set_fraction(0.9) + GLib.idle_add(progress_bar.set_visible, True) + GLib.idle_add(progress_bar.set_fraction, 0.9) subprocess.run(pk_command, capture_output=False, check=True, env=self.new_env) except subprocess.CalledProcessError: self.uninstall_success = False @@ -255,8 +255,8 @@ class myUtils: try: subprocess.run(command, capture_output=False, check=True, env=self.new_env) if progress_bar: - progress_bar.set_visible(True) - progress_bar.set_fraction((i + 1.0) / len(app_arr)) + GLib.idle_add(progress_bar.set_visible, True) + GLib.idle_add(progress_bar.set_fraction, (i + 1.0) / len(app_arr)) except subprocess.CalledProcessError: fails.append(app_arr[i]) @@ -266,8 +266,8 @@ class myUtils: pk_command.append(fails[i]) try: if progress_bar: - progress_bar.set_visible(True) - progress_bar.set_fraction(0.9) + GLib.idle_add(progress_bar.set_visible, True) + GLib.idle_add(progress_bar.set_fraction, 0.9) subprocess.run(pk_command, capture_output=False, check=True, env=self.new_env) except subprocess.CalledProcessError: self.install_success = False diff --git a/src/orphans.blp b/src/orphans.blp index 0d5bea1..7bb7dab 100644 --- a/src/orphans.blp +++ b/src/orphans.blp @@ -66,7 +66,7 @@ template OrphansWindow : Adw.Window { spinning: true; } Label { - label: _("Installing Apps…"); + label: _("Installing…"); styles["title-1", "title"] } Label { diff --git a/src/window.blp b/src/window.blp index 98b51c5..c358326 100644 --- a/src/window.blp +++ b/src/window.blp @@ -49,10 +49,10 @@ template WarehouseWindow : Adw.ApplicationWindow { } content: Adw.ToastOverlay toast_overlay { - Stack main_stack { - Box main_box { - orientation: vertical; - Overlay main_overlay { + Overlay main_overlay { + Stack main_stack { + Box main_box { + orientation: vertical; ScrolledWindow scrolled_window { vexpand: true; Adw.Clamp{ @@ -69,11 +69,57 @@ template WarehouseWindow : Adw.ApplicationWindow { } } } - } - Adw.StatusPage no_flatpaks { - icon-name: "error-symbolic"; - title: _("No Flatpaks Found"); - description: _("There are either no Flatpaks that match the current filter, Warehouse cannot see the list of installed Flatpaks, or the system has no Flatpaks installed."); + Box installing { + orientation: vertical; + spacing: 10; + margin-top: 40; + margin-bottom: 20; + halign: center; + valign: center; + Spinner { + margin-bottom: 35; + width-request: 30; + height-request: 30; + opacity: 0.5; + spinning: true; + } + Label { + label: _("Installing…"); + styles["title-1", "title"] + } + Label { + label: _("This could take a while."); + styles["description", "body"] + } + } + Box uninstalling { + orientation: vertical; + spacing: 10; + margin-top: 40; + margin-bottom: 20; + halign: center; + valign: center; + Spinner { + margin-bottom: 35; + width-request: 30; + height-request: 30; + opacity: 0.5; + spinning: true; + } + Label { + label: _("Uninstalling…"); + styles["title-1", "title"] + } + Label { + label: _("This could take a while."); + styles["description", "body"] + } + } + Adw.StatusPage no_flatpaks { + icon-name: "error-symbolic"; + title: _("No Flatpaks Found"); + description: _("There are either no Flatpaks that match the current filter, Warehouse cannot see the list of installed Flatpaks, or the system has no Flatpaks installed."); + } } } }; diff --git a/src/window.py b/src/window.py index 6a0f382..c265d36 100644 --- a/src/window.py +++ b/src/window.py @@ -53,6 +53,7 @@ class WarehouseWindow(Adw.ApplicationWindow): filter_button = Gtk.Template.Child() scrolled_window = Gtk.Template.Child() main_menu = Gtk.Template.Child() + uninstalling = Gtk.Template.Child() main_progress_bar = Gtk.ProgressBar(visible=False, pulse_step=0.7, can_target=False) main_progress_bar.add_css_class("osd") @@ -95,18 +96,19 @@ class WarehouseWindow(Adw.ApplicationWindow): def uninstallFlatpakCallback(self, _a, _b): self.currently_uninstalling = False self.main_progress_bar.set_visible(False) - self.should_pulse = False + # self.should_pulse = False self.refresh_list_of_flatpaks(_a, False) self.main_toolbar_view.set_sensitive(True) self.disconnect(self.no_close) self.uninstallButtonsEnable(True) + self.main_stack.set_visible_child(self.main_box) if self.my_utils.uninstall_success: self.toast_overlay.add_toast(Adw.Toast.new(_("Uninstalled successfully"))) else: self.toast_overlay.add_toast(Adw.Toast.new(_("Could not uninstall some apps"))) def uninstallFlatpakThread(self, ref_arr, id_arr, type_arr, should_trash): - self.my_utils.uninstallFlatpak(ref_arr, type_arr, should_trash) + self.my_utils.uninstallFlatpak(ref_arr, type_arr, should_trash, self.main_progress_bar) def uninstallFlatpak(self, should_trash): ref_arr = [] @@ -127,13 +129,13 @@ class WarehouseWindow(Adw.ApplicationWindow): task.run_in_thread(lambda _task, _obj, _data, _cancellable, ref_arr=ref_arr, id_arr=id_arr, type_arr=type_arr, should_trash=should_trash: self.uninstallFlatpakThread(ref_arr, id_arr, type_arr, should_trash)) def batchUninstallButtonHandler(self, _widget): - self.should_pulse = True - self.mainPulser() + # self.should_pulse = True + # self.mainPulser() has_user_data = [] # This is only an array so I can edit it in a sub-function without using nonlocal prefix def batchUninstallResponse(_idk, response_id, _widget): if response_id == "cancel": - self.should_pulse = False + # self.should_pulse = False return 1 try: @@ -146,7 +148,8 @@ class WarehouseWindow(Adw.ApplicationWindow): self.uninstallButtonsEnable(False) self.no_close = self.connect("close-request", lambda event: True) # Make window unable to close - self.main_progress_bar.set_visible(True) + # self.main_progress_bar.set_visible(True) + self.main_stack.set_visible_child(self.uninstalling) self.uninstallFlatpak(should_trash) # Create Widgets @@ -211,14 +214,14 @@ class WarehouseWindow(Adw.ApplicationWindow): self.flatpak_rows[index][1] = True def uninstallResponse(_idk, response_id, _widget): + if response_id == "cancel": + # self.should_pulse = False + return 1 + try: should_trash = trash_check.get_active() except: should_trash = False - - if response_id == "cancel": - self.should_pulse = False - return 1 if response_id == "purge": should_trash = True @@ -227,7 +230,8 @@ class WarehouseWindow(Adw.ApplicationWindow): #self.main_toolbar_view.set_sensitive(False) self.no_close = self.connect("close-request", lambda event: True) # Make window unable to close - self.main_progress_bar.set_visible(True) + # self.main_progress_bar.set_visible(True) + self.main_stack.set_visible_child(self.uninstalling) self.uninstallFlatpak(should_trash) # Create Widgets