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