allow editable scale field for manually setting the app scale value

This commit is contained in:
Huy Pham 2020-03-02 09:56:57 -08:00
parent a7fa0bf6d3
commit b0a3c85f0e
2 changed files with 22 additions and 1 deletions

View file

@ -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)

View file

@ -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: