]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/MouseGestures.py
Fix for compilo
[wxWidgets.git] / wxPython / demo / MouseGestures.py
CommitLineData
51c5e1f2
RD
1#*******************
2#By Daniel Pozmanter
3#Under the GPL, etc, etc.
4
5#Thanks to Robin Dunn for taking the time to show me how to do this
6#via the mailing list.
7
8#Version 0.0.0 ALPHA
9
10#This is a hacked version of DragAndDrop.py from the wxPython demo 2.5.2.8
11
12import wx, wx.stc
13from wx.lib.gestures import MouseGestures
14
15#ToDo:
16
17#Add a dialog to record gestures (Have it showcase the manual mode)
18#Allow users to remove gestures
19
20#----------------------------------------------------------------------
21
22class TestPanel(wx.Panel):
23 def __init__(self, parent, log):
24 wx.Panel.__init__(self, parent, -1)
25
26 ID_GESTURE = wx.NewId()
27
28 self.log = log
29
30 #Mouse Gestures:
31
32 self.mg = MouseGestures(self, Auto=True)
33
34 self.mg.SetGesturesVisible(True)
35
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)
40
41 #Widgets:
42
43 self.btnAddGesture = wx.Button(self, ID_GESTURE, 'Add New Gesture')
44
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))
48 text.SetLabel(msg)
49
50 w,h = text.GetTextExtent(msg)
51 text.SetSize(wx.Size(w,h+1))
52 text.SetForegroundColour(wx.BLUE)
53
54 #Sizer:
55 outsideSizer = wx.BoxSizer(wx.VERTICAL)
56
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)
64
65 self.SetAutoLayout(True)
66 self.SetSizer(outsideSizer)
67
68
69 #Events:
70 self.Bind(wx.EVT_BUTTON, self.OnAddGesture, id=ID_GESTURE)
71
72 def LogSomethingClever(self, somethingclever):
73 self.log.WriteText(somethingclever)
74
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()
79 d.Destroy()
80 d = wx.TextEntryDialog(self, 'Print the following text on "%s":' % gesture, "Gesture Action", "")
81 answer2 = d.ShowModal()
82 text = d.GetValue()
83 d.Destroy()
84 if (answer1 == wx.ID_OK) and (answer2 == wx.ID_OK):
85 self.mg.AddGesture(gesture.upper(), self.LogSomethingClever, text)
86
87 def OnDownThenRight(self):
88 self.log.WriteText('You made an "L"!')
89
90#----------------------------------------------------------------------
91
92def runTest(frame, nb, log):
93 win = TestPanel(nb, log)
94 return win
95
96#----------------------------------------------------------------------
97
98
99overview = """\
100<html>
101<body>
102This demo shows how to add MouseGestures
103to your program, and showcases the MouseGestures
104class in all it's mousey glory.
105<p><p>
106</body>
107</html>
108"""
109
110
111if __name__ == '__main__':
112 import sys,os
113 import run
114 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
115