]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDB.py
image sample fix from 2_4
[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 #----------------------------------------------------------------------
9
10 class TestWindow(wxScrolledWindow):
11 def __init__(self, parent):
12 wxScrolledWindow.__init__(self, parent, -1)
13
14 self.clrList = colourdb.getColourList()
15 #self.clrList.sort()
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
26 w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that descends
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)
59 rect = self.GetUpdateRegion().GetBox()
60 dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
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:
79 # determine the subset that has been exposed and needs drawn
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
87 stop = numColours
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
101 # On wxGTK there needs to be a panel under wxScrolledWindows if they are
102 # going to be in a wxNotebook...
103 class 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
113
114 #----------------------------------------------------------------------
115
116
117 def runTest(frame, nb, log):
118 # This loads a whole bunch of new color names and values
119 # into wxTheColourDatabase
120 colourdb.updateColourDB()
121
122 win = TestPanel(nb)
123 return win
124
125 #----------------------------------------------------------------------
126
127 overview = """
128 """
129
130
131 if __name__ == '__main__':
132 import sys,os
133 import run
134 run.main(['', os.path.basename(sys.argv[0])])
135