[wxPython-users] Bind acceleratore table to a function and not
to an id
Robin Dunn
robin at alldunn.com
Wed Nov 22 12:28:02 PST 2006
Franz Steinhaeusler wrote:
> Hello NG,
>
> I have a short sample.
>
> The problem is.
> Imagine you have many controls in a Dialog.
> If you are in a random control, with one hotkey I want
> to exit the dialog.
> you want to quit the dialog with ctrl-q for example.
>
> With the acceleratortable, you can only bind keys to id's, not
> functions.
> But I don't want to bind every control separatly to such an handler.
> Is there any way to have a sort of acceleratortable to bind
> it "globally" to one function?
I think you misunderstand the accelerator table a little bit. The ID in
the table entries is not the ID of the control that the event will
come from, but the ID that will be sent in the simulated menu event, and
which can be used to make the event binding. So the basic pattern is
something like this:
accelId = wx.NewId()
tbl = wx.AcceleratorTable([(wx.ACCEL_ALT, ord('X'), accelId)])
self.SetAcceleratorTable(tbl)
self.Bind(wx.EVT_MENU, self.OnDoSomething, id=accelId)
When Alt-X is pressed in the context of self, a EVT_MENU event is sent
with an id of accelId.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list