File: GetMouseState.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (158 lines) | stat: -rw-r--r-- 4,605 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

import wx

#----------------------------------------------------------------------

class StaticText(wx.StaticText):
    """
    A StaticText that only updates the label if it has changed, to
    help reduce potential flicker since these controls would be
    updated very frequently otherwise.
    """
    def SetLabel(self, label):
        if label <> self.GetLabel():
            wx.StaticText.SetLabel(self, label)

#----------------------------------------------------------------------

class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        sizer.Add((25,25))
        sizer.Add(wx.StaticText(
                      self, -1,
                      "Mouse and modifier state can be polled with wx.GetMouseState"),
                  0, wx.CENTER|wx.ALL, 10)
        sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.TOP, 10)
        
        row = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(row, 0, wx.CENTER)

        fgs = wx.FlexGridSizer(cols=2, hgap=5, vgap=10)
        row.Add(fgs, 0, wx.ALL, 30)

        lbl = StaticText(self, -1, "X pos:")
        self.x = StaticText(self, -1, "00000")
        fgs.Add(lbl)
        fgs.Add(self.x)

        lbl = StaticText(self, -1, "Y pos:")
        self.y = StaticText(self, -1, "00000")
        fgs.Add(lbl)
        fgs.Add(self.y)


        lbl = StaticText(self, -1, "Left down:")
        self.lft = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.lft)

        lbl = StaticText(self, -1, "Middle down:")
        self.mid = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.mid)

        lbl = StaticText(self, -1, "Right down:")
        self.rgt = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.rgt)

        lbl = StaticText(self, -1, "AUX1 down:")
        self.aux1 = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.aux1)

        lbl = StaticText(self, -1, "AUX2 down:")
        self.aux2 = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.aux2)

        fgs = wx.FlexGridSizer(cols=2, hgap=5, vgap=10)
        row.Add(fgs, 0, wx.ALL, 30)

        lbl = StaticText(self, -1, "Control down:")
        self.ctrl = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.ctrl)

        lbl = StaticText(self, -1, "Shift down:")
        self.shft = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.shft)

        lbl = StaticText(self, -1, "Alt down:")
        self.alt = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.alt)

        lbl = StaticText(self, -1, "Meta down:")
        self.meta = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.meta)

        lbl = StaticText(self, -1, "Cmd down:")
        self.cmd = StaticText(self, -1, "False")
        fgs.Add(lbl)
        fgs.Add(self.cmd)
        
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(100)


    def OnTimer(self, evt):
        ms = wx.GetMouseState()
        self.x.SetLabel( str(ms.x) )
        self.y.SetLabel( str(ms.y) )
        
        self.lft.SetLabel( str(ms.leftIsDown) )
        self.mid.SetLabel( str(ms.middleIsDown) )
        self.rgt.SetLabel( str(ms.rightIsDown) )
        self.aux1.SetLabel( str(ms.aux1IsDown) )
        self.aux2.SetLabel( str(ms.aux2IsDown) )

        self.ctrl.SetLabel( str(ms.controlDown) )
        self.shft.SetLabel( str(ms.shiftDown) )
        self.alt.SetLabel( str(ms.altDown) )
        self.meta.SetLabel( str(ms.metaDown) )
        self.cmd.SetLabel( str(ms.cmdDown) )


    def ShutdownDemo(self):
        self.timer.Stop()
        del self.timer
        
#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------



overview = """<html><body>
<h2><center>wx.GetMouseState</center></h2>

The mouse and modifier state can be polled with the wx.GetMouseState
function.  It returns an instance of a wx.MouseState object that
contains the current position of the mouse pointer in screen
coordinates, as well as boolean values indicating the up/down status
of the mouse buttons and the modifier keys.


</body></html>
"""



if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])