wxPyCommandEvent questions/bugs

Robb Shecter wrote:

That's great that you're working on this. And, that you're
looking for the correct solutions for the particular parts -
I'm sure that what you're doing will end up being a guide
for others.

Thank you! (I hadn't planned to spend so much time on this, but
I also take pride in my work, and getting the implementation
right has been trickier than I'd planned. I've also discovered
several things that I should fix in the wxTimeCtrl that I
submitted earlier; specifically the Cut and Paste issue that
I had completely overlooked.)

I will, however, let someone else follow my example to create
a proper wxFloatCtrl. (Although interesting for illustrative
purposes, the wxPyWiki cookbook example for one is just, well,
lame. :slight_smile: I have no immediate need for it though, and can't
afford the time to generate one, but there ought to be a control
that, in addition to what wxIntCtrl will do, handles decimal
fractions, fixed precision, etc. (Perhaps one day someone
will supersede wxIntCtrl with a proper wxNumCtrl that optionally
does all of this.)

What does your package do,
and would it make my task any easier?

I'm not sure if it'd make it easier - you seem to be grubbing around
pretty deep in the event chain. :slight_smile: But then again, maybe it
would. If the package keeps working and being useful, it looks
like it'll become more a standard part of wxPython. Take a look
at the demo in the 'new demos' or the 'event' categories. And if
you can, from the latest wxPython version - I fixed a Skip issue.
I've wanted to post a short announce about it here to the group -
I'll put more information in that.

I look forward to it. I've been too busy to install the latest
and greatest wxPython, but I will probably get to it in the
coming month.

Regards,
/Will Sadkin
Parlance Corporation

This is a short introduction to the EventManager - a group of classes and modules that implement higher-level, object-oriented API on top of the existing event system.

To get it: Install the latest version of wxPython (2.4.0.1). There's a demo in the 'new since last release' section.

Why it exists: Several things happened at the same time;
1) I started doing wxPython programming after years of Java work, and was used to the Swing style of registering listeners, like: aButton.addListener(aHandler). 2) I was working on a complex application for editing images that required one event to be sent to many listeners, and discovered that the wxWindows event system doesn't handle this case. (It supports many-to-one relationships.)
3) I had just finished writing a flexible Publish/Subscribe module.

What it does: (From the demo overview)

The goal of the EventManager is to make wxWindows events more
'Pythonic' (ie. object-oriented) and easier to work with, without
impacting performance. It offers these features:

    * Allows any number of listeners to register for a single
    event. (In addition to the standard wxPython feature of a single
    listener being able to respond to many events.)

    * Makes it easy to disconnect and reconnect listeners. This
    has the effect of reducing the need for case-based branching in
    application code.

    * Has an object-oriented API. Programmers register to get
    events directly from the objects that generate them, instead of
    using ID numbers.

So; I'm really interested to see how this works for other people. I have a fairly complex application (screenshot: http://wiki.wxpython.org/index.cgi/RobbShecter ) based on the EventManager. It must handle the case of dozens of events per second going through the system, being routed to hundreds of handlers that are dynamically registered and deregistered.

Please send me feedback about cases where this works, or doesn't. Finally, here's the API used by an application programmer. This really shows, in a nutshell, what the package is all about.

Usage:

The EventManager class has three public methods. First get a
reference to it:

      from wxPython.lib.evtmgr import eventManager

...and then invoke any of the following methods. These methods are
'safe'; duplicate registrations or de-registrations will have no
effect.

Registering a listener:

       eventManager.Register(listener, event, event-source)

De-registering by window:

       eventManager.DeregisterWindow(event-source)

De-registering by listener:

       eventManager.DeregisterListener(listener)

Simple Example:

  from wxPython.lib.evtmgr import eventManager

  aButton = wxButton(somePanel, -1, 'Click me')
  eventManager.Register(self.someMethod, EVT_BUTTON, aButton)