AcceleratorTables with ACCEL_CMD under OS X

Has anyone had any luck binding CMD+Q when using an AcceleratorTable, under OS X? I already have a bunch of shortcut keys that work in both Windows and Mac, but when attempting to bind the CMD key, I just get the (un)helpful honk from the OS.

This little test app will demonstrate the problem:

import wx

def QuitWithCmdQ(event):

print 'quitting!'

event.Skip()

def TestFunction(event):

print 'Received', type(event)

event.Skip()

app = wx.App(False)

frame = wx.Frame(None, wx.ID_ANY, “Hello World”)

cmd_q = wx.NewId()

cmd_w = wx.NewId()

frame.Bind(wx.EVT_MENU, QuitWithCmdQ, id=cmd_q)

frame.Bind(wx.EVT_MENU, TestFunction, id=cmd_w)

accelerators = wx.AcceleratorTable([

(wx.ACCEL_CMD, ord('Q'), cmd_q),

(wx.ACCEL_NORMAL, ord('W'), cmd_w),

])

frame.SetAcceleratorTable(accelerators)

frame.Show(True)

app.MainLoop()

When pressing ‘W’ it works fine, and should print out “Received <class ‘wx._core.CommandEvent’>”

When pressing ‘CMD+Q’ it doesn’t do anything!

If anyone has an idea where I’m going wrong I would appreciate the insight!

I’ve attached the test code, since I didn’t read the posting instructions prior to posting!

testapp.py (546 Bytes)

Which version of wxPython are you using? If 2.9.x, are you using the Carbon or Cocoa build?

···

On 8/13/12 8:29 AM, alexander wrote:

Has anyone had any luck binding CMD+Q when using an AcceleratorTable,
under OS X? I already have a bunch of shortcut keys that work in both
Windows and Mac, but when attempting to bind the CMD key, I just get the
(un)helpful honk from the OS.

This little test app will demonstrate the problem:

--
Robin Dunn
Software Craftsman

Has anyone had any luck binding CMD+Q when using an AcceleratorTable,

under OS X? I already have a bunch of shortcut keys that work in both

Windows and Mac, but when attempting to bind the CMD key, I just get the

(un)helpful honk from the OS.

This little test app will demonstrate the problem:

Which version of wxPython are you using? If 2.9.x, are you using the
Carbon or Cocoa build?

import wxversion

wxversion.getInstalled()

[‘2.9.3-osx_cocoa’]

···

On Monday, 13 August 2012 23:58:12 UTC, Robin Dunn wrote:

On 8/13/12 8:29 AM, alexander wrote:

Okay. Try it with 2.9.4, it's working for me here.

···

On 8/14/12 2:51 AM, alexander wrote:

On Monday, 13 August 2012 23:58:12 UTC, Robin Dunn wrote:

    On 8/13/12 8:29 AM, alexander wrote:
     > Has anyone had any luck binding CMD+Q when using an
    AcceleratorTable,
     > under OS X? I already have a bunch of shortcut keys that work in
    both
     > Windows and Mac, but when attempting to bind the CMD key, I just
    get the
     > (un)helpful honk from the OS.
     >
     > This little test app will demonstrate the problem:

    Which version of wxPython are you using? If 2.9.x, are you using the
    Carbon or Cocoa build?

>>> import wxversion
>>> wxversion.getInstalled()
['2.9.3-osx_cocoa']

--
Robin Dunn
Software Craftsman

 > Has anyone had any luck binding CMD+Q when using an
AcceleratorTable,
 > under OS X? I already have a bunch of shortcut keys that work in
both
 > Windows and Mac, but when attempting to bind the CMD key, I just
get the
 > (un)helpful honk from the OS.
 >
 > This little test app will demonstrate the problem:
Which version of wxPython are you using?  If 2.9.x, are you using the
Carbon or Cocoa build?

import wxversion

wxversion.getInstalled()

[‘2.9.3-osx_cocoa’]

Okay. Try it with 2.9.4, it’s working for me here.

Awesome, that fixes the issue. Thanks for your time and help.

···

On Tuesday, 14 August 2012 15:37:32 UTC, Robin Dunn wrote:

On 8/14/12 2:51 AM, alexander wrote:

On Monday, 13 August 2012 23:58:12 UTC, Robin Dunn wrote:
On 8/13/12 8:29 AM, alexander wrote:


Robin Dunn

Software Craftsman

http://wxPython.org

Cmd-Q is special on Macs and will typically be an accelerator for a menu item with an ID of wx.ID_EXIT or whatever ID you've assigned with wx.App.SetMacExitMenuItemId. If there is not a real menu item with that ID then I suppose it's possible that the event is stolen before the accelerator table is checked because of the special nature of that key.

···

On 11/22/12 11:27 PM, Mika H�nninen wrote:

I have this problem on the 2.8.12.1 (latest 2.8 release atm). Can
somebody confirm it is an issue with that release ?

--
Robin Dunn
Software Craftsman