]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/OwnerDrawnComboBox.py
   5 #---------------------------------------------------------------------- 
   6 # This ComboBox class graphically displays the various pen styles that 
   7 # are available, making it easy for the user to choose the style they 
  10 class PenStyleComboBox(wx
.combo
.OwnerDrawnComboBox
): 
  12     # Overridden from OwnerDrawnComboBox, called to draw each 
  14     def OnDrawItem(self
, dc
, rect
, item
, flags
): 
  15         if item 
== wx
.NOT_FOUND
: 
  16             # painting the control, but there is no valid item selected yet 
  19         r 
= wx
.Rect(*rect
)  # make a copy 
  24             penStyle 
= wx
.TRANSPARENT
 
  28             penStyle 
= wx
.LONG_DASH
 
  30             penStyle 
= wx
.SHORT_DASH
 
  32             penStyle 
= wx
.DOT_DASH
 
  34             penStyle 
= wx
.BDIAGONAL_HATCH
 
  36             penStyle 
= wx
.CROSSDIAG_HATCH
 
  38             penStyle 
= wx
.FDIAGONAL_HATCH
 
  40             penStyle 
= wx
.CROSS_HATCH
 
  42             penStyle 
= wx
.HORIZONTAL_HATCH
 
  44             penStyle 
= wx
.VERTICAL_HATCH
 
  46         pen 
= wx
.Pen(dc
.GetTextForeground(), 3, penStyle
) 
  49         if flags 
& wx
.combo
.ODCB_PAINTING_CONTROL
: 
  50            # for painting the control itself 
  51            dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width 
- 5, r
.y
+r
.height
/2 ) 
  54             # for painting the items in the popup 
  55             dc
.DrawText(self
.GetString( item 
), 
  57                         (r
.y 
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2 
  59             dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3)+1, r
.x
+r
.width 
- 5, r
.y
+((r
.height
/4)*3)+1 ) 
  62     # Overridden from OwnerDrawnComboBox, called for drawing the 
  63     # background area of each item. 
  64     def OnDrawBackground(self
, dc
, rect
, item
, flags
): 
  65         # If the item is selected, or its item # iseven, or we are painting the 
  66         # combo control itself, then use the default rendering. 
  67         if (item 
& 1 == 0 or flags 
& (wx
.combo
.ODCB_PAINTING_CONTROL |
 
  68                                       wx
.combo
.ODCB_PAINTING_SELECTED
)): 
  69             wx
.combo
.OwnerDrawnComboBox
.OnDrawBackground(self
, dc
, rect
, item
, flags
) 
  72         # Otherwise, draw every other background with different colour. 
  73         bgCol 
= wx
.Colour(240,240,250) 
  74         dc
.SetBrush(wx
.Brush(bgCol
)) 
  75         dc
.SetPen(wx
.Pen(bgCol
)) 
  76         dc
.DrawRectangleRect(rect
); 
  80     # Overridden from OwnerDrawnComboBox, should return the height 
  81     # needed to display an item in the popup, or -1 for default 
  82     def OnMeasureItem(self
, item
): 
  83         # Simply demonstrate the ability to have variable-height items 
  89     # Overridden from OwnerDrawnComboBox.  Callback for item width, or 
  90     # -1 for default/undetermined 
  91     def OnMeasureItemWidth(self
, item
): 
  92         return -1; # default - will be measured from text width 
  97 #---------------------------------------------------------------------- 
  99 class TestPanel(wx
.Panel
): 
 100     def __init__(self
, parent
, log
): 
 102         wx
.Panel
.__init
__(self
, parent
, -1) 
 111             "Backward Diagonal Hatch", 
 112             "Cross-diagonal Hatch", 
 113             "Forward Diagonal Hatch", 
 119         wx
.StaticText(self
, -1, "Pen Styles:", (20, 20)) 
 120         pscb 
= PenStyleComboBox(self
, choices
=penStyles
, style
=wx
.CB_READONLY
, 
 121                                 pos
=(20,40), size
=(250, -1)) 
 125 #---------------------------------------------------------------------- 
 127 def runTest(frame
, nb
, log
): 
 128     win 
= TestPanel(nb
, log
) 
 131 #---------------------------------------------------------------------- 
 135 overview 
= """<html><body> 
 136 <h2><center>wx.combo.OwnerDrawnComboBox</center></h2> 
 138 wx.combo.OwnerDrawnComboBox is a combobox with owner-drawn list 
 139 items. In essence, it is a wx.combo.ComboCtrl with wx.VListBox popup and 
 140 wx.ControlWithItems interface. 
 147 if __name__ 
== '__main__': 
 150     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])