RE: [Pythoncard-users] what does an event object look like
by Kevin Altis other posts by this author
Apr 19 2002 5:06PM messages near this date
[Pythoncard-users] what does an event object look like
|
RE: [Pythoncard-users] what does an event object look like
> From: David Primmer
>
> I'm interested what I can do to inspect event objects. When making an
> event handler, what can I do with the event? What are the most common
> useful events? Are they different for buttons and menus? I tried making
> a copy of an event object and then investigating the namespace with
> pycrust and executing some of it's methods like GetClassName() but that
> just crashes my app. Where would I find, for example, the name of the
> control that sent the event?
PythonCard events are just wxPython events with a few extra attributes added
such as the target (eventObject), the mouse position, modifier key state and
key code if the event was for a key press. Except for the 'target'
attribute, not all events have all the attributes. The 'target' is the
object generating the event, so its name 'event.target.name' should be the
same as the name in your event handler. For example, this assertion should
be true:
def on_btn1_mouseClick(self, event):
assert event.target.name == 'btn1'
A background handler might handle an event type for multiple components:
def on_mouseClick(self, event):
print event.target.name
The tictactoe sample uses a single background handler for the playing field.
The most common events are probably mouseClick and select which are actually
wxCommandEvents. Don't forget to look at the state of the framework messages
on the documentation page:
http://pythoncard.sourceforge.net/documentation.html
in particular the post about events and handlers
http://pythoncard.sourceforge.net/text/events_and_handlers.txt
The code that adds the attributes are in binding.py. As you can see we
aren't currently adding many attributes, but these are the most typically
used.
try:
# all events should have GetEventObject()
aWxEvent.target = aWxEvent.GetEventObject()
aWxEvent.eventObject = aWxEvent.target
except:
pass
try:
# mouse and key events
aWxEvent.position = aWxEvent.GetPosition()
aWxEvent.x = aWxEvent.GetX()
aWxEvent.y = aWxEvent.GetY()
aWxEvent.altDown = aWxEvent.AltDown()
aWxEvent.controlDown = aWxEvent.ControlDown()
aWxEvent.shiftDown = aWxEvent.ShiftDown()
except:
pass
try:
# key events
aWxEvent.keyCode = aWxEvent.GetKeyCode()
except:
pass
To see all of the available methods and the different types of event
objects, look at the wxPython documentation under events. So far, that
wrapped events we're generating include: wxCalendarEvent (Calendar
component), wxCommandEvent (mouseClick, select, most of the common actions
are wxCommandEvents), wxFocusEvent (gainFocus, loseFocus), wxKeyEvent,
wxMouseEvent
For the most part, PythonCard user code shouldn't have to worry about these
event classes and their methods.
To investigate the event, you'll want to use event.Clone() to make a copy.
Any event you clone using wxPython 2.3.2.1 will result in a memory leak, but
that shouldn't matter for investigation purposes.
ka
_______________________________________________
Pythoncard-users mailing list
Pythoncard-users@[...].net
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
Thread:
David Primmer
Kevin Altis
Kevin Altis
|