]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDB.py
2 from wxPython
.wx
import *
3 from wxPython
.lib
import colourdb
8 # This loads a whole bunch of new color names and values
9 # into wxTheColourDatabase
11 colourdb
.updateColourDB()
13 #----------------------------------------------------------------------
15 class TestWindow(wxScrolledWindow
):
16 def __init__(self
, parent
):
17 wxScrolledWindow
.__init
__(self
, parent
, -1)
19 self
.clrList
= colourdb
.getColourList()
20 self
.bg_bmp
= images
.getGridBGBitmap()
22 EVT_PAINT(self
, self
.OnPaint
)
23 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
24 #self.SetBackgroundColour("WHITE")
26 self
.font
= wxFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
)
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
36 self
.SetScrollbars(self
.cellWidth
, self
.lineHeight
, numCells
, len(self
.clrList
) + 2)
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()
45 # adjust for scrolled position
46 spx
, spy
= self
.GetScrollPixelsPerUnit()
47 vsx
, vsy
= self
.GetViewStart()
48 dx
, dy
= (spx
* vsx
) % w
, (spy
* vsy
) % h
54 dc
.DrawBitmap(self
.bg_bmp
, x
, y
)
59 def OnEraseBackground(self
, evt
):
63 self
.TileBackground(dc
)
66 def OnPaint(self
, evt
):
69 self
.Draw(dc
, self
.GetUpdateRegion(), self
.GetViewStart())
72 def Draw(self
, dc
, rgn
=None, vs
=None):
74 dc
.SetTextForeground("BLACK")
75 dc
.SetPen(wxPen("BLACK", 1, wxSOLID
))
77 colours
= self
.clrList
78 numColours
= len(colours
)
81 # determine the subset that have been exposed and needs drawn
83 pixStart
= vs
[1]*self
.lineHeight
+ rect
.y
84 pixStop
= pixStart
+ rect
.height
85 start
= pixStart
/ self
.lineHeight
- 1
86 stop
= pixStop
/ self
.lineHeight
89 stop
= len(numColours
)
91 for line
in range(max(0,start
), min(stop
,numColours
)):
93 y
= (line
+1) * self
.lineHeight
+ 2
94 dc
.DrawText(clr
, self
.cellWidth
, y
)
96 brush
= wxBrush(clr
, wxSOLID
)
98 dc
.DrawRectangle(12 * self
.cellWidth
, y
, 6 * self
.cellWidth
, self
.textHeight
)
104 #----------------------------------------------------------------------
107 def runTest(frame
, nb
, log
):
111 #----------------------------------------------------------------------