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