From 5cade3677f24804a2f13f4d034e4ebb39cc2027b Mon Sep 17 00:00:00 2001 From: heliguy4599 Date: Sat, 12 Oct 2024 15:17:33 -0400 Subject: [PATCH] Add package installation drag and drop --- src/main_window/window.py | 3 ++- src/remotes_page/remotes_page.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main_window/window.py b/src/main_window/window.py index f007245..f11eabc 100644 --- a/src/main_window/window.py +++ b/src/main_window/window.py @@ -172,6 +172,7 @@ class WarehouseWindow(Adw.ApplicationWindow): # Adding a remote self.activate_row(self.remotes_row) remotes_page = self.pages[self.remotes_row] + remotes_page.local_file_handler(remotes[0]) elif len(paks) > 0: # Add packages self.activate_row(self.install_row) @@ -179,7 +180,7 @@ class WarehouseWindow(Adw.ApplicationWindow): install_page.select_page.file_dialog_handler(paks) except Exception as e: - self.toast_overlay.add_toast(ErrorToast(_("Could not open files"), str(e))) + self.toast_overlay.add_toast(ErrorToast(_("Could not open files"), str(e)).toast) def on_drop_enter(self, *args): self.file_drop_stack.set_visible_child(self.file_drop_view) diff --git a/src/remotes_page/remotes_page.py b/src/remotes_page/remotes_page.py index 48ca2fc..c5d872d 100644 --- a/src/remotes_page/remotes_page.py +++ b/src/remotes_page/remotes_page.py @@ -209,11 +209,9 @@ class RemotesPage(Adw.NavigationPage): return self.stack.set_visible_child(self.content_page if total > 0 else self.no_results) - - def file_callback(self, chooser, result): + + def local_file_handler(self, path): try: - file = chooser.open_finish(result) - path = file.get_path() name = path.split("/")[-1].split(".")[0] info = { "title": name.title(), @@ -222,6 +220,14 @@ class RemotesPage(Adw.NavigationPage): "link": path, } AddRemoteDialog(self.main_window, self, info).present(self.main_window) + except Exception as e: + self.toast_overlay.add_toast(ErrorToast(_("Could not open file"), str(e)).toast) + + def file_callback(self, chooser, result): + try: + file = chooser.open_finish(result) + path = file.get_path() + self.local_file_handler(path) except GLib.GError as ge: if "Dismissed by user" in str(ge): return