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