]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxScrolledWindow.py
removed some test code that accidentally was left in
[wxWidgets.git] / utils / wxPython / demo / wxScrolledWindow.py
1
2 from wxPython.wx import *
3
4 #---------------------------------------------------------------------------
5
6 class MyCanvas(wxScrolledWindow):
7 def __init__(self, parent, id = -1, size = wxDefaultSize):
8 wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
9
10 self.lines = []
11 self.maxWidth = 1000
12 self.maxHeight = 1000
13
14 self.SetBackgroundColour(wxNamedColor("WHITE"))
15 self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftButtonEvent)
16 self.Connect(-1, -1, wxEVT_LEFT_UP, self.OnLeftButtonEvent)
17 self.Connect(-1, -1, wxEVT_MOTION, self.OnLeftButtonEvent)
18
19 self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
20 bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
21 self.bmp = bmp
22
23 self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
24
25 def getWidth(self):
26 return self.maxWidth
27
28 def getHeight(self):
29 return self.maxHeight
30
31
32 def OnPaint(self, event):
33 dc = wxPaintDC(self)
34 self.PrepareDC(dc)
35 self.DoDrawing(dc)
36
37
38 def DoDrawing(self, dc):
39 dc.BeginDrawing()
40 pen1 = wxPen(wxNamedColour('RED'))
41 dc.SetPen(pen1)
42 dc.DrawRectangle(5, 5, 50, 50)
43
44 dc.SetBrush(wxLIGHT_GREY_BRUSH)
45 dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
46 dc.DrawRectangle(15, 15, 50, 50)
47
48 font = wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)
49 dc.SetFont(font)
50 dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
51 te = dc.GetTextExtent("Hello World")
52 dc.DrawText("Hello World", 60, 65)
53
54 dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
55 dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
56
57 lst = [(100,110), (150,110), (150,160), (100,160)]
58 dc.DrawLines(lst, -60)
59 dc.SetPen(wxGREY_PEN)
60 dc.DrawPolygon(lst, 75)
61 dc.SetPen(wxGREEN_PEN)
62 dc.DrawSpline(lst+[(100,100)])
63
64 dc.DrawBitmap(self.bmp, 200, 20)
65 dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
66 dc.DrawText("a bitmap", 200, 85)
67
68 self.DrawSavedLines(dc)
69 dc.EndDrawing()
70
71
72 def DrawSavedLines(self, dc):
73 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
74 for line in self.lines:
75 for coords in line:
76 apply(dc.DrawLine, coords)
77
78
79 def SetXY(self, event):
80 self.x, self.y = self.ConvertEventCoords(event)
81
82 def ConvertEventCoords(self, event):
83 xView, yView = self.ViewStart()
84 xDelta, yDelta = self.GetScrollPixelsPerUnit()
85 return (event.GetX() + (xView * xDelta),
86 event.GetY() + (yView * yDelta))
87
88 def OnLeftButtonEvent(self, event):
89 if event.LeftDown():
90 self.SetXY(event)
91 self.curLine = []
92
93 elif event.Dragging():
94 dc = wxClientDC(self)
95 self.PrepareDC(dc)
96 dc.BeginDrawing()
97 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
98 coords = (self.x, self.y) + self.ConvertEventCoords(event)
99 self.curLine.append(coords)
100 apply(dc.DrawLine, coords)
101 self.SetXY(event)
102 dc.EndDrawing()
103
104 elif event.LeftUp():
105 self.lines.append(self.curLine)
106 self.curLine = []
107
108 #---------------------------------------------------------------------------
109
110 def runTest(frame, nb, log):
111 win = MyCanvas(nb)
112 return win
113
114 #---------------------------------------------------------------------------
115
116
117
118
119
120
121
122
123
124
125
126
127
128 overview = """\
129 """