event handlers with wrong number of args

I am starting to use the wxPython available in debian (woody and sarge).

In the docs about wxListBox, I found that EVT_LISTBOX(id, func) is the
event handler for item selection. However, when I use it, I get a
python error saying that the function needs 3 arguments and only 2 are
provided.

In fact, searching in the module file wx.py, I found this definition:

···

+++++++++++++++++++++++++++
def EVT_LISTBOX(win, id, func):
    win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_SELECTED, func)
---------------------------

In wx.py, many events are defined without "id" argument, and with it set
as "-1" in the win.Connect call, as for instance here:

++++++++++++++++++++++++++++++
def EVT_CHAR(win, func):
    win.Connect(-1, -1, wxEVT_CHAR, func)
------------------------------

So I tryed to call the EVT_LISTBOX function with "-1" as id, and it
*seemed* to work. I am not quite sure about it working properly,
because upon exit I *sometimes* got a messages like this on stderr:

+++++++++++++++++++++++++++++++++++++++
Gtk-WARNING **: invalid cast from `GtkCornerType' to `GtkObject'
Gtk-WARNING **: invalid cast from `GtkCornerType' to `GtkObject'
Gtk-CRITICAL **: file gtkwidget.c: line 2728 (gtk_widget_event):
assertion `GTK_IS_WIDGET (widget)' failed.
---------------------------------------

Anyway, I am not sure about these errors being related with the event
handler problem above.

My questions are:

1-Which is wrong, the docs that talk about the function having 2
arguments, or the code that makes it with 3? Please note that *many*
event handlers are documented as having 2 arguments while in fact wx.py
implement them with 3!

2-Must I expect problems from the quick-and-dirt fix of making id=3D-1?

Thanks for all,
Sebrosa

Here is is what I use when I subclass wxListBox:

        wxEVT_LISTBOX(self, self.GetId(), self.OnSelect)

Cheers,

···

--- Jose' Sebrosa <sebrosa@artenumerica.com> wrote:

I am starting to use the wxPython available in debian (woody and
sarge).

In the docs about wxListBox, I found that EVT_LISTBOX(id, func)
is the event handler for item selection. However, when I use
it, I get a python error saying that the function needs 3
arguments and only 2 are provided.

=====
Donnal Walter
Arkansas Children's Hospital

Jose' Sebrosa wrote:

I am starting to use the wxPython available in debian (woody and sarge).

In the docs about wxListBox, I found that EVT_LISTBOX(id, func) is the
event handler for item selection. However, when I use it, I get a
python error saying that the function needs 3 arguments and only 2 are
provided.

In fact, searching in the module file wx.py, I found this definition:

+++++++++++++++++++++++++++
def EVT_LISTBOX(win, id, func):
    win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_SELECTED, func)
---------------------------

In C++ all EVT_*'s are macros that are used in a way that the window receiving the event is implied. In Python they are functions and you have to specify the window that is going to recieve the event, so all EVT_* functions have an added window parameter. In all other respects they are functionally equivalent to the C++.

1-Which is wrong,

Neither.

the docs that talk about the function having 2
arguments, or the code that makes it with 3? Please note that *many*
event handlers are documented as having 2 arguments while in fact wx.py
implement them with 3!

The docs are for C++, so you have to do alittle translation here and there for Python. This page in the wiki doesn't mention the EVT_* change, but it does mention some other things:

http://wiki.wxpython.org/index.cgi/C_2b_2bGuideForwxPythoneers

2-Must I expect problems from the quick-and-dirt fix of making id=3D-1?

-1 is a wildcard value (wxID_ANY) that simply means catch the EVT_LISTBOX from any wxListBox that is a child of this window, so if you only have one it is okay. Otherwise pass the ID of the listbox.

···

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