Hello there. I have a very small, very simple little dialog which is
meant to display a "pretty", little confirmation message. I want it so
that if someone just presses 'enter' when the dialog opens, it will
close it. I just can't get this to work on OSX. Here's some code:
-- begin code --
class dlgConfirm(wx.Dialog):
def __init__(self, parent, id, title, content):
wx.Dialog.__init__(self, parent, id,title=title, style= wx.CAPTION)
if sys.platform == 'darwin':
self.MacSetMetalAppearance(True)
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
text = wx.StaticText(panel, -1, content)
button = wx.Button(panel, -1, "OK")
button.SetDefault()
sizer.Add(text, 1, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=2)
sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, border=2)
self.Bind(wx.EVT_BUTTON, self.OnClose, button)
panel.SetSizer(sizer)
panel.Layout()
sizer.Fit(self)
self.CentreOnScreen()
def OnClose(self, event):
self.EndModal(wx.ID_OK)
--- end code --
I've tried tons of differnt ways to do this, including:
self.Bind(wx.EVT_CHAR, self.OnKeyDown)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_COMMAND_ENTER, self.OnKeyDown)
etc... And thebutton has SetDefault called on it, so its 'focused',
but there is never -anything- happening within def OnKeyDown. The
events never reach it. I tried passing the wx.WANT_CHARS style into
the dialog, but still, no dice.
What am I doing wrong? Thanks!
--Ix