From 5d806a82daf52a7625b01093608bf58f194f7315 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Thu, 19 Sep 2024 10:10:05 -0300 Subject: [PATCH] feat: add auto alpha to keypad switching if hinted the type in the params --- panels/gcode_macros.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/panels/gcode_macros.py b/panels/gcode_macros.py index 10445c02..81643283 100644 --- a/panels/gcode_macros.py +++ b/panels/gcode_macros.py @@ -79,14 +79,23 @@ class Panel(ScreenPanel): "row": row, "params": {}, } - pattern = r'params\.(?P[a-zA-Z0-9_]+)(?:\s*\|.*\s*default\(\s*(?P[^\)]+)\))?' + + pattern = re.compile(r'params\.(?P[a-zA-Z0-9_]+)' + r'(?:\s*\|\s*default\(\s*(?P[^\)]+)\s*\))?' + r'(?:\s*\|\s*(?P[a-zA-Z]+))?') for line in gcode: if line.startswith("{") and "params." in line: result = re.search(pattern, line) if result: result = result.groupdict() - default = result["default"] if "default" in result else "" - entry = Gtk.Entry(placeholder_text=default, input_purpose=Gtk.InputPurpose.ALPHA) + default = result.get("default", "") + hint = result.get("hint", "") + entry = Gtk.Entry(placeholder_text=default) + if hint in ("int", "float"): + entry.set_input_purpose(Gtk.InputPurpose.DIGITS) + entry.get_style_context().add_class("active") + else: + entry.set_input_purpose(Gtk.InputPurpose.ALPHA) icon = self._gtk.PixbufFromIcon("hashtag") entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon) entry.connect("icon-press", self.on_icon_pressed)