From 58156dd4c10d09ef65866a2dd7b7a96381f9f14d Mon Sep 17 00:00:00 2001 From: DYefremov Date: Mon, 9 May 2022 23:57:50 +0300 Subject: [PATCH] backup dialog improvement --- app/commons.py | 19 +++ app/ui/backup.py | 12 +- app/ui/backup_dialog.glade | 233 ++++++++++++++++++++++++++----------- app/ui/ftp.py | 27 +---- app/ui/main.py | 15 ++- 5 files changed, 207 insertions(+), 99 deletions(-) diff --git a/app/commons.py b/app/commons.py index 3860e907..6faa4497 100644 --- a/app/commons.py +++ b/app/commons.py @@ -77,6 +77,25 @@ def run_with_delay(timeout=5): return run_with +def get_size_from_bytes(size): + """ Simple convert function from bytes to other units like K, M or G. """ + try: + b = float(size) + except ValueError: + return size + else: + kb, mb, gb = 1024.0, 1048576.0, 1073741824.0 + + if b < kb: + return str(b) + elif kb <= b < mb: + return f"{b / kb:.1f} K" + elif mb <= b < gb: + return f"{b / mb:.1f} M" + elif gb <= b: + return f"{b / gb:.1f} G" + + class DefaultDict(defaultdict): """ Extended to support functions with params as default factory. """ diff --git a/app/ui/backup.py b/app/ui/backup.py index 2dafa94d..e899fe0f 100644 --- a/app/ui/backup.py +++ b/app/ui/backup.py @@ -33,8 +33,9 @@ import time import zipfile from datetime import datetime from enum import Enum +from pathlib import Path -from app.commons import run_idle +from app.commons import run_idle, get_size_from_bytes from app.settings import SettingsType, SEP from app.ui.dialogs import show_dialog, DialogType, get_builder from app.ui.main_helper import append_text_to_tview @@ -74,6 +75,7 @@ class BackupDialog: self._info_check_button = builder.get_object("info_check_button") self._info_bar = builder.get_object("info_bar") self._message_label = builder.get_object("message_label") + self._file_count_label = builder.get_object("file_count_label") if IS_GNOME_SESSION: header_bar = Gtk.HeaderBar(visible=True, show_close_button=True) @@ -106,10 +108,14 @@ class BackupDialog: def init_data(self): if os.path.isdir(self._backup_path): for file in filter(lambda x: x.endswith(".zip"), os.listdir(self._backup_path)): - self._model.append((file.rstrip(".zip"), False)) + p = Path(os.path.join(self._backup_path, file)) + if p.is_file(): + self._model.append((p.stem, get_size_from_bytes(p.stat().st_size))) else: os.makedirs(os.path.dirname(self._backup_path), exist_ok=True) + self._file_count_label.set_text(str(len(self._model))) + def on_restore_bouquets(self, item): self.restore(RestoreType.BOUQUETS) @@ -136,6 +142,8 @@ class BackupDialog: else: list(map(model.remove, itrs_to_delete)) + self._file_count_label.set_text(str(len(self._model))) + def on_view_popup_menu(self, menu, event): if event.get_event_type() == Gdk.EventType.BUTTON_PRESS and event.button == Gdk.BUTTON_SECONDARY: menu.popup(None, None, None, None, event.button, event.time) diff --git a/app/ui/backup_dialog.glade b/app/ui/backup_dialog.glade index dcb43305..98a3552d 100644 --- a/app/ui/backup_dialog.glade +++ b/app/ui/backup_dialog.glade @@ -41,10 +41,10 @@ Author: Dmitriy Yefremov - + + + - - @@ -198,16 +198,23 @@ Author: Dmitriy Yefremov - Details True False False + Details center 15 - details_image True False + + + True + False + emblem-important-symbolic + 1 + + @@ -228,84 +235,170 @@ Author: Dmitriy Yefremov - + True - True - 5 + False 5 5 + 5 5 - True + 0 + in - + True True - in + 5 + 5 + 5 + 5 + True - - True - True - True - main_list_store - False - 0 - True - True - - - - - - multiple - - - - - Backup - True - 0.5 - True - 0 - - - 10 - - - 0 - - - - - - - - - True - True - - - - - False - in - - + True False - 5 - False - 10 - 10 - 10 - False - False + vertical + 2 + + + True + True + in + + + True + True + True + main_list_store + 0 + True + True + + + + + + multiple + + + + + 75 + Name + True + True + 0.5 + True + 0 + + + 10 + + + 0 + + + + + + + fixed + 120 + Size + 0.5 + + + 0.49000000953674316 + + + 1 + + + + + + + + + True + True + 0 + + + + + True + False + 5 + 5 + 2 + 5 + + + True + False + document-properties + + + False + True + 0 + + + + + True + False + 0 + 4 + 0 + + + False + True + 1 + + + + + False + True + 1 + + + + True + True + + + + + False + in + + + True + False + 5 + False + 10 + 10 + 10 + False + False + + + + + True + True + - - True - True - + + + diff --git a/app/ui/ftp.py b/app/ui/ftp.py index f23481a1..0b14f3c9 100644 --- a/app/ui/ftp.py +++ b/app/ui/ftp.py @@ -39,7 +39,7 @@ from urllib.parse import urlparse, unquote from gi.repository import GLib -from app.commons import log, run_task, run_idle +from app.commons import log, run_task, run_idle, get_size_from_bytes from app.connections import UtfFTP from app.settings import IS_LINUX, IS_DARWIN, IS_WIN, SEP from app.ui.dialogs import show_dialog, DialogType, get_builder @@ -290,7 +290,7 @@ class FtpClientBox(Gtk.HBox): r_size = self.LINK icon = self._link_icon else: - r_size = self.get_size_from_bytes(size) + r_size = get_size_from_bytes(size) self._file_model.append(File(icon, p.name, r_size, date, str(p.resolve()), size)) @@ -314,7 +314,7 @@ class FtpClientBox(Gtk.HBox): r_size = self.LINK icon = self._link_icon else: - r_size = self.get_size_from_bytes(size) + r_size = get_size_from_bytes(size) date = f"{f_data[5]}, {f_data[6]} {f_data[7]}" self._ftp_model.append(File(icon, f_data[8], r_size, date, f_data[0], size)) @@ -801,25 +801,6 @@ class FtpClientBox(Gtk.HBox): """ Sets default homogeneous sizes. """ paned.set_position(0.5 * allocation.width) - @staticmethod - def get_size_from_bytes(size): - """ Simple convert function from bytes to other units like K, M or G. """ - try: - b = float(size) - except ValueError: - return size - else: - kb, mb, gb = 1024.0, 1048576.0, 1073741824.0 - if b < kb: - return str(b) - elif kb <= b < mb: - return f"{b / kb:.1f} K" - elif mb <= b < gb: - return f"{b / mb:.1f} M" - elif gb <= b: - return f"{b / gb:.1f} G" - - -if __name__ == '__main__': +if __name__ == "__main__": pass diff --git a/app/ui/main.py b/app/ui/main.py index a85df7c0..3a5d0f2e 100644 --- a/app/ui/main.py +++ b/app/ui/main.py @@ -265,6 +265,7 @@ class Application(Gtk.Application): # Current page. self._page = Page.INFO self._fav_pages = {Page.SERVICES, Page.PICONS, Page.EPG, Page.TIMERS} + self._download_pages = {Page.INFO, Page.SERVICES, Page.SATELLITE, Page.PICONS} # Signals. GObject.signal_new("profile-changed", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) @@ -1902,12 +1903,18 @@ class Application(Gtk.Application): # ***************** Send/Receive data ********************* # def on_receive(self, action=None, value=None): - self.change_action_state("on_logs_show", GLib.Variant.new_boolean(True)) - self.emit("data-receive", self._page) + if self._page in self._download_pages: + self.change_action_state("on_logs_show", GLib.Variant.new_boolean(True)) + self.emit("data-receive", self._page) + else: + self.show_error_message("Not allowed in this context!") def on_send(self, action=None, value=None): - self.change_action_state("on_logs_show", GLib.Variant.new_boolean(True)) - self.emit("data-send", self._page) + if self._page in self._download_pages: + self.change_action_state("on_logs_show", GLib.Variant.new_boolean(True)) + self.emit("data-send", self._page) + else: + self.show_error_message("Not allowed in this context!") def on_download(self, app, page): if page is Page.SERVICES or page is Page.INFO: