Nathan McCorkle
2014-09-17 23:51:05 UTC
I was trying to post this as a reply to an existing thread, but Google
I made a function which seems to work for me (I was trying to enable the
Escape key to fire a Close event no matter where on the Dialog it was
pressed):
def __init__(self, parent):
#do init
#bind all this and all the children to the KEY_DOWN event
self.bindAllChildren(self, wx.EVT_KEY_DOWN, self.lookForEsc)
def lookForEsc(self, event):
if event.GetKeyCode()== wx.WXK_ESCAPE:
self.EndModal(wx.ID_CANCEL)
event.Skip()
def bindAllChildren(self, obj, event, handler):
if isinstance(obj, (list, wx.WindowList)):
for sub_obj in obj:
self.bindAllChildren(sub_obj, event, handler)
if hasattr(obj, 'Bind'):
obj.Bind(event, handler)
if hasattr(obj, 'GetChildren'):
obj = obj.GetChildren()
if obj:
self.bindAllChildren(obj, event, handler)
I'll post an update if I find this breaking things.
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown, child)
. . .which didn't work, probably because (again) the events don't
propagate.
. . .which didn't work, probably because (again) the events don't
propagate.
Escape key to fire a Close event no matter where on the Dialog it was
pressed):
def __init__(self, parent):
#do init
#bind all this and all the children to the KEY_DOWN event
self.bindAllChildren(self, wx.EVT_KEY_DOWN, self.lookForEsc)
def lookForEsc(self, event):
if event.GetKeyCode()== wx.WXK_ESCAPE:
self.EndModal(wx.ID_CANCEL)
event.Skip()
def bindAllChildren(self, obj, event, handler):
if isinstance(obj, (list, wx.WindowList)):
for sub_obj in obj:
self.bindAllChildren(sub_obj, event, handler)
if hasattr(obj, 'Bind'):
obj.Bind(event, handler)
if hasattr(obj, 'GetChildren'):
obj = obj.GetChildren()
if obj:
self.bindAllChildren(obj, event, handler)
I'll post an update if I find this breaking things.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.