wxEditableListBox

I'm fairly new to Python, and using wxPython for the first time, so please excuse any ignorance in this question.

I'm trying to use the wxEditableListBox, but I'm running into a couple of problems getting events from it. The code I'm using looks like:

self.elb = wxEditableListBox(self, -1, '', size=(150, 100), style=wxEL_ALLOW_NEW | wxEL_ALLOW_DELETE)
elbId = self.elb.GetListCtrl().GetId()
EVT_LIST_ITEM_SELECTED(self, elbId, self.onItemSelected)
newId = self.demoControl.GetNewButton().GetId()
EVT_BUTTON(self, newId, self.onNew)

def onItemSelected(self, event):
     print 'item selected'

def onNew(self, event):
     print 'new'

I add 2 items to the list elsewhere. I would expect to see 'item selected' when I single click on an item, and 'new' when I click on the new item button. Neither works. However, when I do:

EVT_LIST_ITEM_ACTIVATED(self, elbId, self.onItemSelected)

I do see 'item selected' printed to the console. What am I doing wrong?

I'm using wxPython 2.4 for Python 2.2

Thanks in advance,
Adam Endicott

Adam Endicott wrote:

I'm fairly new to Python, and using wxPython for the first time, so please excuse any ignorance in this question.

I'm trying to use the wxEditableListBox, but I'm running into a couple of problems getting events from it. The code I'm using looks like:

self.elb = wxEditableListBox(self, -1, '', size=(150, 100), style=wxEL_ALLOW_NEW | wxEL_ALLOW_DELETE)
elbId = self.elb.GetListCtrl().GetId()
EVT_LIST_ITEM_SELECTED(self, elbId, self.onItemSelected)
newId = self.demoControl.GetNewButton().GetId()
EVT_BUTTON(self, newId, self.onNew)

def onItemSelected(self, event):
    print 'item selected'

def onNew(self, event):
    print 'new'

I add 2 items to the list elsewhere. I would expect to see 'item selected' when I single click on an item, and 'new' when I click on the new item button. Neither works. However, when I do:

EVT_LIST_ITEM_ACTIVATED(self, elbId, self.onItemSelected)

I do see 'item selected' printed to the console. What am I doing wrong?

The wxEditableListBox is probably catching the EVT_LIST_ITEM_SELECTED and handling the event itself. Once an event has been handled then normally no other handlers are looked for. So what you want to do is catch the event before the wxEditableListBox does, which you can do by binding the hander to self.elb.GetListCtrl() instead of to self. Just be sure to call event.Skip() in your handler so the system will keep searching for handlers and the one in wxEditableLIstBox will still get called so it can still do it's default processing.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for the quick resonse, that worked great! I also tried binding the button handler to self.elb, that seems to work too.

···

At 10:30 AM 6/10/03, you wrote:

Adam Endicott wrote:

I'm fairly new to Python, and using wxPython for the first time, so please excuse any ignorance in this question.
I'm trying to use the wxEditableListBox, but I'm running into a couple of problems getting events from it. The code I'm using looks like:
self.elb = wxEditableListBox(self, -1, '', size=(150, 100), style=wxEL_ALLOW_NEW | wxEL_ALLOW_DELETE)
elbId = self.elb.GetListCtrl().GetId()
EVT_LIST_ITEM_SELECTED(self, elbId, self.onItemSelected)
newId = self.demoControl.GetNewButton().GetId()
EVT_BUTTON(self, newId, self.onNew)
def onItemSelected(self, event):
    print 'item selected'
def onNew(self, event):
    print 'new'

I add 2 items to the list elsewhere. I would expect to see 'item selected' when I single click on an item, and 'new' when I click on the new item button. Neither works. However, when I do:
EVT_LIST_ITEM_ACTIVATED(self, elbId, self.onItemSelected)
I do see 'item selected' printed to the console. What am I doing wrong?

The wxEditableListBox is probably catching the EVT_LIST_ITEM_SELECTED and handling the event itself. Once an event has been handled then normally no other handlers are looked for. So what you want to do is catch the event before the wxEditableListBox does, which you can do by binding the hander to self.elb.GetListCtrl() instead of to self. Just be sure to call event.Skip() in your handler so the system will keep searching for handlers and the one in wxEditableLIstBox will still get called so it can still do it's default processing.