13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

http://www.zetcode.com/wxpython/tips/mg = gest.MouseGestures(panel, True, wx.MOUSE_BTN_LEFT)mg.SetGesturePen(wx.Colour(255, 0, 0), 2)mg.SetGesturesVisible(True)mg.AddGesture('DR', self.OnDownRight)self.Centre()self.Show(True)def OnDownRight(self):self.Close()app = wx.App()MyMouseGestures(None, -1, 'mousegestures.py')app.MainLoop()In our example, we have registered a mouse gesture for apanel. Mouse gesture is triggered, when a left button ispressed and we go down and right with a cursor. As in letter'L'. Our mouse gesture will close the application.mg = gest.MouseGestures(panel, True, wx.MOUSE_BTN_LEFT)If we want to use mouse gestures, we have to create aMouseGesture object. <strong>The</strong> first parameter is a window,where the mouse gesture is registered. Second parameterdefines a way to register a gesture. True is for automatic,False for manual. Manual is not fully implemented and weare happy with the automatic way. Last parameter defines amouse button, which will be pressed when triggeringgestures. <strong>The</strong> button can be later changed with theSetMouseButton() method.mg.SetGesturePen(wx.Colour(255, 0, 0), 2)Our gestures will be painted as red lines. <strong>The</strong>y will be 2pixels wide.mg.SetGesturesVisible(True)We set this gesture visible with the SetGesturesVisible()method.mg.AddGesture('DR', self.OnDownRight)We register a mouse gesture with the AddGesture() method.14 de 15 27/04/2008 1:09

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!