Hey all. So I'm attempting to include mouse gestures as a part of a GUI I'm designing. I'm using the following code, and it works great HOWEVER only when the gesture is draw away from widgets/controls (such as buttons, statictext's, etc). If I start a gesture and cross the path of a widget, the gesture gets interrupted. Anyone know how I can use gestures on top of widgets? Thanks

Note: In the following code, drawing an 'L' closes the window. Code from: http://wiki.wxpython.org/AnotherTutorial

import wx
import wx.lib.gestures as gest

class MyMouseGestures(wx.Frame):
    def __init__ (self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 500))

        panel = wx.Panel(self, -1)
        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)

    def OnDownRight(self):
          self.Close()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyMouseGestures(None, -1, "mousegestures.py")
        frame.Show(True)
        frame.Centre()
        return True

app = MyApp(0)
app.MainLoop()

Recommended Answers

All 3 Replies

Associate you guesture with the top/main panel. Example.

pan1=wx.panel(self,-1)
pan2=wx.panel(self,-1)

#Now the buttons and other stuffs on pan2.
#make pan2  inherit pan1 as the parent.
#Associate the gusture on the pan1

That will fix it buddy ;)

Thanks for the reply richieking. I'm intrigued, but would this not make the buttons/controls on pan1 inaccessible? And forgive my lack of knowledge, but how would I make pan2 inherit pan1 as the parent? Would I do something like:

class pan1(wx.Panel):
    self.create_pan2 = pan2(self)
    self.[create gesture...]

class pan2(wx.Panel):
    self.[create other cotrols...]

...then obviously call pan1 from wx.Frame

Cheers

You are welcome.

just make 2 panels.
say pan1 and pan2

pan1=wx.Panel(self,-1)
pan2=wx.panel(pan1,-1)

That is it
;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.