From b0a3c85f0e25adc2ad4840a88cca2ebbada2498b Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Mon, 2 Mar 2020 09:56:57 -0800 Subject: [PATCH] allow editable scale field for manually setting the app scale value --- daemon/core/gui/dialogs/preferences.py | 6 +++++- daemon/core/gui/validation.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/daemon/core/gui/dialogs/preferences.py b/daemon/core/gui/dialogs/preferences.py index 83f50f07..c693e025 100644 --- a/daemon/core/gui/dialogs/preferences.py +++ b/daemon/core/gui/dialogs/preferences.py @@ -81,7 +81,11 @@ class PreferencesDialog(Dialog): ) scale.grid(row=0, column=0, sticky="ew") entry = ttk.Entry( - scale_frame, textvariable=self.gui_scale, width=4, state="disabled" + scale_frame, + textvariable=self.gui_scale, + width=4, + validate="key", + validatecommand=(self.app.validation.app_scale, "%P"), ) entry.grid(row=0, column=1) diff --git a/daemon/core/gui/validation.py b/daemon/core/gui/validation.py index 78685f9f..af16dadd 100644 --- a/daemon/core/gui/validation.py +++ b/daemon/core/gui/validation.py @@ -11,12 +11,16 @@ from netaddr import IPNetwork if TYPE_CHECKING: from core.gui.app import Application +SMALLEST_SCALE = 0.5 +LARGEST_SCALE = 5.0 + class InputValidation: def __init__(self, app: "Application"): self.master = app.master self.positive_int = None self.positive_float = None + self.app_scale = None self.name = None self.ip4 = None self.rgb = None @@ -26,6 +30,7 @@ class InputValidation: def register(self): self.positive_int = self.master.register(self.check_positive_int) self.positive_float = self.master.register(self.check_positive_float) + self.app_scale = self.master.register(self.check_scale_value) self.name = self.master.register(self.check_node_name) self.ip4 = self.master.register(self.check_ip4) self.rgb = self.master.register(self.check_rbg) @@ -105,6 +110,18 @@ class InputValidation: except ValueError: return False + @classmethod + def check_scale_value(cls, s: str) -> bool: + if not s: + return True + try: + float_value = float(s) + if SMALLEST_SCALE <= float_value <= LARGEST_SCALE or float_value == 0: + return True + return False + except ValueError: + return False + @classmethod def check_ip4(cls, s: str) -> bool: if not s: