]>
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 rect
= self
.GetUpdateRegion().GetBox()
64 dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
)
65 self
.TileBackground(dc
)
68 def OnPaint(self
, evt
):
71 self
.Draw(dc
, self
.GetUpdateRegion(), self
.GetViewStart())
74 def Draw(self
, dc
, rgn
=None, vs
=None):
76 dc
.SetTextForeground("BLACK")
77 dc
.SetPen(wxPen("BLACK", 1, wxSOLID
))
79 colours
= self
.clrList
80 numColours
= len(colours
)
83 # determine the subset that has been exposed and needs drawn
85 pixStart
= vs
[1]*self
.lineHeight
+ rect
.y
86 pixStop
= pixStart
+ rect
.height
87 start
= pixStart
/ self
.lineHeight
- 1
88 stop
= pixStop
/ self
.lineHeight
93 for line
in range(max(0,start
), min(stop
,numColours
)):
95 y
= (line
+1) * self
.lineHeight
+ 2
96 dc
.DrawText(clr
, self
.cellWidth
, y
)
98 brush
= wxBrush(clr
, wxSOLID
)
100 dc
.DrawRectangle(12 * self
.cellWidth
, y
, 6 * self
.cellWidth
, self
.textHeight
)
105 # On wxGTK there needs to be a panel under wxScrolledWindows if they are
106 # going to be in a wxNotebook...
107 class TestPanel(wxPanel
):
108 def __init__(self
, parent
):
109 wxPanel
.__init
__(self
, parent
, -1)
110 self
.win
= TestWindow(self
)
111 EVT_SIZE(self
, self
.OnSize
)
113 def OnSize(self
, evt
):
114 self
.win
.SetSize(evt
.GetSize())
118 #----------------------------------------------------------------------
121 def runTest(frame
, nb
, log
):
125 #----------------------------------------------------------------------