]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDB.py
Expose SetClippingRegion(point, size)
[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.SetClippingRect(rect)
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),
97 (6 * self.cellWidth, self.textHeight))
98
99 dc.EndDrawing()
100
101
102 # On wxGTK there needs to be a panel under wxScrolledWindows if they are
103 # going to be in a wxNotebook...
104 class TestPanel(wxPanel):
105 def __init__(self, parent):
106 wxPanel.__init__(self, parent, -1)
107 self.win = TestWindow(self)
108 EVT_SIZE(self, self.OnSize)
109
110 def OnSize(self, evt):
111 self.win.SetSize(evt.GetSize())
112
113
114
115 #----------------------------------------------------------------------
116
117
118 def runTest(frame, nb, log):
119 # This loads a whole bunch of new color names and values
120 # into wxTheColourDatabase
121 colourdb.updateColourDB()
122
123 win = TestPanel(nb)
124 return win
125
126 #----------------------------------------------------------------------
127
128 overview = """
129 """
130
131
132 if __name__ == '__main__':
133 import sys,os
134 import run
135 run.main(['', os.path.basename(sys.argv[0])])
136