Overriding events in a subclass

Hello everyone,

I am creating a subclass of wx.ListCtrl, and I’m having trouble overriding the wx.EVT_LIST_ITEM_SELECTED event.

Here is my subclass:

···

class JumpListCtrl(wx.ListCtrl):
def init(self,
parent,
id=-1,
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.LC_ICON,
validator=wx.DefaultValidator,

     name=wx.ListCtrlNameStr
     ):

print "inside __init__ (JumpListCtrl)"
wx.ListCtrl.__init__(self, parent, id, pos, size, style, validator, name)

self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListSelect, id=wx.ID_NEW)

def OnListSelect(self, event):
    print "inside OnListSelect (JumpListCtrl)"

When I create an instance of JumpListCtrl, I get the “inside init (JumpListCtrl)” message, but I don’t “inside OnListSelect (JumpListCtrl)” message when selecting list items.

Am I doing something wrong here? I have been looking for information on the internet on how to override events in wxPython subclasses, but I haven’t found much.

Thanks in advance.

Jonathan

Hello,

···

On Nov 23, 2008, at 1:31 PM, python dev wrote:

Hello everyone,

I am creating a subclass of wx.ListCtrl, and I'm having trouble overriding the wx.EVT_LIST_ITEM_SELECTED event.

Here is my subclass:

--------------------------------------------
class JumpListCtrl(wx.ListCtrl):
    def __init__(self,
         parent,
         id=-1,
         pos=wx.DefaultPosition,
         size=wx.DefaultSize,
         style=wx.LC_ICON,
         validator=wx.DefaultValidator,
         name=wx.ListCtrlNameStr
         ):

    print "inside __init__ (JumpListCtrl)"
    wx.ListCtrl.__init__(self, parent, id, pos, size, style, validator, name)

    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListSelect, id=wx.ID_NEW)

    def OnListSelect(self, event):
        print "inside OnListSelect (JumpListCtrl)"
--------------------------------------------

When I create an instance of JumpListCtrl, I get the "inside __init__ (JumpListCtrl)" message, but I don't "inside OnListSelect (JumpListCtrl)" message when selecting list items.

Am I doing something wrong here? I have been looking for information on the internet on how to override events in wxPython subclasses, but I haven't found much.

Its probably because of the id=wx.ID_NEW. You are binding the event to the widget that's ID is wx.ID_NEW. However your ListCtrl may or may not have that id.

self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListSelect)

Should work.

Cody

Yes, that works. Thanks Cody.

Jonathan

···

On Sun, Nov 23, 2008 at 2:40 PM, Cody Precord codyprecord@gmail.com wrote:

Its probably because of the id=wx.ID_NEW. You are binding the event to the widget that’s ID is wx.ID_NEW. However your ListCtrl may or may not have that id.

self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListSelect)

Should work.

Cody