From f2ab8f0fd1491dd49610de73394f4e4b49e4f4e7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 10 Sep 2020 16:54:14 +0100 Subject: [PATCH] UI Scaling: Switch to using integers to avoid tk bug Using a Tk.DoubleVar() with a locale where a comma is used as the decimals separator leads to internal tk code recording values with the comma but then other tk code not accepting that back, so it always thinks the value is zero and the scale slider can't be moved. Ref: https://stackoverflow.com/questions/45289237/tkinter-scale-slider-with-float-values-doesnt-work-with-locale-of-language-that * Change to storing as a REG_DWORD under 'ui_scale' not 'ui_scaling'. * Change all the code, except the call to *set* the tk scaling to use an integer, with 100 = 100%, i.e. equivalent to the old 1.0. * Update strings slightly, so translations will need updating too. NB: The theme.default_ui_scale value for plugin authors to query is still the float that tk returns. --- EDMarketConnector.py | 14 +++++++------- L10n/en.template | 6 +++--- prefs.py | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4cfd4985..1898fe83 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1038,7 +1038,7 @@ argv[0]: {sys.argv[0]} exec_prefix: {sys.exec_prefix} executable: {sys.executable} sys.path: {sys.path}''' - ) +) # TODO: unittests in place of these # logger.debug('Test from __main__') @@ -1056,13 +1056,13 @@ sys.path: {sys.path}''' Translations.install(config.get('language') or None) # Can generate errors so wait til log set up root = tk.Tk(className=appname.lower()) - ui_scaling = config.get('ui_scaling') - if not ui_scaling: - ui_scaling = '0.0' - config.set('ui_scaling', ui_scaling) + ui_scale = config.getint('ui_scale') + if not ui_scale: + ui_scale = 0 + config.set('ui_scale', ui_scale) theme.default_ui_scale = root.tk.call('tk', 'scaling') - if ui_scaling != '0.0': - root.tk.call('tk', 'scaling', float(ui_scaling)) + if ui_scale != 0: + root.tk.call('tk', 'scaling', float(ui_scale) / 100.0) app = AppWindow(root) def messagebox_not_py3(): diff --git a/L10n/en.template b/L10n/en.template index dc286b4e..1e5b6cb0 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -527,10 +527,10 @@ "{APP} needs permission to use shortcuts" = "{APP} needs permission to use shortcuts"; /* Label for 'UI Scaling' option [prefs.py] */ -"UI Scaling" = "UI Scaling"; +"UI Scale Percentage" = "UI Scale Percentage"; -/* Text describing that value '0.0' means 'default', and changes require a restart [prefs.py] */ -"0.0 means Default{CR}Restart Required for{CR}changes to take effect!" = "0.0 means Default{CR}Restart Required for{CR}changes to take effect!"; +/* 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!"; /* Label for user configured level of logging [prefs.py] */ "Log Level" = "Log Level"; diff --git a/prefs.py b/prefs.py index 934ebcd2..7643a8f6 100644 --- a/prefs.py +++ b/prefs.py @@ -340,22 +340,24 @@ class PreferencesDialog(tk.Toplevel): # UI Scaling ttk.Separator(themeframe, orient=tk.HORIZONTAL).grid(columnspan=4, padx=PADX, pady=PADY*4, sticky=tk.EW) - nb.Label(themeframe, text=_('UI Scaling')).grid(row = 23, padx=PADX, pady=2*PADY, sticky=tk.W) - self.ui_scaling = tk.DoubleVar() - self.ui_scaling.set(float(config.get('ui_scaling'))) + nb.Label(themeframe, text=_('UI Scale Percentage')).grid(row=23, padx=PADX, pady=2*PADY, sticky=tk.W) + self.ui_scale = tk.IntVar() + self.ui_scale.set(config.getint('ui_scale')) self.uiscale_bar = tk.Scale( themeframe, - variable=self.ui_scaling, + variable=self.ui_scale, orient=tk.HORIZONTAL, length=300, - from_=0.0, - to=4.0, - tickinterval=0.5, - resolution=0.1, + from_=0, + to=400, + tickinterval=50, + resolution=10, ) self.uiscale_bar.grid(row=23, column=1, sticky=tk.W) - #self.ui_scaling_defaultis = nb.Label(themeframe, text=_('0.0 means Default') + '\n' + _('Restart Required for') + '\n' + _('changes to take effect!')).grid(row=23, column=3, padx=PADX, pady=2*PADY, sticky=tk.E) - self.ui_scaling_defaultis = nb.Label(themeframe, text=_('0.0 means Default{CR}Restart Required for{CR}changes to take effect!')).grid(row=23, column=3, padx=PADX, pady=2*PADY, sticky=tk.E) + self.ui_scaling_defaultis = nb.Label( + themeframe, + text=_('0 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 ttk.Separator(themeframe, orient=tk.HORIZONTAL).grid(columnspan=3, padx=PADX, pady=PADY*4, sticky=tk.EW) @@ -649,8 +651,7 @@ class PreferencesDialog(tk.Toplevel): config.set('language', lang_codes.get(self.lang.get()) or '') Translations.install(config.get('language') or None) - config.set('ui_scaling', str(self.ui_scaling.get())) - # self.tk.call('tk', 'scaling', self.ui_scaling.get()) + config.set('ui_scale', self.ui_scale.get()) config.set('always_ontop', self.always_ontop.get()) config.set('theme', self.theme.get()) config.set('dark_text', self.theme_colors[0])