]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Cursor.py
Patch #930307, really exit if wrong python on the mac
[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 = 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.getBlom12Image()
90 image.SetMaskColour(255, 255, 255)
91
92 # since this image didn't come from a .cur file, tell it where the hotspot is
93 image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 0)
94 image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 22)
95
96 # make the image into a cursor
97 cursor = wx.CursorFromImage(image)
98
99 else:
100 # create one of the stock (built-in) cursors
101 cursor = wx.StockCursor(cnum)
102
103 # set the cursor for the window
104 self.win.SetCursor(cursor)
105
106
107 def OnDrawDot(self, evt):
108 # Draw a dot so the user can see where the hotspot is
109 dc = wx.ClientDC(self.win)
110 dc.SetPen(wx.Pen("RED"))
111 dc.SetBrush(wx.Brush("RED"))
112 pos = evt.GetPosition()
113 dc.DrawCircle(pos.x, pos.y, 4)
114
115
116 #----------------------------------------------------------------------
117
118 def runTest(frame, nb, log):
119 win = TestPanel(nb, log)
120 return win
121
122 #----------------------------------------------------------------------
123
124
125
126 overview = """<html><body>
127 <h2><center>wx.Cursor</center></h2>
128
129 This demo shows the stock mouse cursors that are available to wxPython.
130
131 </body></html>
132 """
133
134
135
136 if __name__ == '__main__':
137 import sys,os
138 import run
139 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
140