binding to events that don't have a PyEventBinder?

Today we needed to execute some code when a TextEditMixin (a ListCtrl mixin) closes its editor. It posts the wxEVT_COMMAND_LIST_END_LABEL_EDIT event when this happens, but catching this event turned out to be tricky -- unlike EVT_BUTTON, there does not appear to be a PyEventBinder already set up for this event.

We solved it by patching in our own:

# wxPython doesn't seem to include the following event binder,
# so let's create it ourselves:
wx.EVT_COMMAND_LIST_END_LABEL_EDIT = wx.PyEventBinder(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT)

(I know, you'd think we could declare this locally rather than stuffing it into the wx module, but our bindings are set up via a config file that expects to find all the binders in wx, so the above was convenient.)

So, is my understanding correct?

1. wxPython includes binders for common events (like EVT_BUTTON) for our convenience, but not all of them.
2. When you need to catch an event for which no PyEventBinder exists, then you just create such a binder yourself, with something like the above.

Or is there an easier way?

Thanks,
- Joe

Hello,

There is a binder: wx.EVT_LIST_END_LABEL_EDIT

The event type wx. wxEVT_COMMAND_LIST_END_LABEL_EDIT shows that it is a command event.

Cody

···

On Fri, Dec 5, 2008 at 11:40 AM, Joe Strout joe@strout.net wrote:

Today we needed to execute some code when a TextEditMixin (a ListCtrl mixin) closes its editor. It posts the wxEVT_COMMAND_LIST_END_LABEL_EDIT event when this happens, but catching this event turned out to be tricky – unlike EVT_BUTTON, there does not appear to be a PyEventBinder already set up for this event.

We solved it by patching in our own:

wxPython doesn’t seem to include the following event binder,

so let’s create it ourselves:

wx.EVT_COMMAND_LIST_END_LABEL_EDIT = wx.PyEventBinder(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT)

(I know, you’d think we could declare this locally rather than stuffing it into the wx module, but our bindings are set up via a config file that expects to find all the binders in wx, so the above was convenient.)

So, is my understanding correct?

  1. wxPython includes binders for common events (like EVT_BUTTON) for our convenience, but not all of them.

  2. When you need to catch an event for which no PyEventBinder exists, then you just create such a binder yourself, with something like the above.

Or is there an easier way?

Thanks,

  • Joe

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Aha! Thanks, didn't see that at all.

So, in general, given wxEVT_COMMAND_FOO, I should expect to fin a binder named wx.EVT_FOO?

Best,
- Joe

···

On Dec 5, 2008, at 10:44 AM, Cody Precord wrote:

There is a binder: wx.EVT_LIST_END_LABEL_EDIT

The event type wx. wxEVT_COMMAND_LIST_END_LABEL_EDIT shows that it is a command event.

Joe Strout wrote:

There is a binder: wx.EVT_LIST_END_LABEL_EDIT

The event type wx. wxEVT_COMMAND_LIST_END_LABEL_EDIT shows that it is a command event.

Aha! Thanks, didn't see that at all.

So, in general, given wxEVT_COMMAND_FOO, I should expect to fin a binder named wx.EVT_FOO?

Best,
- Joe

I would say "yes" for the most part. Some of the more complicated widgets (i.e. wx.grid) may have slightly different names for their events. I recommend doing something like this to find out what events are available:

<code>
import wx

for x in dir(wx):
    if x.startswith('EVT_'):
        print x
</code>

And for my complicated widget example:

<code>
import wx.grid

for x in dir(wx.grid):
    if x.startswith('EVT_'):
        print x
</code>

You can usually find what you are looking for this way...

···

On Dec 5, 2008, at 10:44 AM, Cody Precord wrote:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

I did something like that, but it was too much to quickly read through line by line, so I searched for EVT_COMMAND_LIST_END_LABEL_EDIT, and came up empty-handed. I didn't know that it would appear without the "COMMAND" part.

Thanks all,
- Joe

···

On Dec 5, 2008, at 11:36 AM, Mike Driscoll wrote:

I recommend doing something like this to find out what events are available:

<code>
import wx

for x in dir(wx):
  if x.startswith('EVT_'):
      print x
</code>

Joe Strout wrote:

I recommend doing something like this to find out what events are available:

<code>
import wx

for x in dir(wx):
  if x.startswith('EVT_'):
      print x
</code>

I did something like that, but it was too much to quickly read through line by line, so I searched for EVT_COMMAND_LIST_END_LABEL_EDIT, and came up empty-handed. I didn't know that it would appear without the "COMMAND" part.

The event binders keep track of the event type, so you could do something like this to find a specific binder:

  >>> for x in dir(wx):
  ... if x.startswith('EVT_'):
  ... b = getattr(wx, x)
  ... if hasattr(b, 'typeId') and b.typeId == wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT:
  ... print x
  ...
  EVT_LIST_END_LABEL_EDIT

···

On Dec 5, 2008, at 11:36 AM, Mike Driscoll wrote:

  >>>

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