From ad5bf7106476995ac04d5913ff661547ace27332 Mon Sep 17 00:00:00 2001 From: Daniel <86781586+0xDS@users.noreply.github.com> Date: Thu, 6 Feb 2025 05:47:01 +1400 Subject: [PATCH] Update application.py handle child focus for per-field level validation. --- gooey/gui/containers/application.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gooey/gui/containers/application.py b/gooey/gui/containers/application.py index b232f0e..b1747de 100644 --- a/gooey/gui/containers/application.py +++ b/gooey/gui/containers/application.py @@ -127,11 +127,22 @@ class GooeyApplication(wx.Frame): # self.Bind(wx.EVT_CLOSE, self.onClose) # TODO: handle child focus for per-field level validation. - # self.Bind(wx.EVT_CHILD_FOCUS, self.handleFocus) + self.Bind(wx.EVT_CHILD_FOCUS, self.handleFocus) if self.buildSpec.get('auto_start', False): self.onStart() + def handleFocus(self, event): + """ + Handle focus event for per-field level validation. + """ + child = event.GetWindow() + if isinstance(child, wx.TextCtrl): # Sample validation for text inputs + value = child.GetValue() + if not value: # Simple validation to check if the field is empty + wx.MessageBox('This field cannot be empty!', 'Validation Error', wx.OK | wx.ICON_ERROR) + child.SetFocus() # Keep focus on the field until valid + event.Skip() # Ensure the event is not blocked def applyConfiguration(self): self.SetTitle(self.buildSpec['program_name'])