Added a demo to show off all the colours that can be added to

wxTheColourDatabase by the wxPython.lib.colourdb module.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9801 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2001-04-19 23:32:05 +00:00
parent 6057972be4
commit c8ace611be
5 changed files with 138 additions and 1 deletions

114
wxPython/demo/ColourDB.py Normal file
View File

@ -0,0 +1,114 @@
from wxPython.wx import *
from wxPython.lib import colourdb
import images
# This loads a whole bunch of new color names and values
# into wxTheColourDatabase
colourdb.updateColourDB()
#----------------------------------------------------------------------
class TestWindow(wxScrolledWindow):
def __init__(self, parent):
wxScrolledWindow.__init__(self, parent, -1)
self.clrList = colourdb.getColourList()
self.bg_bmp = images.getGridBGBitmap()
EVT_PAINT(self, self.OnPaint)
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
#self.SetBackgroundColour("WHITE")
self.font = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL)
dc = wxClientDC(self)
dc.SetFont(self.font)
w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that decends
self.textHeight = h + d
self.lineHeight = self.textHeight + 5
self.cellWidth = w
numCells = 24
self.SetScrollbars(self.cellWidth, self.lineHeight, numCells, len(self.clrList) + 2)
def TileBackground(self, dc):
# tile the background bitmap
sz = self.GetClientSize()
w = self.bg_bmp.GetWidth()
h = self.bg_bmp.GetHeight()
# adjust for scrolled position
spx, spy = self.GetScrollPixelsPerUnit()
vsx, vsy = self.GetViewStart()
dx, dy = (spx * vsx) % w, (spy * vsy) % h
x = -dx
while x < sz.width:
y = -dy
while y < sz.height:
dc.DrawBitmap(self.bg_bmp, x, y)
y = y + h
x = x + w
def OnEraseBackground(self, evt):
dc = evt.GetDC()
if not dc:
dc = wxClientDC(self)
self.TileBackground(dc)
def OnPaint(self, evt):
dc = wxPaintDC(self)
self.PrepareDC(dc)
self.Draw(dc, self.GetUpdateRegion(), self.GetViewStart())
def Draw(self, dc, rgn=None, vs=None):
dc.BeginDrawing()
dc.SetTextForeground("BLACK")
dc.SetPen(wxPen("BLACK", 1, wxSOLID))
dc.SetFont(self.font)
colours = self.clrList
numColours = len(colours)
if rgn:
# determine the subset that have been exposed and needs drawn
rect = rgn.GetBox()
pixStart = vs[1]*self.lineHeight + rect.y
pixStop = pixStart + rect.height
start = pixStart / self.lineHeight - 1
stop = pixStop / self.lineHeight
else:
start = 0
stop = len(numColours)
for line in range(max(0,start), min(stop,numColours)):
clr = colours[line]
y = (line+1) * self.lineHeight + 2
dc.DrawText(clr, self.cellWidth, y)
brush = wxBrush(clr, wxSOLID)
dc.SetBrush(brush)
dc.DrawRectangle(12 * self.cellWidth, y, 6 * self.cellWidth, self.textHeight)
dc.EndDrawing()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestWindow(nb)
return win
#----------------------------------------------------------------------
overview = """
"""

View File

@ -23,6 +23,7 @@ import images
_treeList = [
('New since last release', ['ColourSelect', 'ImageBrowser', 'infoframe',
'ColourDB',
]),
('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

View File

@ -46,7 +46,8 @@ command_lines = [
"-a -n Smiles bmp_source/smiles.bmp images.py",
#"-a -n bmp_source/ images.py",
"-a -n GridBG bmp_source/GridBG.gif images.py",
]

View File

@ -5183,3 +5183,24 @@ def getSmilesBitmap():
def getSmilesImage():
return wxImageFromBitmap(getSmilesBitmap())
#----------------------------------------------------------------------
def getGridBGData():
return cPickle.loads(zlib.decompress(
"x\332\355\230\301\012\2030\014\206\357>Ea\007\007\202\2648e}\012\017^<\354\
\222Nv\032\270\367?mD{pd\222\035\252\006\022\204\300o\373\265\2054M{~\276\\\
\326\345\327\213\371|\215qy\006]nn\326\271\2739\371\032\032\030P*g\011\352P\
\005\217R\037%\013\217P\2434\306\216\003\014\241B\251\215\222\007\037,JE\354\
\350\202\015\3154b\002\233\300%\232\351\321\242\033\321\276D\266S\260xp\262p\
k\3218S]\266\234\035\265`\005\213\007'\0137rr\344\256Y\272\002\215\024\025,\
\036\274m\270\361\035\265k\024,\036\274m\270\221\251\227]\023(X<8Y\270\221y\
\225\237\244\177\037\377\012\026\014\336\3630\345_u\246\226\012\026\017N\035\
n\214\372\222\221\262\211D\257`\211\340\003\324nk\227\233\305\202\025,\036|\
\200w7\366j\024,\036\274Qv[\011\373\177\037\246\025,\030\274g\355\266\266k\
\250\177\012\226\015.\337F\021\023\224" ))
def getGridBGBitmap():
return wxBitmapFromXPMData(getGridBGData())
def getGridBGImage():
return wxImageFromBitmap(getGridBGBitmap())