[wxpython-users] accelerator newbie, help
Oswaldo Hernández
listas at soft-com.es
Thu Apr 24 09:51:04 PDT 2008
Bernd Kreuss escribió:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Phillip Watts wrote:
>> TypeError: an integer is required
>
> As far as i have understood this the wx.AcceleratorTable should fire a
> wx.EVT_MENU, but I remember once spending more than an hour trying to
> get this to work in a small test application with only a naked frame
> without a menu without any success until I finally gave up.
>
> If someone could post a minimal working example for this I would be
> interested too.
>
I make a library function to make more easy accelerators:
def AtSet(ventana, teclas):
"""
Create Accelerator Table
ventana: object to assign the accelerator
teclas: tuple of tuples(flag, key, function_to_bind)
"""
at = []
for tecla in teclas:
eid = wx.NewId()
at.append(wx.AcceleratorEntry(tecla[0], tecla[1], eid))
ventana.Bind(wx.EVT_MENU, tecla[2], id=eid)
ventana.SetAcceleratorTable(wx.AcceleratorTable(at))
Put on a library module and when you need an accelerator only do:
mylib.AtSet(self, (
(wx.ACCEL_CTRL, wx.WXK_LEFT, self.OnCtrlLeft),
(wx.ACCEL_CTRL, wx.WXK_RIGHT, self.OnCtrlRight),
))
--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.
More information about the wxpython-users
mailing list