From 0a5bbad55b3fb239b524a78c580ad68e003b1634 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 11 Sep 2020 09:26:01 +0100 Subject: [PATCH 1/3] UI Scaling: Change our %age scaling to be relative to base tk-scaling So if at startup tk-scaling is 1.33 then a user configured 200(%) will set it to 2.66 for this run. * Low end of scale bar set to 10, not 0, because now 0 makes absolutely no sense. * In theory the width of the scale bar, in pixels, is now also correctly scaled. --- EDMarketConnector.py | 11 ++++++++--- prefs.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 765fa62f..b6e348a7 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1062,13 +1062,18 @@ Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' Translations.install(config.get('language') or None) # Can generate errors so wait til log set up root = tk.Tk(className=appname.lower()) + + # UI Scaling + """ + We scale the UI relative to what we find tk-scaling is on startup. + """ ui_scale = config.getint('ui_scale') if not ui_scale: - ui_scale = 0 + ui_scale = 100 config.set('ui_scale', ui_scale) theme.default_ui_scale = root.tk.call('tk', 'scaling') - if ui_scale != 0: - root.tk.call('tk', 'scaling', float(ui_scale) / 100.0) + logger.debug(f'Default tk scaling = {theme.default_ui_scale}') + root.tk.call('tk', 'scaling', theme.default_ui_scale * float(ui_scale) / 100.0) app = AppWindow(root) def messagebox_not_py3(): diff --git a/prefs.py b/prefs.py index 7643a8f6..40cf8a93 100644 --- a/prefs.py +++ b/prefs.py @@ -339,6 +339,13 @@ class PreferencesDialog(tk.Toplevel): self.theme_button_1.grid(row=21, column=1, padx=PADX, pady=PADY, sticky=tk.NSEW) # UI Scaling + """ + The provided UI Scale setting is a percentage value relative to the + tk-scaling setting on startup. + + So, if at startup we find tk-scaling is 1.33 and have a user setting + of 200 we'll end up setting 2.66 as the tk-scaling value. + """ ttk.Separator(themeframe, orient=tk.HORIZONTAL).grid(columnspan=4, padx=PADX, pady=PADY*4, sticky=tk.EW) nb.Label(themeframe, text=_('UI Scale Percentage')).grid(row=23, padx=PADX, pady=2*PADY, sticky=tk.W) self.ui_scale = tk.IntVar() @@ -347,8 +354,8 @@ class PreferencesDialog(tk.Toplevel): themeframe, variable=self.ui_scale, orient=tk.HORIZONTAL, - length=300, - from_=0, + length=300 * (float(config.getint('ui_scale')) / 100.0 * theme.default_ui_scale), + from_=10, to=400, tickinterval=50, resolution=10, @@ -356,7 +363,7 @@ class PreferencesDialog(tk.Toplevel): self.uiscale_bar.grid(row=23, column=1, sticky=tk.W) self.ui_scaling_defaultis = nb.Label( themeframe, - text=_('0 means Default{CR}Restart Required for{CR}changes to take effect!') + text=_('100 means Default{CR}Restart Required for{CR}changes to take effect!') ).grid(row=23, column=3, padx=PADX, pady=2*PADY, sticky=tk.E) # Always on top From 5f759ee2d3bb76d0275789dc3ff65f9d91f133ea Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 11 Sep 2020 09:29:00 +0100 Subject: [PATCH 2/3] UI Scaling: Update translation now that 100 is default. --- L10n/en.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index 1e5b6cb0..a8ca6dc6 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -529,8 +529,8 @@ /* Label for 'UI Scaling' option [prefs.py] */ "UI Scale Percentage" = "UI Scale Percentage"; -/* Text describing that value '0' means 'default', and changes require a restart [prefs.py] */ -"0 means Default{CR}Restart Required for{CR}changes to take effect!" = "0 means Default{CR}Restart Required for{CR}changes to take effect!"; +/* Text describing that value '100' means 'default', and changes require a restart [prefs.py] */ +"100 means Default{CR}Restart Required for{CR}changes to take effect!" = "100 means Default{CR}Restart Required for{CR}changes to take effect!"; /* Label for user configured level of logging [prefs.py] */ "Log Level" = "Log Level"; From cd24db88a99dd9dffc968ae0f83d6f0e1277b5cb Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 11 Sep 2020 11:14:19 +0100 Subject: [PATCH 3/3] UI Scaling: Size the Scale bar as per our startup value If we use the last configured value then the width of the Scale bar changes as per the user's last setting, even though they might not have yet restarted for all the rest of the UI to resize. --- EDMarketConnector.py | 2 ++ prefs.py | 4 ++-- theme.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b6e348a7..f2f8fbb4 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1068,11 +1068,13 @@ Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' We scale the UI relative to what we find tk-scaling is on startup. """ ui_scale = config.getint('ui_scale') + # NB: This *also* catches a literal 0 value to re-set to the default 100 if not ui_scale: ui_scale = 100 config.set('ui_scale', ui_scale) theme.default_ui_scale = root.tk.call('tk', 'scaling') logger.debug(f'Default tk scaling = {theme.default_ui_scale}') + theme.startup_ui_scale = ui_scale root.tk.call('tk', 'scaling', theme.default_ui_scale * float(ui_scale) / 100.0) app = AppWindow(root) diff --git a/prefs.py b/prefs.py index 40cf8a93..6b2e824c 100644 --- a/prefs.py +++ b/prefs.py @@ -354,8 +354,8 @@ class PreferencesDialog(tk.Toplevel): themeframe, variable=self.ui_scale, orient=tk.HORIZONTAL, - length=300 * (float(config.getint('ui_scale')) / 100.0 * theme.default_ui_scale), - from_=10, + length=300 * (float(theme.startup_ui_scale) / 100.0 * theme.default_ui_scale), + from_=0, to=400, tickinterval=50, resolution=10, diff --git a/theme.py b/theme.py index f1a97721..d56b7798 100644 --- a/theme.py +++ b/theme.py @@ -116,6 +116,7 @@ class _Theme(object): self.defaults = {} self.current = {} self.default_ui_scale = None # None == not yet known + self.startup_ui_scale = None def register(self, widget): # Note widget and children for later application of a theme. Note if the widget has explicit fg or bg attributes.