GUI: Hide blocked window when new window appears

This commit is contained in:
deajan 2025-03-05 07:59:37 +01:00
parent 5a80d545b4
commit b0615a09ae
2 changed files with 51 additions and 26 deletions

View file

@ -50,7 +50,7 @@ from resources.customization import (
)
from npbackup.gui.config import config_gui, ask_manager_password
from npbackup.gui.operations import operations_gui
from npbackup.gui.helpers import get_anon_repo_uri, gui_thread_runner
from npbackup.gui.helpers import get_anon_repo_uri, gui_thread_runner, HideWindow
from npbackup.gui.handle_window import handle_current_window
from npbackup.core.i18n_helper import _t
from npbackup.core import upgrade_runner
@ -326,6 +326,7 @@ def _make_treedata_from_json(ls_result: List[dict]) -> sg.TreeData:
def ls_window(repo_config: dict, snapshot_id: str) -> bool:
with HideWindow(window):
result = gui_thread_runner(
repo_config,
"ls",
@ -587,6 +588,7 @@ def _main_gui(viewer_mode: bool):
sg.PopupError(_t("generic.file_does_not_exist"), keep_on_top=True)
continue
try:
with HideWindow(window):
full_config = npbackup.configuration.load_config(config_file)
except EnvironmentError as exc:
sg.PopupError(exc, keep_on_top=True)
@ -726,12 +728,14 @@ def _main_gui(viewer_mode: bool):
if action == "--CANCEL--":
break
if action == "--NEW-CONFIG--":
with HideWindow(window):
full_config = config_gui(
npbackup.configuration.get_default_config(), config_file
)
if config_file:
logger.info(f"Using configuration file {config_file}")
try:
with HideWindow(window):
full_config = npbackup.configuration.load_config(config_file)
GUI_STATUS_IGNORE_ERRORS = True
except EnvironmentError as exc:
@ -1148,18 +1152,21 @@ def _main_gui(viewer_mode: bool):
if not full_config:
sg.PopupError(_t("main_gui.no_config"), keep_on_top=True)
continue
with HideWindow(window):
full_config = operations_gui(full_config)
event = "--STATE-BUTTON--"
if event == "--CONFIGURE--":
if not full_config:
sg.PopupError(_t("main_gui.no_config"), keep_on_top=True)
continue
with HideWindow(window):
full_config = config_gui(full_config, config_file)
GUI_STATUS_IGNORE_ERRORS = True
# Make sure we trigger a GUI refresh when configuration is changed
# Also make sure we retrigger get_config
event = "--LOAD-EXISTING-CONF--"
if event == "--OPEN-REPO--":
with HideWindow(window):
viewer_repo_uri, viewer_repo_password = viewer_repo_gui(
viewer_repo_uri, viewer_repo_password
)
@ -1221,6 +1228,7 @@ def _main_gui(viewer_mode: bool):
sg.PopupNoFrame(destination_string)
continue
if event == "--ABOUT--":
with HideWindow(window):
about_gui(
version_string,
config_file,

View file

@ -363,3 +363,20 @@ def gui_thread_runner(
# Do not change this because of linter, it's a false positive to say we can remove the else statement
else:
return result
class HideWindow:
"""
Context manager to hide a window when a new one is opened
This prevents showing blocked windows
"""
def __init__(self, window):
self.window = window
def __enter__(self):
self.window.hide()
def __exit__(self, exc_type, exc_value, traceback):
# exit method receives optional traceback from execution within with statement
self.window.un_hide()