I've attached my source code for the init function of the dialog class I'm trygin to create. I can't see where I'm going wrong. The events don't work (i.e. OnItemSelected and OnItemActivated aren't called.
class DlgPlaylists(wxDialogPtr):
def __init__(self, parent, db_cursor):
print "init"
res = wxXmlResource("./dialog_playlists.xrc")
dlg = res.LoadDialog(parent, "DLG_PLAYLISTS")
wxDialogPtr.__init__(self, dlg.this)
self.db_cursor = db_cursor
self.list_playlists = XRCCTRL(self, "LIST_PLAYLISTS")
##Query the database for all the playlists
self.db_cursor.execute("select * from playlists;")
playlists = self.db_cursor.fetchall()
for playlist, _ in playlists:
self.list_playlists.Append(playlist)
The way I understand the events is that the first parameter is
object which contains the can handle the event not the object which
emits the event.
The second paramter is the wxWindows ID of the objects which emits
the event.
The way I understand the events is that the first parameter is
object which contains the can handle the event not the object which
emits the event.
The second paramter is the wxWindows ID of the objects which emits
the event.
I tried the way you suggested but it didn't make a difference. I had a look at how boa-constructor handled list boxes and the 1st parameter is the control that generates the event. For example:
EVT_LIST_ITEM_SELECTED(self.listCtrl1, wxID_WXDIALOG1LISTCTRL1,
self.OnListctrl1ListItemSelected)
I'm sure the Id / /am passing to/ /the event handler is right because self.list_playlist.GetId() == XRCID("LIST_PLAYLISTS")
The way I understand the events is that the first parameter is
object which contains the can handle the event not the object which
emits the event.
The second paramter is the wxWindows ID of the objects which emits
the event.
I tried the way you suggested but it didn't make a difference. I had a look at how boa-constructor handled list boxes and the 1st parameter is the control that generates the event. For example:
EVT_LIST_ITEM_SELECTED(self.listCtrl1, wxID_WXDIALOG1LISTCTRL1,
self.OnListctrl1ListItemSelected)
I'm sure the Id / /am passing to/ /the event handler is right because self.list_playlist.GetId() == XRCID("LIST_PLAYLISTS")
The worst thing about this problem is that if I add an event handler for a button that is a child of the dialog it works! This is really puzzling.....I can't see what the difference is between the button event handler and list box event handler.
class DlgPlaylists(wxDialogPtr):
def __init__(self, parent, db_cursor):
print "init"
res = wxXmlResource("./dialog_playlists.xrc")
dlg = res.LoadDialog(parent, "DLG_PLAYLISTS") wxDialogPtr.__init__(self, dlg.this)
self.db_cursor = db_cursor
self.list_playlists = XRCCTRL(self, "LIST_PLAYLISTS")
self.button_ok = XRCCTRL(self, "BUTTON_OK")
##Query the database for all the playlists
self.db_cursor.execute("select * from playlists;")
playlists = self.db_cursor.fetchall() for playlist, _ in playlists:
self.list_playlists.Append(playlist)
then I don't know.
The example I gave works fine for me but
I don't use XRC resources.
So there maybe a difference there.
Regards
Adi
Quoting sashan <sashang@ihug.co.nz>:
···
sashan wrote:
> Adi Sieker wrote:
>
>> Hi Sashan,
>>
>> sashan wrote:
>>
>> [snip]
>> > EVT_LIST_ITEM_SELECTED(self.list_playlists,
>> > XRCID("LIST_PLAYLISTS"), self.OnItemSelected)
>> > EVT_LIST_ITEM_ACTIVATED(self.list_playlists,
>> > XRCID("LIST_PLAYLISTS"), self.OnItemActivated)
>> >
>> Try this:
>> EVT_LIST_ITEM_SELECTED(self,
>> XRCID("LIST_PLAYLISTS"), self.OnItemSelected)
>>
>> The way I understand the events is that the first parameter is
>> object which contains the can handle the event not the object which
>> emits the event.
>> The second paramter is the wxWindows ID of the objects which emits
>> the event.
>
>
>
> I tried the way you suggested but it didn't make a difference. I had a
> look at how boa-constructor handled list boxes and the 1st parameter
> is the control that generates the event. For example:
> EVT_LIST_ITEM_SELECTED(self.listCtrl1, wxID_WXDIALOG1LISTCTRL1,
> self.OnListctrl1ListItemSelected)
>
> I'm sure the Id / /am passing to/ /the event handler is right because
> self.list_playlist.GetId() == XRCID("LIST_PLAYLISTS")
>
Also I think the way you suggest should also work since the example over here http://wiki.wxpython.org/index.cgi/UsingXmlResources uses that method for the
event handlers for the button.
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
I've attached my source code for the init function of the dialog class I'm trygin to create. I can't see where I'm going wrong. The events don't work (i.e. OnItemSelected and OnItemActivated aren't called.
class DlgPlaylists(wxDialogPtr):
def __init__(self, parent, db_cursor):
print "init"
res = wxXmlResource("./dialog_playlists.xrc") dlg = res.LoadDialog(parent, "DLG_PLAYLISTS") wxDialogPtr.__init__(self, dlg.this)
self.db_cursor = db_cursor
self.list_playlists = XRCCTRL(self, "LIST_PLAYLISTS")
##Query the database for all the playlists
self.db_cursor.execute("select * from playlists;")
playlists = self.db_cursor.fetchall() for playlist, _ in playlists:
self.list_playlists.Append(playlist)
I don't see any problems with the above. Please reduce it to a small runnable sample that shows the problem and somebody will take a closer look.
Ok...I've attached a resource file and code to load and run the resource file. The button event works as expected but the list selected event doesn't. The file uses tab characters for spacing (sorry if this annoys some people). You can run it by typing
I don't see any problems with the above. Please reduce it to a small runnable sample that shows the problem and somebody will take a closer look.
Ok...I've attached a resource file and code to load and run the resource file. The button event works as expected but the list selected event doesn't.
You are using the wrong event. Your XRC is using a wxListBox, but EVT_LIST_ITEM_SELECTED is for wxListCtrl's. If you change to EVT_LISTBOX then the handler is called.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!