EVT_BUTTON parameter query

Hi,

When setting up a button event thus:

EVT_BUTTON(dlg, 100, cbutp)

what is the first parameter for? In this case dlg.

I'd like to be able to access this parameter in the cbutp(event) function but
can't seem to find out how.

If you know this to be documented somewhere obvious please tell me where. I'm
finding wxPython documentation slightly problematic. If not, just an answer
would be nice.

Edgar.

Edgar writes:

When setting up a button event thus:

EVT_BUTTON(dlg, 100, cbutp)

what is the first parameter for? In this case dlg.

I'd like to be able to access this parameter in the
cbutp(event) function but can't seem to find out how.

def cbutp(evt):
  dlg = evt.GetEventObject()

If you know this to be documented somewhere obvious please
tell me where. I'm finding wxPython documentation slightly
problematic. If not, just an answer would be nice.

The documentation is based on the wxWidgets documentation, and
despite its organizational shortcomings, is quite complete.
GetEventObject() is documented with wxEvent.

But we are getting new Pythonic wxPython documentation. If you
have a relatively recent wxPython (2.5.x), try this:

[pmcnett@sol dabo]$ python
Python 2.3.2 (#1, Oct 6 2003, 10:07:16)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.

import wx
help(wx.Event)

(ok, not much documentation there yet, but at least you can see
the defined method names). Try this instead:

help(wx.Window)

Plenty of documentation there already.

Try using the new Bind() syntax which some find more natural
than calling the wxEVT_ wrapper functions. For instance, with
your example:

import wx

def cbutp(evt):
  print "button", evt.GetEventObject()

dlg = wx.Dialog(...)
but = wx.Button(dlg)

but.Bind(wx.EVT_BUTTON, cbutp)

You'll need an application object as well, but note that you no
longer need to send id's around.

···

--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com

Edgar wrote:

Hi,

When setting up a button event thus:

EVT_BUTTON(dlg, 100, cbutp)

what is the first parameter for? In this case dlg.

It is where in the window heirarchy to bind the event handler. So you can think of it as installing at dlg that is listening for any EVT_BUTTON messages with ID 100 flying by. If it sees any then it will catch it and call cbutp.

I'd like to be able to access this parameter in the cbutp(event) function but can't seem to find out how.

Make cbutp be a method oc the dlg and then just use self.

···

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