]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GetMouseState.py
drop highlight color fix
[wxWidgets.git] / wxPython / demo / GetMouseState.py
1
2 import wx
3
4 #----------------------------------------------------------------------
5
6 class StaticText(wx.StaticText):
7 """
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.
11 """
12 def SetLabel(self, label):
13 if label <> self.GetLabel():
14 wx.StaticText.SetLabel(self, label)
15
16 #----------------------------------------------------------------------
17
18 class TestPanel(wx.Panel):
19 def __init__(self, parent, log):
20 self.log = log
21 wx.Panel.__init__(self, parent, -1)
22
23 sizer = wx.BoxSizer(wx.VERTICAL)
24 self.SetSizer(sizer)
25 sizer.Add((25,25))
26 sizer.Add(wx.StaticText(
27 self, -1,
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)
31
32 row = wx.BoxSizer(wx.HORIZONTAL)
33 sizer.Add(row, 0, wx.CENTER)
34
35 fgs = wx.FlexGridSizer(cols=2, hgap=5, vgap=10)
36 row.Add(fgs, 0, wx.ALL, 30)
37
38 lbl = StaticText(self, -1, "X pos:")
39 self.x = StaticText(self, -1, "00000")
40 fgs.Add(lbl)
41 fgs.Add(self.x)
42
43 lbl = StaticText(self, -1, "Y pos:")
44 self.y = StaticText(self, -1, "00000")
45 fgs.Add(lbl)
46 fgs.Add(self.y)
47
48
49 lbl = StaticText(self, -1, "Left down:")
50 self.lft = StaticText(self, -1, "False")
51 fgs.Add(lbl)
52 fgs.Add(self.lft)
53
54 lbl = StaticText(self, -1, "Middle Down:")
55 self.mid = StaticText(self, -1, "False")
56 fgs.Add(lbl)
57 fgs.Add(self.mid)
58
59 lbl = StaticText(self, -1, "Right down:")
60 self.rgt = StaticText(self, -1, "False")
61 fgs.Add(lbl)
62 fgs.Add(self.rgt)
63
64 fgs = wx.FlexGridSizer(cols=2, hgap=5, vgap=10)
65 row.Add(fgs, 0, wx.ALL, 30)
66
67 lbl = StaticText(self, -1, "Control down:")
68 self.ctrl = StaticText(self, -1, "False")
69 fgs.Add(lbl)
70 fgs.Add(self.ctrl)
71
72 lbl = StaticText(self, -1, "Shift down:")
73 self.shft = StaticText(self, -1, "False")
74 fgs.Add(lbl)
75 fgs.Add(self.shft)
76
77 lbl = StaticText(self, -1, "Alt down:")
78 self.alt = StaticText(self, -1, "False")
79 fgs.Add(lbl)
80 fgs.Add(self.alt)
81
82 lbl = StaticText(self, -1, "Meta down:")
83 self.meta = StaticText(self, -1, "False")
84 fgs.Add(lbl)
85 fgs.Add(self.meta)
86
87 lbl = StaticText(self, -1, "Cmd down:")
88 self.cmd = StaticText(self, -1, "False")
89 fgs.Add(lbl)
90 fgs.Add(self.cmd)
91
92 self.timer = wx.Timer(self)
93 self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
94 self.timer.Start(100)
95
96
97 def OnTimer(self, evt):
98 ms = wx.GetMouseState()
99 self.x.SetLabel( str(ms.x) )
100 self.y.SetLabel( str(ms.y) )
101
102 self.lft.SetLabel( str(ms.leftDown) )
103 self.mid.SetLabel( str(ms.middleDown) )
104 self.rgt.SetLabel( str(ms.rightDown) )
105
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) )
111
112
113 def ShutdownDemo(self):
114 self.timer.Stop()
115 del self.timer
116
117 #----------------------------------------------------------------------
118
119 def runTest(frame, nb, log):
120 win = TestPanel(nb, log)
121 return win
122
123 #----------------------------------------------------------------------
124
125
126
127 overview = """<html><body>
128 <h2><center>wx.GetMouseState</center></h2>
129
130 The mouse and modifier state can be polled with the wx.GetMouseState
131 function. It returns an instance of a wx.MouseState object that
132 contains the current position of the mouse pointer in screen
133 coordinates, as well as boolean values indicating the up/down status
134 of the mouse buttons and the modifier keys.
135
136
137 </body></html>
138 """
139
140
141
142 if __name__ == '__main__':
143 import sys,os
144 import run
145 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
146