]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxScrolledWindow.py
compilation fix for recent commit
[wxWidgets.git] / wxPython / demo / wxScrolledWindow.py
CommitLineData
cf694132
RD
1
2from wxPython.wx import *
3
96bfd053
RD
4import images
5
cf694132
RD
6#---------------------------------------------------------------------------
7
8class MyCanvas(wxScrolledWindow):
e166644c
RD
9 def __init__(self, parent, id = -1, size = wxDefaultSize):
10 wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
cf694132
RD
11
12 self.lines = []
bb0054cd
RD
13 self.maxWidth = 1000
14 self.maxHeight = 1000
cf694132
RD
15
16 self.SetBackgroundColour(wxNamedColor("WHITE"))
f6bcfd97
BP
17 EVT_LEFT_DOWN(self, self.OnLeftButtonEvent)
18 EVT_LEFT_UP(self, self.OnLeftButtonEvent)
19 EVT_MOTION(self, self.OnLeftButtonEvent)
f6bcfd97
BP
20 EVT_PAINT(self, self.OnPaint)
21
cf694132 22 self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
96bfd053 23 bmp = images.getTest2Bitmap()
5ed3dab2
RD
24 mask = wxMaskColour(bmp, wxBLUE)
25 bmp.SetMask(mask)
bb0054cd 26 self.bmp = bmp
cf694132 27
bb0054cd
RD
28 self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
29
a3015b16 30
bb0054cd
RD
31 def getWidth(self):
32 return self.maxWidth
33
34 def getHeight(self):
35 return self.maxHeight
cf694132
RD
36
37
38 def OnPaint(self, event):
39 dc = wxPaintDC(self)
40 self.PrepareDC(dc)
41 self.DoDrawing(dc)
42
43
44 def DoDrawing(self, dc):
45 dc.BeginDrawing()
0569df0f 46 dc.SetPen(wxPen(wxNamedColour('RED')))
cf694132
RD
47 dc.DrawRectangle(5, 5, 50, 50)
48
49 dc.SetBrush(wxLIGHT_GREY_BRUSH)
50 dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
51 dc.DrawRectangle(15, 15, 50, 50)
52
0569df0f 53 dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))
cf694132
RD
54 dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
55 te = dc.GetTextExtent("Hello World")
56 dc.DrawText("Hello World", 60, 65)
57
58 dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
59 dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
60
61 lst = [(100,110), (150,110), (150,160), (100,160)]
62 dc.DrawLines(lst, -60)
63 dc.SetPen(wxGREY_PEN)
64 dc.DrawPolygon(lst, 75)
65 dc.SetPen(wxGREEN_PEN)
66 dc.DrawSpline(lst+[(100,100)])
67
5ed3dab2 68 dc.DrawBitmap(self.bmp, 200, 20, true)
bb0054cd
RD
69 dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
70 dc.DrawText("a bitmap", 200, 85)
cf694132 71
6999b0d8
RD
72 font = wxFont(20, wxSWISS, wxNORMAL, wxNORMAL)
73 dc.SetFont(font)
74 dc.SetTextForeground(wxBLACK)
75 for a in range(0, 360, 45):
76 dc.DrawRotatedText("Rotated text...", 300, 300, a)
77
eec92d76
RD
78 dc.SetPen(wxTRANSPARENT_PEN)
79 dc.SetBrush(wxBLUE_BRUSH)
80 dc.DrawRectangle(50,500,50,50)
81 dc.DrawRectangle(100,500,50,50)
82
0569df0f 83 dc.SetPen(wxPen(wxNamedColour('RED')))
c368d904
RD
84 dc.DrawEllipticArc(200, 500, 50, 75, 0, 90)
85
217cb2fa
RD
86 y = 20
87 for style in [wxDOT, wxLONG_DASH, wxSHORT_DASH, wxDOT_DASH, wxUSER_DASH]:
88 pen = wxPen("DARK ORCHID", 1, style)
89 if style == wxUSER_DASH:
05f30eec 90 pen.SetDashes([1, 2, 3, 4, 5, 6, 7, 8])
ecc08ead 91 pen.SetColour("RED")
217cb2fa
RD
92 dc.SetPen(pen)
93 dc.DrawLine(300, y, 400, y)
94 y = y + 10
95
c5943253
RD
96 dc.SetBrush(wxNullBrush)
97 dc.SetPen(wxPen(wxColour(0xFF, 0x20, 0xFF), 1, wxSOLID))
98 dc.DrawRectangle(450, 50, 100, 100)
99 old_pen = dc.GetPen()
100 new_pen = wxPen("BLACK", 5)
101 dc.SetPen(new_pen)
102 dc.DrawRectangle(470, 70, 60, 60)
103 dc.SetPen(old_pen)
104 dc.DrawRectangle(490, 90, 20, 20)
105
106
cf694132
RD
107 self.DrawSavedLines(dc)
108 dc.EndDrawing()
109
110
eec92d76 111
cf694132
RD
112 def DrawSavedLines(self, dc):
113 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
114 for line in self.lines:
115 for coords in line:
116 apply(dc.DrawLine, coords)
117
118
119 def SetXY(self, event):
120 self.x, self.y = self.ConvertEventCoords(event)
121
122 def ConvertEventCoords(self, event):
3ca6a5f0 123 xView, yView = self.GetViewStart()
cf694132
RD
124 xDelta, yDelta = self.GetScrollPixelsPerUnit()
125 return (event.GetX() + (xView * xDelta),
126 event.GetY() + (yView * yDelta))
127
128 def OnLeftButtonEvent(self, event):
129 if event.LeftDown():
130 self.SetXY(event)
131 self.curLine = []
714d23b4 132 self.CaptureMouse()
cf694132
RD
133
134 elif event.Dragging():
135 dc = wxClientDC(self)
136 self.PrepareDC(dc)
137 dc.BeginDrawing()
138 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
139 coords = (self.x, self.y) + self.ConvertEventCoords(event)
140 self.curLine.append(coords)
141 apply(dc.DrawLine, coords)
142 self.SetXY(event)
143 dc.EndDrawing()
144
145 elif event.LeftUp():
146 self.lines.append(self.curLine)
147 self.curLine = []
714d23b4 148 self.ReleaseMouse()
cf694132 149
d1679124
RD
150
151## This is an example of what to do for the EVT_MOUSEWHEEL event,
152## but since wxScrolledWindow does this already it's not
153## necessary to do it ourselves.
154
155## wheelScroll = 0
156## def OnWheel(self, evt):
157## delta = evt.GetWheelDelta()
158## rot = evt.GetWheelRotation()
159## linesPer = evt.GetLinesPerAction()
160## ws = self.wheelScroll
161## ws = ws + rot
162## lines = ws / delta
163## ws = ws - lines * delta
164## self.wheelScroll = ws
165## if lines != 0:
166## lines = lines * linesPer
167## vsx, vsy = self.GetViewStart()
168## scrollTo = vsy - lines
169## self.Scroll(-1, scrollTo)
170
cf694132
RD
171#---------------------------------------------------------------------------
172
173def runTest(frame, nb, log):
174 win = MyCanvas(nb)
175 return win
176
177#---------------------------------------------------------------------------
178
179
180
181
182
183
184
185
186
187
188
189
190
191overview = """\
192"""