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