Monitor all events for a widget

190 views
Skip to first unread message

Michael Hipp

unread,
Feb 24, 2012, 10:42:20 AM2/24/12
to wxPython Users
I fear this is a dumb question, but that never stopped me before...

Is there a simple way to monitor all events emitted by a particular widget and
perhaps print the name of the event that was sent.

Use case: I'm working with a control I've never touched before
(DataViewListCtrl) which has lots of events for which the descriptions in the
docs all seem very similar. So I don't know what to Bind(). Would be nice if I
could just create the widget, poke it a bit, and see what comes out.

Thanks,
Michael

werner

unread,
Feb 24, 2012, 10:52:05 AM2/24/12
to wxpytho...@googlegroups.com
What about running it with the WIT, e.g. create the app with:

from wx.lib.mixins import inspection
app = inspection.InspectableApp(0)

run your test app, ctrl-alt-i and start the Event Watcher

see in the wiki for more details on the WIT -
http://wiki.wxpython.org/Widget%20Inspection%20Tool

Werner

Michael Hipp

unread,
Feb 24, 2012, 11:58:20 AM2/24/12
to wxpytho...@googlegroups.com
On 2012-02-24 9:52 AM, werner wrote:
> On 24/02/2012 16:42, Michael Hipp wrote:
>> Is there a simple way to monitor all events emitted by a particular widget
>> and perhaps print the name of the event that was sent.
> What about running it with the WIT, e.g. create the app with:

Thanks, I've been using the WIT for a long time but never noticed it had an
event monitor. After turning off all the SET_CURSOR events that buries it, I
think it will do what I need.

Thanks,
Michael

Gadget/Steve

unread,
Feb 24, 2012, 12:54:20 PM2/24/12
to wxpytho...@googlegroups.com
Just tried a little experiment:
Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit
(Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> e=wx.Event
>>> dir(e)
['ClassName', 'Clone', 'Destroy', 'EventObject', 'EventType',
'GetClassName', 'G
etEventObject', 'GetEventType', 'GetId', 'GetSkipped', 'GetTimestamp',
'Id', 'Is
CommandEvent', 'IsSameAs', 'ResumePropagation', 'SetEventObject',
'SetEventType'
, 'SetId', 'SetTimestamp', 'ShouldPropagate', 'Skip', 'Skipped',
'StopPropagatio
n', 'Timestamp', '__class__', '__del__', '__delattr__', '__dict__',
'__doc__', '
__format__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__'
, '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str
__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'thisown']
>>> help(e.GetEventType)
Help on method GetEventType in module wx._core:

GetEventType(*args, **kwargs) unbound wx._core.Event method
GetEventType(self) -> EventType

Returns the identifier of the given event type, such as
``wxEVT_COMMAND_BUTTON_CLICKED``.

So if you bind an a single event handler to all the events for your
control you can print out the event types from within the handler...

Gadget/Steve


Robin Dunn

unread,
Feb 24, 2012, 1:58:00 PM2/24/12
to wxpytho...@googlegroups.com
On 2/24/12 9:54 AM, Gadget/Steve wrote:
>>>> help(e.GetEventType)
> Help on method GetEventType in module wx._core:
>
> GetEventType(*args, **kwargs) unbound wx._core.Event method
> GetEventType(self) -> EventType
>
> Returns the identifier of the given event type, such as
> ``wxEVT_COMMAND_BUTTON_CLICKED``.
>
> So if you bind an a single event handler to all the events for your
> control you can print out the event types from within the handler...

Unfortunately they will just be numbers at that point without any useful
meaning attached to them. They will need to be mapped back to their
EVT_ names to be recognizable by a human, and the event watcher in the
WIT does that for you. You can also use the EventWatcher independently
of the WIT if you want to, take a look at the wx.lib.eventwatcher module.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages