]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDB.py
Updated version to 2.3.2 so apps can test for differences in new merged source
[wxWidgets.git] / wxPython / demo / ColourDB.py
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 self.TileBackground(dc)
64
65
66 def OnPaint(self, evt):
67 dc = wxPaintDC(self)
68 self.PrepareDC(dc)
69 self.Draw(dc, self.GetUpdateRegion(), self.GetViewStart())
70
71
72 def Draw(self, dc, rgn=None, vs=None):
73 dc.BeginDrawing()
74 dc.SetTextForeground("BLACK")
75 dc.SetPen(wxPen("BLACK", 1, wxSOLID))
76 dc.SetFont(self.font)
77 colours = self.clrList
78 numColours = len(colours)
79
80 if rgn:
81 # determine the subset that has been exposed and needs drawn
82 rect = rgn.GetBox()
83 pixStart = vs[1]*self.lineHeight + rect.y
84 pixStop = pixStart + rect.height
85 start = pixStart / self.lineHeight - 1
86 stop = pixStop / self.lineHeight
87 else:
88 start = 0
89 stop = len(numColours)
90
91 for line in range(max(0,start), min(stop,numColours)):
92 clr = colours[line]
93 y = (line+1) * self.lineHeight + 2
94 dc.DrawText(clr, self.cellWidth, y)
95
96 brush = wxBrush(clr, wxSOLID)
97 dc.SetBrush(brush)
98 dc.DrawRectangle(12 * self.cellWidth, y, 6 * self.cellWidth, self.textHeight)
99
100 dc.EndDrawing()
101
102
103
104 #----------------------------------------------------------------------
105
106
107 def runTest(frame, nb, log):
108 win = TestWindow(nb)
109 return win
110
111 #----------------------------------------------------------------------
112
113 overview = """
114 """