Setting an accelerator table for a child window

Hi all,

I have a wx.ListBox with a pop-up context menu attached. I want to create a wx.AcceleratorTable so that while keyboard focus is inside the list box, the user can activate the menu items by keyboard shortcut. In any other part of my application, the shortcuts shouldn't be active.

However, calling the SetAcceleratorTable method of my wx.ListBox doesn't seem to actually do anything, and in my testing it doesn't work for wx.Panel either. Only top-level windows like wx.Frame. Is this one of the cases where the wx APIs don't actually match the capabilities of the underlying control?

Thanks.

···

--
James Scholes
http://twitter.com/JamesScholes

No. Your ListBox only has a SetAcceleratorTable method because everything inherited from wx.Window does. The accelerator table is an app-global thing, and hence is only meaningful for wx.Frames. This is a limitation of the underlying operating system, not of wx.

···

On Mar 19, 2017, at 11:35 AM, James Scholes <james@jls-radio.com> wrote:

However, calling the SetAcceleratorTable method of my wx.ListBox doesn't
seem to actually do anything, and in my testing it doesn't work for
wx.Panel either. Only top-level windows like wx.Frame. Is this one of
the cases where the wx APIs don't actually match the capabilities of the
underlying control?


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Tim Roberts wrote:

The accelerator table is an app-global thing, and hence is only meaningful for wx.Frames.

This doesn't seem to be the case, at least not on Windows. To start with, I was binding my wx.EVT_MENU handler directly on the context menu instance, and calling SetAcceleratorTable on my ListBox. My understanding of how wx propagates events is muddled at best, but I assume that the events fired by the ListBox when I pressed the assigned accelerators simply weren't reaching the menu at all. As soon as I bound wx.EVT_MENU on the ListBox instead, the accelerator table worked flawlessly.

Having said that, in a short sample I wrote, setting an accelerator table for a wx.Panel and also binding wx.EVT_MENU on that panel doesn't work either. So maybe the ListBox is a special case or there's something else at play. Either way, for the moment, my ListBox has specific shortcut keys which is what I was after.

···

--
James Scholes
http://twitter.com/JamesScholes