From f4ab22b49e8d44886ad12c33980a5f5766ef072d Mon Sep 17 00:00:00 2001 From: heliguy4599 Date: Thu, 21 Sep 2023 16:30:58 -0400 Subject: [PATCH] Sync current work --- src/{functions.py => common.py} | 13 ++++++------- src/meson.build | 2 +- src/window.py | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) rename src/{functions.py => common.py} (90%) diff --git a/src/functions.py b/src/common.py similarity index 90% rename from src/functions.py rename to src/common.py index 41206870..b9e56161 100644 --- a/src/functions.py +++ b/src/common.py @@ -3,14 +3,13 @@ import subprocess import pathlib -class functions(): +class myUtils: def __init__(self, window, **kwargs): - super().__init__(**kwargs) self.main_window = window self.host_home = str(pathlib.Path.home()) self.user_data_path = self.host_home + "/.var/app/" - def trash_folder(self, path): + def trashFolder(self, path): if not os.path.exists(path): return 1 try: @@ -19,7 +18,7 @@ def trash_folder(self, path): except subprocess.CalledProcessError: return 2 - def get_size_format(self, b): + def getSizeFormat(self, b): factor = 1024 suffix = "B" for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: @@ -28,7 +27,7 @@ def get_size_format(self, b): b /= factor return f"{b:.1f}{suffix}" - def get_directory_size(self, directory): + def getDirectorySize(self, directory): """Returns the `directory` size in bytes.""" total = 0 try: @@ -42,7 +41,7 @@ def get_directory_size(self, directory): elif entry.is_dir(): # if it's a directory, recursively call this function try: - total += self.get_directory_size(entry.path) + total += self.getDirectorySize(entry.path) except FileNotFoundError: pass except NotADirectoryError: @@ -53,7 +52,7 @@ def get_directory_size(self, directory): return 0 return total - def find_app_icon(self, app_id): + def findAppIcon(self, app_id): icon_theme = Gtk.IconTheme.new() icon_theme.add_search_path("/var/lib/flatpak/exports/share/icons/") icon_theme.add_search_path(self.host_home + "/.local/share/flatpak/exports/share/icons") diff --git a/src/meson.build b/src/meson.build index 57688dc3..9bb564dc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -43,7 +43,7 @@ warehouse_sources = [ 'properties_window.py', 'orphans_window.py', 'remotes.py', - 'functions.py', + 'common.py', ] install_data(warehouse_sources, install_dir: moduledir) diff --git a/src/window.py b/src/window.py index 3e0d6403..56affe58 100644 --- a/src/window.py +++ b/src/window.py @@ -23,7 +23,7 @@ from gi.repository import Adw, Gdk, Gio, GLib, Gtk from .properties_window import show_properties_window from .orphans_window import show_orphans_window -from .functions import functions +from .common import myUtils @Gtk.Template(resource_path="/io/github/heliguy4599/Warehouse/window.ui") class WarehouseWindow(Adw.ApplicationWindow): @@ -258,7 +258,7 @@ def generate_list(widget, is_select_all): if not file_list[i] in id_list: row_index += 1 select_orphans_tickbox = Gtk.CheckButton(halign=Gtk.Align.CENTER) - orphans_row = Adw.ActionRow(title=GLib.markup_escape_text(file_list[i]), subtitle=_("~") + self.func.get_size_format(self.func.get_directory_size(f"{self.user_data_path}{file_list[i]}"))) + orphans_row = Adw.ActionRow(title=GLib.markup_escape_text(file_list[i]), subtitle=_("~") + self.my_utils.getSizeFormat(self.my_utils.getDirectorySize(f"{self.user_data_path}{file_list[i]}"))) orphans_row.add_suffix(select_orphans_tickbox) orphans_row.set_activatable_widget(select_orphans_tickbox) select_orphans_tickbox.connect("toggled", selection_handler, orphans_row.get_title()) @@ -458,7 +458,7 @@ def get_host_flatpaks(): app_id = self.host_flatpaks[index][2] app_ref = self.host_flatpaks[index][8] flatpak_row = Adw.ActionRow(title=GLib.markup_escape_text(app_name)) - flatpak_row.add_prefix(self.func.find_app_icon(app_id)) + flatpak_row.add_prefix(self.my_utils.findAppIcon(app_id)) if (not self.show_runtimes) and "runtime" in self.host_flatpaks[index][12]: continue @@ -543,7 +543,7 @@ def on_batch_clean_response(self, dialog, response, _a): app_id = self.host_flatpaks[self.selected_host_flatpak_indexes[i]][2] app_name = self.host_flatpaks[self.selected_host_flatpak_indexes[i]][0] path = f"{self.user_data_path}{app_id}" - trash = self.func.trash_folder(None, path) + trash = self.my_utils.trash_folder(None, path) if trash == 1: show_success = False self.toast_overlay.add_toast(Adw.Toast.new(_("No user data for {}").format(app_name))) @@ -588,7 +588,7 @@ def flatpak_row_select_handler(self, tickbox, index): def __init__(self, **kwargs): super().__init__(**kwargs) - self.func = functions(self) + self.my_utils = myUtils(self) self.list_of_flatpaks.set_filter_func(self.filter_func) self.set_size_request(0, 230) self.generate_list_of_flatpaks()