Setting an accelerator table for a child window

27 views
Skip to first unread message

James Scholes

unread,
Mar 19, 2017, 2:35:45 PM3/19/17
to wxpytho...@googlegroups.com
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

Tim Roberts

unread,
Mar 20, 2017, 3:01:22 AM3/20/17
to wxpytho...@googlegroups.com
On Mar 19, 2017, at 11:35 AM, James Scholes <ja...@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?

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.

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

James Scholes

unread,
Mar 20, 2017, 7:13:32 AM3/20/17
to wxpytho...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages