File: Cursor.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 (139 lines) | stat: -rw-r--r-- 4,464 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

import wx
import images

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

CUSTOMID = 1111

cursors = {
    "wx.CURSOR_ARROW" : wx.CURSOR_ARROW,
    "wx.CURSOR_RIGHT_ARROW" : wx.CURSOR_RIGHT_ARROW,
    "wx.CURSOR_BULLSEYE" : wx.CURSOR_BULLSEYE,
    "wx.CURSOR_CHAR" : wx.CURSOR_CHAR,
    "wx.CURSOR_CROSS" : wx.CURSOR_CROSS,
    "wx.CURSOR_HAND" : wx.CURSOR_HAND,
    "wx.CURSOR_IBEAM" : wx.CURSOR_IBEAM,
    "wx.CURSOR_LEFT_BUTTON" : wx.CURSOR_LEFT_BUTTON,
    "wx.CURSOR_MAGNIFIER" : wx.CURSOR_MAGNIFIER,
    "wx.CURSOR_MIDDLE_BUTTON" : wx.CURSOR_MIDDLE_BUTTON,
    "wx.CURSOR_NO_ENTRY" : wx.CURSOR_NO_ENTRY,
    "wx.CURSOR_PAINT_BRUSH" : wx.CURSOR_PAINT_BRUSH,
    "wx.CURSOR_PENCIL" : wx.CURSOR_PENCIL,
    "wx.CURSOR_POINT_LEFT" : wx.CURSOR_POINT_LEFT,
    "wx.CURSOR_POINT_RIGHT" : wx.CURSOR_POINT_RIGHT,
    "wx.CURSOR_QUESTION_ARROW" : wx.CURSOR_QUESTION_ARROW,
    "wx.CURSOR_RIGHT_BUTTON" : wx.CURSOR_RIGHT_BUTTON,
    "wx.CURSOR_SIZENESW" : wx.CURSOR_SIZENESW,
    "wx.CURSOR_SIZENS" : wx.CURSOR_SIZENS,
    "wx.CURSOR_SIZENWSE" : wx.CURSOR_SIZENWSE,
    "wx.CURSOR_SIZEWE" : wx.CURSOR_SIZEWE,
    "wx.CURSOR_SIZING" : wx.CURSOR_SIZING,
    "wx.CURSOR_SPRAYCAN" : wx.CURSOR_SPRAYCAN,
    "wx.CURSOR_WAIT" : wx.CURSOR_WAIT,
    "wx.CURSOR_WATCH" : wx.CURSOR_WATCH,
    "wx.CURSOR_BLANK" : wx.CURSOR_BLANK,
    "wx.CURSOR_DEFAULT" : wx.CURSOR_DEFAULT,
    "wx.CURSOR_COPY_ARROW" : wx.CURSOR_COPY_ARROW,
    "wx.CURSOR_ARROWWAIT" : wx.CURSOR_ARROWWAIT,

    "zz [custom cursor]"  : CUSTOMID,
}


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

        # create a list of choices from the dictionary above
        choices = cursors.keys()
        choices.sort()

        # create the controls
        self.cb = wx.ComboBox(self, -1, "wx.CURSOR_DEFAULT", choices=choices,
                              style=wx.CB_READONLY)
        self.tx = wx.StaticText(self, -1,                                
             "This sample allows you to see all the stock cursors \n"
             "available to wxPython.  Simply select a name from the \n"
             "wx.Choice and then move the mouse into the window \n"
             "below to see the cursor.  NOTE: not all stock cursors \n"
             "have a specific representaion on all platforms.")
        
        self.win = wx.Window(self, -1, size=(200,200), style=wx.SIMPLE_BORDER)
        self.win.SetBackgroundColour("white")

        # bind an event or two
        self.Bind(wx.EVT_COMBOBOX, self.OnChooseCursor, self.cb)
        self.win.Bind(wx.EVT_LEFT_DOWN, self.OnDrawDot)
        

        # Setup the layout
        gbs = wx.GridBagSizer()
        gbs.Add(self.cb, (2,1))
        gbs.Add(self.tx, (2,3))
        gbs.Add(self.win, (5,0), (1, 6), wx.ALIGN_CENTER)
        self.SetSizer(gbs)


    def OnChooseCursor(self, evt):
        # clear the dots
        self.win.Refresh()

        choice = self.cb.GetStringSelection()
        self.log.write("Selecting the %s cursor\n" % choice)

        cnum = cursors[choice]
        
        if cnum == CUSTOMID:
            image = images.Pointy.GetImage()

            # since this image didn't come from a .cur file, tell it where the hotspot is
            image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 1)
            image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 1)

            # make the image into a cursor
            cursor = wx.CursorFromImage(image)

        else:
            # create one of the stock (built-in) cursors
            cursor = wx.StockCursor(cnum)

        # set the cursor for the window
        self.win.SetCursor(cursor)


    def OnDrawDot(self, evt):
        # Draw a dot so the user can see where the hotspot is
        dc = wx.ClientDC(self.win)
        dc.SetPen(wx.Pen("RED"))
        dc.SetBrush(wx.Brush("RED"))
        pos = evt.GetPosition()
        dc.DrawCircle(pos.x, pos.y, 4)
        

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

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

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



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

This demo shows the stock mouse cursors that are available to wxPython.

</body></html>
"""



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