]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/MouseGestures.py
4 #Thanks to Robin Dunn for taking the time to show me how to do this
9 #This is a hacked version of DragAndDrop.py from the wxPython demo 2.5.2.8
11 import wx
, wx
. lib
. dialogs
12 from wx
. lib
. gestures
import MouseGestures
16 #Add a dialog to record gestures (Have it showcase the manual mode)
17 #Allow users to remove gestures
19 #----------------------------------------------------------------------
21 class TestPanel ( wx
. Panel
):
22 def __init__ ( self
, parent
, log
):
23 wx
. Panel
.__ init
__ ( self
, parent
, - 1 )
25 ID_GESTURE
= wx
. NewId ()
27 ID_MODIFIER
= wx
. NewId ()
28 ID_VISIBLE
= wx
. NewId ()
34 self
. mg
= MouseGestures ( self
, Auto
= True ,
35 MouseButton
= wx
. MOUSE_BTN_RIGHT
)
37 self
. mg
. SetGesturesVisible ( True )
39 self
. mg
. AddGesture ( 'LR' , self
. ShowSomethingClever
, 'Left then Right!' )
40 self
. mg
. AddGesture ( '39' , self
. ShowSomethingClever
, 'You made a V!' )
41 self
. mg
. AddGesture ( 'L' , self
. LogSomethingClever
, 'You moved left' )
42 self
. mg
. AddGesture ( '9' , self
. LogSomethingClever
, 'You moved right and up' )
43 self
. mg
. AddGesture ( 'U' , self
. LogSomethingClever
, 'You moved up' )
44 self
. mg
. AddGesture ( 'DR' , self
. OnDownThenRight
)
45 self
. mg
. AddGesture ( 'LDRU' , self
. SetToBlue
)
46 self
. mg
. AddGesture ( 'RDLU' , self
. SetToOrange
)
50 self
. btnAddGesture
= wx
. Button ( self
, ID_GESTURE
, 'Add New Gesture' )
51 self
. btnChangeMouseButton
= wx
. Button ( self
, ID_MOUSE
, 'Change Mouse Button' )
52 self
. btnChangeModifier
= wx
. Button ( self
, ID_MODIFIER
, 'Change Modifier' )
53 self
. btnToggleVisible
= wx
. ToggleButton ( self
, ID_VISIBLE
, 'Toggle Gestures Visible' )
54 self
. btnToggleVisible
. SetValue ( True )
56 msg
= "Mouse Gestures"
57 text
= wx
. StaticText ( self
, - 1 , "" , style
= wx
. ALIGN_CENTRE
)
58 text
. SetFont ( wx
. Font ( 24 , wx
. SWISS
, wx
. NORMAL
, wx
. BOLD
, False ))
61 w
, h
= text
. GetTextExtent ( msg
)
62 text
. SetSize ( wx
. Size ( w
, h
+ 1 ))
63 text
. SetForegroundColour ( wx
. BLUE
)
66 outsideSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
68 btnSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
70 outsideSizer
. Add ( text
, 0 , wx
. EXPAND|wx
. ALL
, 5 )
71 outsideSizer
. Add ( wx
. StaticLine ( self
, - 1 ), 0 , wx
. EXPAND
)
72 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , ' ' ), 0 , wx
. EXPAND
)
73 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , 'Hold The Middle Mouse Button Down to Gesticulate' ), 0 , wx
. EXPAND
)
74 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , 'Left Then Right, Left, The Diagonal Up/Right, Down Then Right, Diagonal Down/Right Then Diagonal Up/Right, and Up are Preset' ), 0 , wx
. EXPAND
)
75 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , 'Left,Down,Right,Up Sets the line colour to Blue.' ), 0 , wx
. EXPAND
)
76 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , 'Right,Down,Left,Up Sets the line colour to Orange.' ), 0 , wx
. EXPAND
)
77 outsideSizer
. Add ( wx
. StaticText ( self
, - 1 , ' ' ), 0 , wx
. EXPAND
)
78 btnSizer
. Add ( self
. btnAddGesture
, 0 , wx
. SHAPED
)
79 btnSizer
. Add ( self
. btnChangeMouseButton
, 0 , wx
. SHAPED
)
80 btnSizer
. Add ( self
. btnChangeModifier
, 0 , wx
. SHAPED
)
81 btnSizer
. Add ( self
. btnToggleVisible
, 0 , wx
. SHAPED
)
82 outsideSizer
. Add ( btnSizer
, 0 , wx
. SHAPED
)
84 self
. SetAutoLayout ( True )
85 self
. SetSizer ( outsideSizer
)
88 self
. Bind ( wx
. EVT_BUTTON
, self
. OnAddGesture
, id = ID_GESTURE
)
89 self
. Bind ( wx
. EVT_BUTTON
, self
. OnChangeMouseButton
, id = ID_MOUSE
)
90 self
. Bind ( wx
. EVT_BUTTON
, self
. OnChangeModifiers
, id = ID_MODIFIER
)
91 self
. Bind ( wx
. EVT_TOGGLEBUTTON
, self
. OnToggleVisible
, id = ID_VISIBLE
)
93 def LogSomethingClever ( self
, somethingclever
):
94 self
. log
. WriteText ( somethingclever
)
96 def OnAddGesture ( self
, event
):
97 d
= wx
. TextEntryDialog ( self
, "Enter Gesture (LRUD1379) (EG Right Then Up Then DownLeft is RU1):" , "Add New Gesture" , "" )
98 answer1
= d
. ShowModal ()
99 gesture
= d
. GetValue ()
102 d
= wx
. TextEntryDialog ( self
, 'Print the following text on " %s ":' % gesture
, "Gesture Action" , "" )
103 answer2
= d
. ShowModal ()
107 if ( answer1
== wx
. ID_OK
) and ( answer2
== wx
. ID_OK
):
108 self
. mg
. AddGesture ( gesture
. upper (), self
. LogSomethingClever
, text
)
110 def OnChangeModifiers ( self
, event
):
111 choices
= [ wx
. WXK_CONTROL
, wx
. WXK_SHIFT
, wx
. WXK_ALT
]
112 schoices
= [ 'Control' , 'Shift' , 'Alt' ]
114 d
= wx
. lib
. dialogs
. MultipleChoiceDialog ( self
, 'Select Modifier Keys: \n (Select None if you do not want to use modifier keys \n\n ' , "Change Modifier Keys" , schoices
)
115 answer
= d
. ShowModal ()
119 if ( answer
== wx
. ID_OK
):
124 modifiers
. append ( choices
[ x
])
125 modstring
+= schoices
[ x
] + ' '
126 self
. mg
. SetModifiers ( modifiers
)
127 self
. log
. WriteText ( 'Set Modifiers to: ' + modstring
)
129 self
. mg
. SetModifiers ()
130 self
. log
. WriteText ( 'UnSet All Modifiers' )
132 def OnChangeMouseButton ( self
, event
):
133 choices
= [ wx
. MOUSE_BTN_LEFT
, wx
. MOUSE_BTN_MIDDLE
, wx
. MOUSE_BTN_RIGHT
]
134 schoices
= [ 'Left' , 'Middle' , 'Right' ]
135 d
= wx
. SingleChoiceDialog ( self
, "Set Mouse Button To" , "Change Mouse Button" , schoices
,
136 wx
. CHOICEDLG_STYLE|wx
. OK|wx
. CANCEL
)
137 d
. SetSize ( wx
. Size ( 250 , 200 ))
138 answer
= d
. ShowModal ()
141 if ( answer
== wx
. ID_OK
):
142 self
. mg
. SetMouseButton ( choices
[ i
])
143 self
. log
. WriteText ( 'Set the Mouse Button to ' + schoices
[ i
])
145 def OnDownThenRight ( self
):
146 self
. log
. WriteText ( 'You made an "L"!' )
148 def OnToggleVisible ( self
, event
):
149 visual
= self
. btnToggleVisible
. GetValue ()
150 self
. mg
. SetGesturesVisible ( visual
)
152 self
. log
. WriteText ( 'Made Gestures Visible' )
154 self
. log
. WriteText ( 'Made Gestures Invisible' )
157 self
. mg
. SetGesturePen ( wx
. Colour ( 0 , 144 , 255 ), 5 )
158 self
. log
. WriteText ( 'Set Gesture Colour to Blue' )
160 def SetToOrange ( self
):
161 self
. mg
. SetGesturePen ( wx
. Colour ( 255 , 156 , 0 ), 5 )
162 self
. log
. WriteText ( 'Set Gesture Colour to Orange' )
164 def ShowSomethingClever ( self
, somethingclever
):
165 d
= wx
. MessageDialog ( self
, somethingclever
, 'Mouse Gesture Action' , wx
. OK
)
169 #----------------------------------------------------------------------
171 def runTest ( frame
, nb
, log
):
172 win
= TestPanel ( nb
, log
)
175 #----------------------------------------------------------------------
181 This demo shows how to add MouseGestures
182 to your program, and showcases the MouseGestures
183 class in all it's mousey glory.
190 if __name__
== '__main__' :
193 run
. main ([ '' , os
. path
. basename ( sys
. argv
[ 0 ])] + sys
. argv
[ 1 :])