]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDB.py
2 from wxPython
.wx
import *
3 from wxPython
.lib
import colourdb
8 #----------------------------------------------------------------------
10 class TestWindow(wxScrolledWindow
):
11 def __init__(self
, parent
):
12 wxScrolledWindow
.__init
__(self
, parent
, -1)
14 self
.clrList
= colourdb
.getColourList()
16 self
.bg_bmp
= images
.getGridBGBitmap()
18 EVT_PAINT(self
, self
.OnPaint
)
19 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
20 #self.SetBackgroundColour("WHITE")
22 self
.font
= wxFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
)
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
32 self
.SetScrollbars(self
.cellWidth
, self
.lineHeight
, numCells
, len(self
.clrList
) + 2)
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()
41 # adjust for scrolled position
42 spx
, spy
= self
.GetScrollPixelsPerUnit()
43 vsx
, vsy
= self
.GetViewStart()
44 dx
, dy
= (spx
* vsx
) % w
, (spy
* vsy
) % h
50 dc
.DrawBitmap(self
.bg_bmp
, x
, y
)
55 def OnEraseBackground(self
, evt
):
59 rect
= self
.GetUpdateRegion().GetBox()
60 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
)
61 self
.TileBackground(dc
)
64 def OnPaint(self
, evt
):
67 self
.Draw(dc
, self
.GetUpdateRegion(), self
.GetViewStart())
70 def Draw(self
, dc
, rgn
=None, vs
=None):
72 dc
.SetTextForeground("BLACK")
73 dc
.SetPen(wxPen("BLACK", 1, wxSOLID
))
75 colours
= self
.clrList
76 numColours
= len(colours
)
79 # determine the subset that has been exposed and needs drawn
81 pixStart
= vs
[1]*self
.lineHeight
+ rect
.y
82 pixStop
= pixStart
+ rect
.height
83 start
= pixStart
/ self
.lineHeight
- 1
84 stop
= pixStop
/ self
.lineHeight
89 for line
in range(max(0,start
), min(stop
,numColours
)):
91 y
= (line
+1) * self
.lineHeight
+ 2
92 dc
.DrawText(clr
, self
.cellWidth
, y
)
94 brush
= wxBrush(clr
, wxSOLID
)
96 dc
.DrawRectangle(12 * self
.cellWidth
, y
, 6 * self
.cellWidth
, self
.textHeight
)
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
)
109 def OnSize(self
, evt
):
110 self
.win
.SetSize(evt
.GetSize())
114 #----------------------------------------------------------------------
117 def runTest(frame
, nb
, log
):
118 # This loads a whole bunch of new color names and values
119 # into wxTheColourDatabase
120 colourdb
.updateColourDB()
125 #----------------------------------------------------------------------
131 if __name__
== '__main__':
134 run
.main(['', os
.path
.basename(sys
.argv
[0])])