]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/MouseGestures.py
3 #Under the GPL, etc, etc.
5 #Thanks to Robin Dunn for taking the time to show me how to do this
10 #This is a hacked version of DragAndDrop.py from the wxPython demo 2.5.2.8
13 from wx
.lib
.gestures
import MouseGestures
17 #Add a dialog to record gestures (Have it showcase the manual mode)
18 #Allow users to remove gestures
20 #----------------------------------------------------------------------
22 class TestPanel(wx
.Panel
):
23 def __init__(self
, parent
, log
):
24 wx
.Panel
.__init
__(self
, parent
, -1)
26 ID_GESTURE
= wx
.NewId()
32 self
.mg
= MouseGestures(self
, Auto
=True)
34 self
.mg
.SetGesturesVisible(True)
36 self
.mg
.AddGesture('L', self
.LogSomethingClever
, 'You moved left')
37 self
.mg
.AddGesture('9', self
.LogSomethingClever
, 'You moved right and up')
38 self
.mg
.AddGesture('U', self
.LogSomethingClever
, 'You moved up')
39 self
.mg
.AddGesture('DR', self
.OnDownThenRight
)
43 self
.btnAddGesture
= wx
.Button(self
, ID_GESTURE
, 'Add New Gesture')
45 msg
= "Mouse Gestures"
46 text
= wx
.StaticText(self
, -1, "", style
=wx
.ALIGN_CENTRE
)
47 text
.SetFont(wx
.Font(24, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
50 w
,h
= text
.GetTextExtent(msg
)
51 text
.SetSize(wx
.Size(w
,h
+1))
52 text
.SetForegroundColour(wx
.BLUE
)
55 outsideSizer
= wx
.BoxSizer(wx
.VERTICAL
)
57 outsideSizer
.Add(text
, 0, wx
.EXPAND|wx
.ALL
, 5)
58 outsideSizer
.Add(wx
.StaticLine(self
, -1), 0, wx
.EXPAND
)
59 outsideSizer
.Add(wx
.StaticText(self
, -1, ' '), 0, wx
.EXPAND
)
60 outsideSizer
.Add(wx
.StaticText(self
, -1, 'Hold The Middle Mouse Button Down to Gesticulate'), 0, wx
.EXPAND
)
61 outsideSizer
.Add(wx
.StaticText(self
, -1, 'Left, The Diagonal Up/Right, Down Then Right, and Up are Preset'), 0, wx
.EXPAND
)
62 outsideSizer
.Add(wx
.StaticText(self
, -1, ' '), 0, wx
.EXPAND
)
63 outsideSizer
.Add(self
.btnAddGesture
, 0, wx
.SHAPED
)
65 self
.SetAutoLayout(True)
66 self
.SetSizer(outsideSizer
)
70 self
.Bind(wx
.EVT_BUTTON
, self
.OnAddGesture
, id=ID_GESTURE
)
72 def LogSomethingClever(self
, somethingclever
):
73 self
.log
.WriteText(somethingclever
)
75 def OnAddGesture(self
, event
):
76 d
= wx
.TextEntryDialog(self
, "Enter Gesture (LRUD1379) (EG Right Then Up Then DownLeft is RU1):", "Add New Gesture", "")
77 answer1
= d
.ShowModal()
78 gesture
= d
.GetValue()
80 d
= wx
.TextEntryDialog(self
, 'Print the following text on "%s":' % gesture
, "Gesture Action", "")
81 answer2
= d
.ShowModal()
84 if (answer1
== wx
.ID_OK
) and (answer2
== wx
.ID_OK
):
85 self
.mg
.AddGesture(gesture
.upper(), self
.LogSomethingClever
, text
)
87 def OnDownThenRight(self
):
88 self
.log
.WriteText('You made an "L"!')
90 #----------------------------------------------------------------------
92 def runTest(frame
, nb
, log
):
93 win
= TestPanel(nb
, log
)
96 #----------------------------------------------------------------------
102 This demo shows how to add MouseGestures
103 to your program, and showcases the MouseGestures
104 class in all it's mousey glory.
111 if __name__
== '__main__':
114 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])