From c050f6f868d0663b4070b7209cdbb62655b264d2 Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 31 Mar 2026 20:33:04 +0200 Subject: [PATCH 1/2] GUI: Try to fix scaling for small screens --- npbackup/gui/__main__.py | 7 ++++--- npbackup/gui/ttk_theme.py | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/npbackup/gui/__main__.py b/npbackup/gui/__main__.py index 28f8dc6..526834a 100644 --- a/npbackup/gui/__main__.py +++ b/npbackup/gui/__main__.py @@ -413,7 +413,7 @@ def ls_window( col0_heading=_t("generic.path"), col0_width=80, key="-TREE-", - show_expanded=False, + show_expanded=True, enable_events=False, expand_x=True, expand_y=True, @@ -425,15 +425,16 @@ def ls_window( sg.Button(_t("generic.quit"), key="quit"), ], ] - layout = [[sg.Column(left_col, element_justification="C")]] + layout = [[sg.Column(left_col, element_justification="C", expand_x=True, expand_y=True)]] window = sg.Window( _t("generic.content"), layout=layout, grab_anywhere=True, no_titlebar=False, keep_on_top=False, - size=(int(WINDOW_SCALING * 1024), int(WINDOW_SCALING * 650)), + size=sg.Window.get_screen_size(), enable_close_attempted_event=True, + resizable=True, ) # Reclaim memory from thread result diff --git a/npbackup/gui/ttk_theme.py b/npbackup/gui/ttk_theme.py index 5d5d447..809105c 100644 --- a/npbackup/gui/ttk_theme.py +++ b/npbackup/gui/ttk_theme.py @@ -55,7 +55,20 @@ try: WINDOW_SCALING = float(os.environ.get("NPBACKUP_SCALING", None)) except (TypeError, ValueError): - WINDOW_SCALING = 1.0 + WINDOW_SCALING = None + +# Let's decide our own scaling +# Get actual pixel size for scaling +def get_scaling(): + # called before window created + root = sg.tk.Tk() + scaling = root.winfo_fpixels('1i')/92 + root.destroy() + return scaling +width, height = sg.Window.get_screen_size() +WINDOW_SCALING = round(1.0 * get_scaling(), 2) +print(WINDOW_SCALING) + if WINDOW_SCALING: sg.set_options(scaling=WINDOW_SCALING) theme = os.environ.get("NPBACKUP_THEME", "light").lower() @@ -71,15 +84,6 @@ sg.ADDITIONAL_TTK_STYLING_PATHS = ttk_theme_path sg.USE_TTK_BUTTONS = False -# Get actual pixel size for scaling -root = sg.tk.Tk() -scale = 96 / root.winfo_fpixels("1i") # Format your layout if when 96 DPI -root.destroy() - - -def scaled(pixels): - return round(scale * pixels) - sg.theme(CURRENT_THEME) From 9456aa916f3fc528e1e9c8d03353aaa42ef1c732 Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 31 Mar 2026 21:03:07 +0200 Subject: [PATCH 2/2] GUI: Another UI scaling fix try --- npbackup/gui/__main__.py | 2 +- npbackup/gui/config.py | 2 +- npbackup/gui/ttk_theme.py | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/npbackup/gui/__main__.py b/npbackup/gui/__main__.py index 526834a..bc9a0df 100644 --- a/npbackup/gui/__main__.py +++ b/npbackup/gui/__main__.py @@ -432,7 +432,7 @@ def ls_window( grab_anywhere=True, no_titlebar=False, keep_on_top=False, - size=sg.Window.get_screen_size(), + size=(int(1500 * WINDOW_SCALING), int(900 * WINDOW_SCALING)), enable_close_attempted_event=True, resizable=True, ) diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index 4927ecb..a9d1246 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -1100,7 +1100,7 @@ def config_layout() -> List[list]: window = sg.Window( title="Configuration", layout=config_layout(), - size=(int(1000 * WINDOW_SCALING), int(800 * WINDOW_SCALING)), + size=(int(1500 * WINDOW_SCALING), int(900 * WINDOW_SCALING)), auto_size_text=True, auto_size_buttons=False, default_element_size=(12, 1), diff --git a/npbackup/gui/ttk_theme.py b/npbackup/gui/ttk_theme.py index 809105c..ad045d6 100644 --- a/npbackup/gui/ttk_theme.py +++ b/npbackup/gui/ttk_theme.py @@ -23,6 +23,7 @@ TITLE_FONT, # Is needed for imports by other gui files ) + try: from resources.customization import SG_CUSTOM_THEME, SG_CUSTOM_DARK_THEME @@ -65,9 +66,19 @@ def get_scaling(): scaling = root.winfo_fpixels('1i')/92 root.destroy() return scaling + width, height = sg.Window.get_screen_size() -WINDOW_SCALING = round(1.0 * get_scaling(), 2) -print(WINDOW_SCALING) +if width <= 800 or height <=600: + scaling_factor = 0.6 + HAVE_TTK_THEME = False + print(f"Too small screen size detected {width}x{height}, this will create UI glitches we cannot fix") +elif width <= 1366 or height <= 768: + scaling_factor = 0.85 + HAVE_TTK_THEME = False + print(f"Small screen size detected {width}x{height}, this will create UI. We'll disable TTK themes to avoid some of them") +else: + scaling_factor = 1.0 +WINDOW_SCALING = round(1.0 * get_scaling() * scaling_factor, 2) if WINDOW_SCALING: sg.set_options(scaling=WINDOW_SCALING)