Events in wxPy 2.5 - question/proposal

Hi Robin and other wxPython gurus,

When you define event handler macros, some macros requires
two arguments and some three arguments. (I count the "self" as
an argument)

Code example with a wxTextCtrl:

···

#---------------------------------------------------------
class MyTextCtrl(wxTextCtrl):
    
    def __init__(self, parent, id, txt, pos, size):
        wxTextCtrl.__init__(self, parent, id, '', pos, size)
        
        self.id = self.GetId()
        
        EVT_CHAR(self, self.OnChar)
        EVT_KEY_UP(self, self.OnKeyUp)
        EVT_KEY_DOWN(self, self.OnKeyDown)
        EVT_LEFT_DOWN(self, self.OnLeftDown)
        EVT_TEXT(self, self.id, self.OnText)
        
    def OnKeyDown(self, event):
        print jmtime() + 'OnKeyDown'
        event.Skip()

    def OnChar(self, event):
        print jmtime() + 'OnChar'
        event.Skip()
    
    def OnKeyUp(self, event):
        print jmtime() + 'OnKeyUp'
        event.Skip()
    
    def OnLeftDown(self, event):
        print jmtime() + 'OnLeftDown'
        event.Skip()
        
    def OnText(self, event):
        print jmtime() + 'OnTest'
        event.Skip()
#--------------------------

From *an end user point of view*, I do not understand why you

should define a char/mouse event handler in the above class
        EVT_KEY_UP(self, self.OnKeyUp)
or
        EVT_LEFT_DOWN(self, self.OnLeftDown)
with 2 arguments, while using three in
        EVT_TEXT(self, self.id, self.OnText)

This seems not logical. Both macros apply to the same
control. Is there a way to unify this in 2.5?

Regards

Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

Hi Robin and other wxPython gurus,

When you define event handler macros, some macros requires
two arguments and some three arguments. (I count the "self" as
an argument)

And some 4.

[...]

From *an end user point of view*, I do not understand why you
should define a char/mouse event handler in the above class
        EVT_KEY_UP(self, self.OnKeyUp) or
        EVT_LEFT_DOWN(self, self.OnLeftDown)
with 2 arguments, while using three in
        EVT_TEXT(self, self.id, self.OnText)

This seems not logical. Both macros apply to the same
control.

It is not the type of control that determines it, but the type of event object that is generated when the event happens.

Events derived from wxCommandEvent are allowed to travel up to the parent windows, and so you need to be able to differentiate the event bindings but the ID of the source, in case the parent window wants to catch events of the same from more than one child. If you are catching the event in the control that is generating it then you can just use wxID_ANY (or -1) as a wildcard.

On the other hand, events that derive from wxEvent do not travel up to the parent windows and so there is never any need to differentiate their bindings by ID.

Is there a way to unify this in 2.5?

Yes, see the "Binding Events" section of http://lists.wxwindows.org/cgi-bin/ezmlm-cgi?12:mss:221:mijoofleblacnmjippbg

···

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