Bind() does not work for wx.EVT_LEFT_UP and similar key events

Hello,

I try to bind an event handler to a key event with Bind().
I does not work. Using the old macro works. Is this a bug or a feature ?

Code:

class FrameProcess(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: FrameProcess.__init__
        kwds["style"] = wx.CAPTION|wx.FRAME_NO_TASKBAR|wx.FRAME_FLOAT_ON_PARENT
        wx.Frame.__init__(self, *args, **kwds)
        self.cmdTappet = wx.Button(self, -1, _("Tappet"))
        self.cmdLight = wx.ToggleButton(self, -1, _("Light"))
        self.cmdGrab = wx.Button(self, -1, _("Grab"))

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

        wx.EVT_LEFT_DOWN( self.cmdTappet, self.OnTappet )
        wx.EVT_LEFT_UP( self.cmdTappet, self.OnTappet )
        # binding events with following 2 lines does not work!
        #self.Bind( wx.EVT_LEFT_DOWN, self.OnTappet, self.cmdTappet )
        #self.Bind( wx.EVT_LEFT_UP, self.OnTappet, self.cmdTappet )
        self.Bind( wx.EVT_TOGGLEBUTTON, self.OnLight, self.cmdLight )
        self.Bind( wx.EVT_BUTTON, self.OnGrab, self.cmdGrab )

My platform:
- Windows XP,
- Python 2.3.5
- wxPython 2.6.3.2-ansi

Thanks for your help,
Matthias

···

--
Matthias Kirst

CLONDIAG chip technologies

Matthias Kirst wrote:

Hello,

I try to bind an event handler to a key event with Bind().
I does not work. Using the old macro works. Is this a bug or a feature ?

       wx.EVT_LEFT_DOWN( self.cmdTappet, self.OnTappet )
       wx.EVT_LEFT_UP( self.cmdTappet, self.OnTappet )
       # binding events with following 2 lines does not work!
       #self.Bind( wx.EVT_LEFT_DOWN, self.OnTappet, self.cmdTappet )
       #self.Bind( wx.EVT_LEFT_UP, self.OnTappet, self.cmdTappet )

They don't work because they are not equivalent to the first two lines. In the first case you are binding the events at the self.cmdTappet point, but in the second case you are binding them at the self point, and since they are not command events they are not propagated from self.cmdTappet up to self. This is what you want:

         self.cmdTappet.Bind( wx.EVT_LEFT_DOWN, self.OnTappet )
         self.cmdTappet.Bind( wx.EVT_LEFT_UP, self.OnTappet )

···

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