]>
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() 
  21         self
.bg_bmp 
= images
.getGridBGBitmap() 
  23         EVT_PAINT(self
, self
.OnPaint
) 
  24         EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
) 
  25         #self.SetBackgroundColour("WHITE") 
  27         self
.font 
= wxFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
) 
  31         w
,h
,d
,e 
= dc
.GetFullTextExtent("Wy") # a wide character and one that decends 
  32         self
.textHeight 
= h 
+ d
 
  33         self
.lineHeight 
= self
.textHeight 
+ 5 
  37         self
.SetScrollbars(self
.cellWidth
, self
.lineHeight
, numCells
, len(self
.clrList
) + 2) 
  40     def TileBackground(self
, dc
): 
  41         # tile the background bitmap 
  42         sz 
= self
.GetClientSize() 
  43         w 
= self
.bg_bmp
.GetWidth() 
  44         h 
= self
.bg_bmp
.GetHeight() 
  46         # adjust for scrolled position 
  47         spx
, spy 
= self
.GetScrollPixelsPerUnit() 
  48         vsx
, vsy 
= self
.GetViewStart() 
  49         dx
,  dy  
= (spx 
* vsx
) % w
, (spy 
* vsy
) % h
 
  55                 dc
.DrawBitmap(self
.bg_bmp
, x
, y
) 
  60     def OnEraseBackground(self
, evt
): 
  64             rect 
= self
.GetUpdateRegion().GetBox() 
  65             dc
.SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
) 
  66         self
.TileBackground(dc
) 
  69     def OnPaint(self
, evt
): 
  72         self
.Draw(dc
, self
.GetUpdateRegion(), self
.GetViewStart()) 
  75     def Draw(self
, dc
, rgn
=None, vs
=None): 
  77         dc
.SetTextForeground("BLACK") 
  78         dc
.SetPen(wxPen("BLACK", 1, wxSOLID
)) 
  80         colours 
= self
.clrList
 
  81         numColours 
= len(colours
) 
  84             # determine the subset that has been exposed and needs drawn 
  86             pixStart 
= vs
[1]*self
.lineHeight 
+ rect
.y
 
  87             pixStop  
= pixStart 
+ rect
.height
 
  88             start 
= pixStart 
/ self
.lineHeight 
- 1 
  89             stop 
= pixStop 
/ self
.lineHeight
 
  94         for line 
in range(max(0,start
), min(stop
,numColours
)): 
  96             y 
= (line
+1) * self
.lineHeight 
+ 2 
  97             dc
.DrawText(clr
, self
.cellWidth
, y
) 
  99             brush 
= wxBrush(clr
, wxSOLID
) 
 101             dc
.DrawRectangle(12 * self
.cellWidth
, y
, 6 * self
.cellWidth
, self
.textHeight
) 
 106 # On wxGTK there needs to be a panel under wxScrolledWindows if they are 
 107 # going to be in a wxNotebook... 
 108 class TestPanel(wxPanel
): 
 109     def __init__(self
, parent
): 
 110         wxPanel
.__init
__(self
, parent
, -1) 
 111         self
.win 
= TestWindow(self
) 
 112         EVT_SIZE(self
, self
.OnSize
) 
 114     def OnSize(self
, evt
): 
 115         self
.win
.SetSize(evt
.GetSize()) 
 119 #---------------------------------------------------------------------- 
 122 def runTest(frame
, nb
, log
): 
 126 #----------------------------------------------------------------------