Enter on dialogs w/ wxMac

Okay. I have a fairly simple dialog on wxMac. On windows, pressing
'enter' triggers the default button. On Mac, it doesn't. How do I fix
this?

class dlgConfirm(wx.Dialog):
    def __init__(self, parent, title, content, id=-1):
        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, wx.ID_OK, "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)
        panel.SetSizer(sizer)
        panel.Layout()
        sizer.Fit(self)
        self.CentreOnScreen()
        wx.EVT_BUTTON(self, wx.ID_OK, self.OnReturn)

    def OnReturn(self, event):
        print 'Returning'
        self.EndModal(wx.ID_OK)

IxokaI wrote:

Okay. I have a fairly simple dialog on wxMac. On windows, pressing
'enter' triggers the default button. On Mac, it doesn't. How do I fix
this?

Something on the dialog must have the focus in order for the Enter key to be caught. On OS X buttons don't get the focus like they can on the other platforms.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

How can I do that? I tried in the example code calling:

button.SetFocus()

and the behavior doesn't change.

···

On 2/2/06, Robin Dunn <robin@alldunn.com> wrote:

IxokaI wrote:
> Okay. I have a fairly simple dialog on wxMac. On windows, pressing
> 'enter' triggers the default button. On Mac, it doesn't. How do I fix
> this?
>

Something on the dialog must have the focus in order for the Enter key
to be caught. On OS X buttons don't get the focus like they can on the
other platforms.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

IxokaI wrote:

How can I do that? I tried in the example code calling:

button.SetFocus()

and the behavior doesn't change.

Because, as I said, buttons can't get the focus on the Mac. You need to have a control on the dialog that can get the focus. If you just want to display a message and an OK button then consider using the standard wx.MessageDialog. Since it is based on a native API it does handle the Enter and ESC keys as you would expect.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!