]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GetMouseState.py
4 #----------------------------------------------------------------------
6 class StaticText(wx
.StaticText
):
8 A StaticText that only updates the label if it has changed, to
9 help reduce potential flicker since these controls would be
10 updated very frequently otherwise.
12 def SetLabel(self
, label
):
13 if label
<> self
.GetLabel():
14 wx
.StaticText
.SetLabel(self
, label
)
16 #----------------------------------------------------------------------
18 class TestPanel(wx
.Panel
):
19 def __init__(self
, parent
, log
):
21 wx
.Panel
.__init
__(self
, parent
, -1)
23 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
26 sizer
.Add(wx
.StaticText(
28 "Mouse and modifier state can be polled with wx.GetMouseState"),
29 0, wx
.CENTER|wx
.ALL
, 10)
30 sizer
.Add(wx
.StaticLine(self
), 0, wx
.EXPAND|wx
.TOP
, 10)
32 row
= wx
.BoxSizer(wx
.HORIZONTAL
)
33 sizer
.Add(row
, 0, wx
.CENTER
)
35 fgs
= wx
.FlexGridSizer(cols
=2, hgap
=5, vgap
=10)
36 row
.Add(fgs
, 0, wx
.ALL
, 30)
38 lbl
= StaticText(self
, -1, "X pos:")
39 self
.x
= StaticText(self
, -1, "00000")
43 lbl
= StaticText(self
, -1, "Y pos:")
44 self
.y
= StaticText(self
, -1, "00000")
49 lbl
= StaticText(self
, -1, "Left down:")
50 self
.lft
= StaticText(self
, -1, "False")
54 lbl
= StaticText(self
, -1, "Middle Down:")
55 self
.mid
= StaticText(self
, -1, "False")
59 lbl
= StaticText(self
, -1, "Right down:")
60 self
.rgt
= StaticText(self
, -1, "False")
64 fgs
= wx
.FlexGridSizer(cols
=2, hgap
=5, vgap
=10)
65 row
.Add(fgs
, 0, wx
.ALL
, 30)
67 lbl
= StaticText(self
, -1, "Control down:")
68 self
.ctrl
= StaticText(self
, -1, "False")
72 lbl
= StaticText(self
, -1, "Shift down:")
73 self
.shft
= StaticText(self
, -1, "False")
77 lbl
= StaticText(self
, -1, "Alt down:")
78 self
.alt
= StaticText(self
, -1, "False")
82 lbl
= StaticText(self
, -1, "Meta down:")
83 self
.meta
= StaticText(self
, -1, "False")
87 lbl
= StaticText(self
, -1, "Cmd down:")
88 self
.cmd
= StaticText(self
, -1, "False")
92 self
.timer
= wx
.Timer(self
)
93 self
.Bind(wx
.EVT_TIMER
, self
.OnTimer
, self
.timer
)
97 def OnTimer(self
, evt
):
98 ms
= wx
.GetMouseState()
99 self
.x
.SetLabel( str(ms
.x
) )
100 self
.y
.SetLabel( str(ms
.y
) )
102 self
.lft
.SetLabel( str(ms
.leftDown
) )
103 self
.mid
.SetLabel( str(ms
.middleDown
) )
104 self
.rgt
.SetLabel( str(ms
.rightDown
) )
106 self
.ctrl
.SetLabel( str(ms
.controlDown
) )
107 self
.shft
.SetLabel( str(ms
.shiftDown
) )
108 self
.alt
.SetLabel( str(ms
.altDown
) )
109 self
.meta
.SetLabel( str(ms
.metaDown
) )
110 self
.cmd
.SetLabel( str(ms
.cmdDown
) )
113 #----------------------------------------------------------------------
115 def runTest(frame
, nb
, log
):
116 win
= TestPanel(nb
, log
)
119 #----------------------------------------------------------------------
123 overview
= """<html><body>
124 <h2><center>wx.GetMouseState</center></h2>
126 The mouse and modifier state can be polled with the wx.GetMouseState
127 function. It returns an instance of a wx.MouseState object that
128 contains the current position of the mouse pointer in screen
129 coordinates, as well as boolean values indicating the up/down status
130 of the mouse buttons and the modifier keys.
138 if __name__
== '__main__':
141 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])