mercado mercado wrote:
I just upgraded from wxPython 2.8.7.1 <http://2.8.7.1/> to 2.8.8.1 <http://2.8.8.1/> on my machine (Ubuntu Hardy 8.04.1), and the following code stopped working:
(snippet from larger program)
------------------------------------------------------------------------------
self.text = wx.TextCtrl(self.panel, -1)
self.list = wx.ListCtrl(self.panel, -1, style=wx.LC_REPORT
> wx.BORDER_NONE
> wx.LC_EDIT_LABELS
)self.text.Bind(wx.EVT_KEY_DOWN, self.OnKeyStroke)
self.list.Bind(wx.EVT_KEY_DOWN, self.OnKeyStroke)def OnKeyStroke(self, event):
id = event.EventObject.Id <http://event.eventobject.id/>if id == self.text.Id <http://self.text.id/>:
(snip #1)
elif id == self.list.Id <http://self.list.id/>:
(snip #2)
------------------------------------------------------------------------------If I print out self.text.Id <http://self.text.id/> and self.list.Id , they give me values of -203 and -204, respectively.
When an event fires from the text control, id has a value of -203, and everything works as it did before. However, when an event fires from the list control, id has a value of -205, the compare fails, and none of the code in (snip #2) runs. This same code worked fine with wxPython 2.8.7.1.
Am I doing something wrong by using event.EventObject.Id to identify the control that fired an event, or is this a bug in wxPython?
I don't see anything in the svn log that sounds like a change related to this so I'm not sure yet what it was before, but I can tell you why it is behaving the way it is now. The generic listctrl used on GTK and Mac is actually implemented with sub-windows, and those sub-windows have their own IDs. Since the main sub-window has the focus when the key event happens then that is which ID is put into the key event. Try comparing with self.list.MainWindow.Id instead of self.list.Id, or see Chris' reply for a better way to do it.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!