]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Cursor.py
Some tweaks to the temporary art images, added wxART_NEW
[wxWidgets.git] / wxPython / demo / Cursor.py
1
2 import wx
3 import images
4
5 #----------------------------------------------------------------------
6
7 CUSTOMID = 1111
8
9 cursors = {
10 "wx.CURSOR_ARROW" : wx.CURSOR_ARROW,
11 "wx.CURSOR_RIGHT_ARROW" : wx.CURSOR_RIGHT_ARROW,
12 "wx.CURSOR_BULLSEYE" : wx.CURSOR_BULLSEYE,
13 "wx.CURSOR_CHAR" : wx.CURSOR_CHAR,
14 "wx.CURSOR_CROSS" : wx.CURSOR_CROSS,
15 "wx.CURSOR_HAND" : wx.CURSOR_HAND,
16 "wx.CURSOR_IBEAM" : wx.CURSOR_IBEAM,
17 "wx.CURSOR_LEFT_BUTTON" : wx.CURSOR_LEFT_BUTTON,
18 "wx.CURSOR_MAGNIFIER" : wx.CURSOR_MAGNIFIER,
19 "wx.CURSOR_MIDDLE_BUTTON" : wx.CURSOR_MIDDLE_BUTTON,
20 "wx.CURSOR_NO_ENTRY" : wx.CURSOR_NO_ENTRY,
21 "wx.CURSOR_PAINT_BRUSH" : wx.CURSOR_PAINT_BRUSH,
22 "wx.CURSOR_PENCIL" : wx.CURSOR_PENCIL,
23 "wx.CURSOR_POINT_LEFT" : wx.CURSOR_POINT_LEFT,
24 "wx.CURSOR_POINT_RIGHT" : wx.CURSOR_POINT_RIGHT,
25 "wx.CURSOR_QUESTION_ARROW" : wx.CURSOR_QUESTION_ARROW,
26 "wx.CURSOR_RIGHT_BUTTON" : wx.CURSOR_RIGHT_BUTTON,
27 "wx.CURSOR_SIZENESW" : wx.CURSOR_SIZENESW,
28 "wx.CURSOR_SIZENS" : wx.CURSOR_SIZENS,
29 "wx.CURSOR_SIZENWSE" : wx.CURSOR_SIZENWSE,
30 "wx.CURSOR_SIZEWE" : wx.CURSOR_SIZEWE,
31 "wx.CURSOR_SIZING" : wx.CURSOR_SIZING,
32 "wx.CURSOR_SPRAYCAN" : wx.CURSOR_SPRAYCAN,
33 "wx.CURSOR_WAIT" : wx.CURSOR_WAIT,
34 "wx.CURSOR_WATCH" : wx.CURSOR_WATCH,
35 "wx.CURSOR_BLANK" : wx.CURSOR_BLANK,
36 "wx.CURSOR_DEFAULT" : wx.CURSOR_DEFAULT,
37 "wx.CURSOR_COPY_ARROW" : wx.CURSOR_COPY_ARROW,
38 "wx.CURSOR_ARROWWAIT" : wx.CURSOR_ARROWWAIT,
39
40 "zz [custom cursor]" : CUSTOMID,
41 }
42
43
44 class TestPanel(wx.Panel):
45 def __init__(self, parent, log):
46 self.log = log
47 wx.Panel.__init__(self, parent, -1)
48
49 # create a list of choices from the dictionary above
50 choices = cursors.keys()
51 choices.sort()
52
53 # create the controls
54 self.cb = wx.ComboBox(self, -1, "wx.CURSOR_DEFAULT", choices=choices,
55 style=wx.CB_READONLY)
56 self.tx = wx.StaticText(self, -1,
57 "This sample allows you to see all the stock cursors \n"
58 "available to wxPython. Simply select a name from the \n"
59 "wx.Choice and then move the mouse into the window \n"
60 "below to see the cursor. NOTE: not all stock cursors \n"
61 "have a specific representaion on all platforms.")
62
63 self.win = wx.Window(self, -1, size=(200,200), style=wx.SIMPLE_BORDER)
64 self.win.SetBackgroundColour("white")
65
66 # bind an event or two
67 self.Bind(wx.EVT_COMBOBOX, self.OnChooseCursor, self.cb)
68 self.win.Bind(wx.EVT_LEFT_DOWN, self.OnDrawDot)
69
70
71 # Setup the layout
72 gbs = wx.GridBagSizer()
73 gbs.Add(self.cb, (2,1))
74 gbs.Add(self.tx, (2,3))
75 gbs.Add(self.win, (5,0), (1, 6), wx.ALIGN_CENTER)
76 self.SetSizer(gbs)
77
78
79 def OnChooseCursor(self, evt):
80 # clear the dots
81 self.win.Refresh()
82
83 choice = evt.GetString() #self.cb.GetStringSelection()
84 self.log.write("Selecting the %s cursor\n" % choice)
85
86 cnum = cursors[choice]
87
88 if cnum == CUSTOMID:
89 image = images.getPointyImage()
90
91 # since this image didn't come from a .cur file, tell it where the hotspot is
92 image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 1)
93 image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 1)
94
95 # make the image into a cursor
96 cursor = wx.CursorFromImage(image)
97
98 else:
99 # create one of the stock (built-in) cursors
100 cursor = wx.StockCursor(cnum)
101
102 # set the cursor for the window
103 self.win.SetCursor(cursor)
104
105
106 def OnDrawDot(self, evt):
107 # Draw a dot so the user can see where the hotspot is
108 dc = wx.ClientDC(self.win)
109 dc.SetPen(wx.Pen("RED"))
110 dc.SetBrush(wx.Brush("RED"))
111 pos = evt.GetPosition()
112 dc.DrawCircle(pos.x, pos.y, 4)
113
114
115 #----------------------------------------------------------------------
116
117 def runTest(frame, nb, log):
118 win = TestPanel(nb, log)
119 return win
120
121 #----------------------------------------------------------------------
122
123
124
125 overview = """<html><body>
126 <h2><center>wx.Cursor</center></h2>
127
128 This demo shows the stock mouse cursors that are available to wxPython.
129
130 </body></html>
131 """
132
133
134
135 if __name__ == '__main__':
136 import sys,os
137 import run
138 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
139