From 25de9a1181f26b3560aa7e0c9d0170558e3ffbf6 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Fri, 20 Oct 2017 17:19:49 -0700 Subject: [PATCH] enable deselecting a mutually exclusive group --- gooey/gui/widgets/components.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/gooey/gui/widgets/components.py b/gooey/gui/widgets/components.py index bfc5925..7c9f65b 100644 --- a/gooey/gui/widgets/components.py +++ b/gooey/gui/widgets/components.py @@ -167,6 +167,8 @@ class RadioGroup(object): self.do_layout(parent, title, msg) + self.selected_button = None + def do_layout(self, parent, titles, msgs): self.panel = wx.Panel(parent) @@ -192,13 +194,20 @@ class RadioGroup(object): self.panel.SetSizer(vertical_container) self.panel.Bind(wx.EVT_SIZE, self.onResize) - self.panel.Bind(wx.EVT_RADIOBUTTON, self.showz) + + for button in self.radio_buttons: + button.Bind(wx.EVT_LEFT_DOWN, self.handle_selection) + return self.panel - def showz(self, evt): - print(evt) - for i in self.radio_buttons: - print(i.GetValue()) + def handle_selection(self, event): + if event.EventObject.Id == getattr(self.selected_button, 'Id', None): + # if it is already selected, manually deselect it + self.selected_button.SetValue(False) + self.selected_button = None + else: + event.Skip() + self.selected_button = event.EventObject def onResize(self, evt): msg = self.help_msgs[0]