]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | from wxPython.wx import * | |
3 | from wxPython.lib import colourdb | |
4 | ||
5 | import images | |
6 | ||
7 | ||
8 | # This loads a whole bunch of new color names and values | |
9 | # into wxTheColourDatabase | |
10 | ||
11 | colourdb.updateColourDB() | |
12 | ||
13 | #---------------------------------------------------------------------- | |
14 | ||
15 | class TestWindow(wxScrolledWindow): | |
16 | def __init__(self, parent): | |
17 | wxScrolledWindow.__init__(self, parent, -1) | |
18 | ||
19 | self.clrList = colourdb.getColourList() | |
20 | #self.clrList.sort() | |
21 | self.bg_bmp = images.getGridBGBitmap() | |
22 | ||
23 | EVT_PAINT(self, self.OnPaint) | |
24 | EVT_ERASE_BACKGROUND(self, self.OnEraseBackground) | |
25 | #self.SetBackgroundColour("WHITE") | |
26 | ||
27 | self.font = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL) | |
28 | dc = wxClientDC(self) | |
29 | dc.SetFont(self.font) | |
30 | ||
31 | w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that decends | |
32 | self.textHeight = h + d | |
33 | self.lineHeight = self.textHeight + 5 | |
34 | self.cellWidth = w | |
35 | ||
36 | numCells = 24 | |
37 | self.SetScrollbars(self.cellWidth, self.lineHeight, numCells, len(self.clrList) + 2) | |
38 | ||
39 | ||
40 | def TileBackground(self, dc): | |
41 | # tile the background bitmap | |
42 | sz = self.GetClientSize() | |
43 | w = self.bg_bmp.GetWidth() | |
44 | h = self.bg_bmp.GetHeight() | |
45 | ||
46 | # adjust for scrolled position | |
47 | spx, spy = self.GetScrollPixelsPerUnit() | |
48 | vsx, vsy = self.GetViewStart() | |
49 | dx, dy = (spx * vsx) % w, (spy * vsy) % h | |
50 | ||
51 | x = -dx | |
52 | while x < sz.width: | |
53 | y = -dy | |
54 | while y < sz.height: | |
55 | dc.DrawBitmap(self.bg_bmp, x, y) | |
56 | y = y + h | |
57 | x = x + w | |
58 | ||
59 | ||
60 | def OnEraseBackground(self, evt): | |
61 | dc = evt.GetDC() | |
62 | if not dc: | |
63 | dc = wxClientDC(self) | |
64 | rect = self.GetUpdateRegion().GetBox() | |
65 | dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height) | |
66 | self.TileBackground(dc) | |
67 | ||
68 | ||
69 | def OnPaint(self, evt): | |
70 | dc = wxPaintDC(self) | |
71 | self.PrepareDC(dc) | |
72 | self.Draw(dc, self.GetUpdateRegion(), self.GetViewStart()) | |
73 | ||
74 | ||
75 | def Draw(self, dc, rgn=None, vs=None): | |
76 | dc.BeginDrawing() | |
77 | dc.SetTextForeground("BLACK") | |
78 | dc.SetPen(wxPen("BLACK", 1, wxSOLID)) | |
79 | dc.SetFont(self.font) | |
80 | colours = self.clrList | |
81 | numColours = len(colours) | |
82 | ||
83 | if rgn: | |
84 | # determine the subset that has been exposed and needs drawn | |
85 | rect = rgn.GetBox() | |
86 | pixStart = vs[1]*self.lineHeight + rect.y | |
87 | pixStop = pixStart + rect.height | |
88 | start = pixStart / self.lineHeight - 1 | |
89 | stop = pixStop / self.lineHeight | |
90 | else: | |
91 | start = 0 | |
92 | stop = numColours | |
93 | ||
94 | for line in range(max(0,start), min(stop,numColours)): | |
95 | clr = colours[line] | |
96 | y = (line+1) * self.lineHeight + 2 | |
97 | dc.DrawText(clr, self.cellWidth, y) | |
98 | ||
99 | brush = wxBrush(clr, wxSOLID) | |
100 | dc.SetBrush(brush) | |
101 | dc.DrawRectangle(12 * self.cellWidth, y, 6 * self.cellWidth, self.textHeight) | |
102 | ||
103 | dc.EndDrawing() | |
104 | ||
105 | ||
106 | # On wxGTK there needs to be a panel under wxScrolledWindows if they are | |
107 | # going to be in a wxNotebook... | |
108 | class TestPanel(wxPanel): | |
109 | def __init__(self, parent): | |
110 | wxPanel.__init__(self, parent, -1) | |
111 | self.win = TestWindow(self) | |
112 | EVT_SIZE(self, self.OnSize) | |
113 | ||
114 | def OnSize(self, evt): | |
115 | self.win.SetSize(evt.GetSize()) | |
116 | ||
117 | ||
118 | ||
119 | #---------------------------------------------------------------------- | |
120 | ||
121 | ||
122 | def runTest(frame, nb, log): | |
123 | win = TestPanel(nb) | |
124 | return win | |
125 | ||
126 | #---------------------------------------------------------------------- | |
127 | ||
128 | overview = """ | |
129 | """ |