From caf8b27bc605977d7d174e1634c25c3a880e5452 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Mon, 22 Jan 2024 21:26:22 +0100 Subject: [PATCH] WIP GUI refactor --- npbackup/gui/config.py | 79 ++++++++++++++++++------- npbackup/translations/config_gui.en.yml | 2 +- npbackup/translations/config_gui.fr.yml | 2 +- npbackup/translations/generic.en.yml | 1 + npbackup/translations/generic.fr.yml | 1 + 5 files changed, 61 insertions(+), 24 deletions(-) diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index 5b76fa5..ede8586 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -96,6 +96,9 @@ def config_gui(full_config: dict, config_file: str): }, } + byte_units = ["B", "KB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB"] + + ENCRYPTED_DATA_PLACEHOLDER = "<{}>".format(_t("config_gui.encrypted_data")) def get_objects() -> List[str]: @@ -272,7 +275,10 @@ def config_gui(full_config: dict, config_file: str): for key in window.AllKeysDict: # We only clear config keys, wihch have '.' separator if "." in str(key) and not "inherited" in str(key): - window[key]("") + if isinstance(window[key], sg.Tree): + window[key].Update(sg.TreeData()) + else: + window[key]("") object_type, object_name = get_object_from_combo(object_name) @@ -473,7 +479,9 @@ def config_gui(full_config: dict, config_file: str): ), ], [ - sg.Tree(sg.TreeData(), key="inherited.backup_opts.path", headings=[], expand_x=True, expand_y=True) + sg.Tree(sg.TreeData(), key="inherited.backup_opts.path", headings=[], + col0_heading=_t("generic.paths"), + expand_x=True, expand_y=True) ], [ sg.Input(visible=False, key="--PATHS-ADD-FILE--", enable_events=True), @@ -494,32 +502,43 @@ def config_gui(full_config: dict, config_file: str): ), sg.pin(sg.Image(INHERITANCE_ICON, key="inherited.backup_opts.backup_priority", tooltip=_t("config_gui.group_inherited"))) ], + [ + sg.Column([ + [ + sg.Tree(sg.TreeData(), key="inherited.backup_opts.tags", headings=[], + col0_heading="Tags", col0_width=30, num_rows=3, expand_x=True, expand_y=True) + ] + ], pad=0, size=(295, 80)), + sg.Column([ + [ + sg.Button("+", key="--ADD-TAG--", size=(3, 1)) + ], + [ + sg.Button("-", key="--REMOVE-TAG--", size=(3, 1)) + ] + ], pad=0, size=(50, 80)), + sg.Column([ + [ + sg.Text(_t("config_gui.minimum_backup_size_error"), size=(40, 2)), + ], + [ + sg.Input(key="backup_opts.minimum_backup_size_error", size=(20, 1)), + sg.Combo(byte_units, default_value=byte_units[3], key="bakcup_opts.minimum_backup_size_error_unit") + ] + ], pad=0, size=(300, 80)) + ], [ sg.Checkbox("", key="backup_opts.use_fs_snapshot", size=(1, 1)), sg.Text( textwrap.fill(f'{_t("config_gui.use_fs_snapshot")} ({_t("config_gui.windows_only")})', width=34), size=(34, 2), ), - ], - [ - sg.Text(_t("config_gui.minimum_backup_size_error"), size=(40, 2)), - sg.Input(key="backup_opts.minimum_backup_size_error", size=(50, 1)), - ], - [ - sg.Text( - f"{_t('config_gui.tags')}\n({_t('config_gui.one_per_line')})", - size=(40, 2), - ), - sg.Multiline(key="backup_opts.tags", size=(48, 4)), - ], - [ - sg.Text(_t("config_gui.additional_parameters"), size=(40, 1)), - sg.Input(key="backup_opts.additional_parameters", size=(50, 1)), - ], - [ sg.Text( _t("config_gui.additional_backup_only_parameters"), size=(40, 1) ), + ], + [ + sg.Input( key="backup_opts.additional_backup_only_parameters", size=(50, 1) ), @@ -753,6 +772,10 @@ def config_gui(full_config: dict, config_file: str): ), sg.Multiline(key="env.encrypted_env_variables", size=(48, 5)), ], + [ + sg.Text(_t("config_gui.additional_parameters"), size=(40, 1)), + sg.Input(key="backup_opts.additional_parameters", size=(50, 1)), + ], ] object_list = get_objects() @@ -964,7 +987,8 @@ def config_gui(full_config: dict, config_file: str): object_layout(), key="--repo-group-config--", expand_x=True, - expand_y=True + expand_y=True, + pad=0 ) ], [ @@ -973,7 +997,8 @@ def config_gui(full_config: dict, config_file: str): global_options_layout(), key="--global-config--", expand_x=True, - expand_y=True + expand_y=True, + pad=0 ) ], ] @@ -981,7 +1006,7 @@ def config_gui(full_config: dict, config_file: str): _global_layout = [ [ sg.TabGroup( - tab_group_layout, enable_events=True, key="--configtabgroup--", expand_x=True, expand_y=True, + tab_group_layout, enable_events=True, key="--configtabgroup--", expand_x=True, expand_y=True, pad=0, ) ], [sg.Push(), sg.Column(buttons, @@ -1006,6 +1031,7 @@ def config_gui(full_config: dict, config_file: str): ) backup_paths_tree = sg.TreeData() + tags_tree = sg.TreeData() # Update gui with first default object (repo or group) update_object_gui(get_objects()[0], unencrypted=False) @@ -1052,6 +1078,15 @@ def config_gui(full_config: dict, config_file: str): for key in values['inherited.backup_opts.path']: backup_paths_tree.delete(key) window['inherited.backup_opts.path'].update(values=backup_paths_tree) + if event == "--ADD-TAG--": + node = sg.PopupGetText(_t("config_gui.enter_tag")) + if node: + tags_tree.insert('', node, node, node) + window["inherited.backup_opts.tags"].Update(values=tags_tree) + if event == "--REMOVE-TAG--": + for key in values["inherited.backup_opts.tags"]: + tags_tree.delete(key) + window["inherited.backup_opts.tags"].Update(values=tags_tree) if event == "--ACCEPT--": if ( not values["repo_opts.repo_password"] diff --git a/npbackup/translations/config_gui.en.yml b/npbackup/translations/config_gui.en.yml index 2a693b5..425749a 100644 --- a/npbackup/translations/config_gui.en.yml +++ b/npbackup/translations/config_gui.en.yml @@ -19,7 +19,7 @@ en: one_file_system: Do not follow mountpoints minimum_backup_size_error: Minimum size under which backup is considered failed pre_exec_commands: Pre-exec commands - maximum_exec_time: Maximum exec time + maximum_exec_time: Maximum exec time (seconds) exec_failure_is_fatal: Execution failure is fatal post_exec_commands: Post-exec commands execute_even_on_backup_error: Execute even if backup failed diff --git a/npbackup/translations/config_gui.fr.yml b/npbackup/translations/config_gui.fr.yml index 459443b..6f11b55 100644 --- a/npbackup/translations/config_gui.fr.yml +++ b/npbackup/translations/config_gui.fr.yml @@ -20,7 +20,7 @@ fr: one_file_system: Ne pas suivre les points de montage minimum_backup_size_error: Taille minimale en dessous de laquelle la sauvegarde est considérée échouée pre_exec_commands: Commandes pré-sauvegarde - maximum_exec_time: Temps maximal d'execution + maximum_exec_time: Temps maximal d'execution (secondes) exec_failure_is_fatal: L'échec d'execution est fatal post_exec_commands: Commandes post-sauvegarde execute_even_on_backup_error: Executer même si la sauvegarde a échouée diff --git a/npbackup/translations/generic.en.yml b/npbackup/translations/generic.en.yml index 7b933ba..5b2d54d 100644 --- a/npbackup/translations/generic.en.yml +++ b/npbackup/translations/generic.en.yml @@ -28,6 +28,7 @@ en: size: Size path: Path + paths: Paths modification_date: Modification date content: Content diff --git a/npbackup/translations/generic.fr.yml b/npbackup/translations/generic.fr.yml index 4563651..c0bbf4f 100644 --- a/npbackup/translations/generic.fr.yml +++ b/npbackup/translations/generic.fr.yml @@ -28,6 +28,7 @@ fr: size: Taille path: Chemin + path: Chemins modification_date: Date de modification content: Contenu