35     "Panel With Controls", 
  36     "Panel With RadioBox", 
  43 testChoices 
= keyword
.kwlist
 
  45 testChoices2 
= "one two three four five six seven eight nine".split() 
  50 class Frame(wx
.Frame
): 
  52         wx
.Frame
.__init
__(self
, None, title
="Draw Widget Test") 
  53         self
.left 
= wx
.Panel(self
) 
  54         self
.right 
= DisplayPanel(self
) 
  57         sizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
  58         sizer
.Add(self
.left
, 1, wx
.EXPAND
) 
  59         sizer
.Add(self
.right
, 1, wx
.EXPAND
) 
  63         menu
.Append(wx
.ID_EXIT
, "E&xit\tAlt-X") 
  64         self
.Bind(wx
.EVT_MENU
, self
.OnExit
, id=wx
.ID_EXIT
) 
  66         mbar
.Append(menu
, "&File") 
  69         cb 
= wx
.ComboBox(self
.left
, -1, pos
=(20,20), 
  70                          choices
=testItems
, style
=wx
.CB_READONLY
) 
  71         self
.Bind(wx
.EVT_COMBOBOX
, self
.OnWidgetChosen
, cb
) 
  74     def OnWidgetChosen(self
, evt
): 
  75         item 
= evt
.GetString() 
  76         item 
= item
.replace(" ", "_") 
  77         func 
= getattr(self
, "Test"+item
, None) 
  81     def OnExit(self
, evt
): 
  86     def DoWidget(self
, widget
): 
  88         if self
.widget 
is not None: 
  95         hiddenPos 
= (-1000,-1000) 
  97         widget
.SetPosition(visiblePos
) 
  99         self
.GetBMP(0)  # Uses just a DC.Blit, so it must be visible 
 101         # the rest should work when the widget is not visible. 
 102         widget
.SetPosition(hiddenPos
) 
 110         # make it visible again for the user to compare 
 111         widget
.SetPosition(visiblePos
) 
 114     def GetBMP(self
, method
): 
 116         maskClr 
= wx
.Colour(12, 34, 56) 
 118         bmp 
= wx
.EmptyBitmap(sz
.width
, sz
.height
) 
 121         dc
.SetBackground(wx
.Brush(maskClr
)) 
 126             dc
.Blit(0,0, sz
.width
, sz
.height
, wdc
, 0, 0) 
 128             wx
.DrawWindowOnDC(w
, dc
, method
) 
 130         dc
.SelectObject(wx
.NullBitmap
) 
 131         bmp
.SetMaskColour(maskClr
) 
 132         self
.right
.SetBMP(bmp
, method
) 
 141     def TestBitmapButton(self
, p
): 
 142         self
.DoWidget(wx
.BitmapButton(p
, -1, 
 143                                       wx
.Bitmap("image.png"))) 
 144     def TestButton(self
, p
): 
 145         self
.DoWidget(wx
.Button(p
, -1, "A button")) 
 147     def TestCalendarCtrl(self
, p
): 
 149         w 
= wx
.calendar
.CalendarCtrl(p
, style
=wx
.calendar
.CAL_SEQUENTIAL_MONTH_SELECTION
) 
 152     def TestCheckBox(self
, p
): 
 153         self
.DoWidget(wx
.CheckBox(p
, -1, "checkbox")) 
 155     def TestCheckListBox(self
, p
): 
 156         w 
= wx
.CheckListBox(p
, -1, choices
=testChoices
) 
 160     def TestChoice(self
, p
): 
 161         w 
= wx
.Choice(p
, -1, choices
=testChoices
) 
 165     def TestComboBox(self
, p
): 
 166         w 
= wx
.ComboBox(p
, -1, choices
=testChoices
) 
 170     def TestGauge(self
, p
): 
 171         w 
= wx
.Gauge(p
, -1, 100, size
=(150, -1)) 
 175     def TestGenericDirCtrl(self
, p
): 
 176         w 
= wx
.GenericDirCtrl(p
, size
=(150,200), style
=wx
.DIRCTRL_DIR_ONLY
) 
 179     def TestListBox(self
, p
): 
 180         w 
= wx
.ListBox(p
, -1, choices
=testChoices
) 
 184     def TestListCtrl(self
, p
): 
 185         w 
= wx
.ListCtrl(p
, -1, size
=(250, 100), style
=wx
.LC_REPORT
) 
 186         w
.InsertColumn(0, "Col 1") 
 187         w
.InsertColumn(1, "Col 2") 
 188         w
.InsertColumn(2, "Col 3") 
 190             w
.InsertStringItem(x
, str(x
)) 
 191             w
.SetStringItem(x
, 1, str(x
)) 
 192             w
.SetStringItem(x
, 2, str(x
)) 
 195     def TestRadioBox(self
, p
): 
 196         w 
= wx
.RadioBox(p
, -1, "RadioBox", 
 197                         choices
=testChoices2
, majorDimension
=3) 
 200     def TestRadioButton(self
, p
): 
 201         self
.DoWidget(wx
.RadioButton(p
, -1, "RadioButton")) 
 203     def TestScrollBar(self
, p
): 
 204         w 
= wx
.ScrollBar(p
, -1, size
=(150,-1)) 
 205         w
.SetScrollbar(25, 5, 100, 10) 
 208     def TestSlider(self
, p
): 
 209         w 
= wx
.Slider(p
, -1, size
=(150,-1)) 
 212     def TestSpinButton(self
, p
): 
 213         w 
= wx
.SpinButton(p
, -1) 
 216     def TestSpinCtrl(self
, p
): 
 217         w 
= wx
.SpinCtrl(p
, -1) 
 220     def TestStaticBitmap(self
, p
): 
 221         w 
= wx
.StaticBitmap(p
, -1, wx
.Bitmap("image.png")) 
 224     def TestStaticBox(self
, p
): 
 225         w 
= wx
.StaticBox(p
, -1, "StaticBox", size
=(150,75)) 
 228     def TestStaticLine(self
, p
): 
 229         w 
= wx
.StaticLine(p
, -1, size
=(150,-1)) 
 232     def TestStaticText(self
, p
): 
 233         w 
= wx
.StaticText(p
, -1, "This is a wx.StaticText") 
 236     def TestTextCtrl(self
, p
): 
 237         self
.DoWidget(wx
.TextCtrl(p
, -1, "This is a TextCtrl", size
=(150,-1))) 
 239     def TestToggleButton(self
, p
): 
 240         w 
= wx
.ToggleButton(p
, -1, "Toggle Button") 
 243     def TestTreeCtrl(self
, p
): 
 244         w 
= wx
.TreeCtrl(p
, -1, size
=(150,200)) 
 245         root 
= w
.AddRoot("The Root Item") 
 247             child 
= w
.AppendItem(root
, "Item %d" % x
) 
 251     def TestPanel(self
, p
): 
 252         w 
= wx
.Panel(p
, size
=(100,100)) 
 255     def TestPanel_With_Border(self
, p
): 
 256         w 
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
) 
 259     def TestPanel_With_BG(self
, p
): 
 260         w 
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
) 
 261         w
.SetBackgroundColour("pink") 
 264     def TestPanel_With_Controls(self
, p
): 
 265         w 
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
) 
 266         l1 
= wx
.StaticText(w
, -1, "Name:") 
 267         l2 
= wx
.StaticText(w
, -1, "Email:") 
 268         t1 
= wx
.TextCtrl(w
, -1, "", size
=(120,-1)) 
 269         t2 
= wx
.TextCtrl(w
, -1, "", size
=(120,-1)) 
 270         btn 
= wx
.Button(w
, wx
.ID_OK
) 
 271         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 272         fgs 
= wx
.FlexGridSizer(2,2,5,5) 
 277         sizer
.Add(fgs
, 0, wx
.ALL
, 10) 
 278         sizer
.Add(btn
, 0, wx
.ALL
, 10) 
 279         w
.SetSizerAndFit(sizer
) 
 282     def TestPanel_With_RadioBox(self
, p
): 
 283         w 
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
) 
 284         wx
.RadioBox(w
, -1, "RadioBox", pos
=(10,10), 
 285                     choices
=testChoices2
, majorDimension
=3) 
 289     def TestGenericButton(self
, p
): 
 290         import wx
.lib
.buttons 
as b
 
 291         w 
= b
.GenButton(p
, -1, "Generic Button") 
 292         w
.SetFont(wx
.Font(20, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False)) 
 295         w
.SetBackgroundColour("Navy") 
 296         w
.SetForegroundColour(wx
.WHITE
) 
 317 class DisplayPanel(wx
.Panel
): 
 318     def __init__(self
, parent
, ID
=-1): 
 319         wx
.Panel
.__init
__(self
, parent
, ID
) 
 320         self
.SetBackgroundColour("sky blue") 
 322         self
.Bind(wx
.EVT_PAINT
,            self
.OnPaint
) 
 323         self
.Bind(wx
.EVT_ERASE_BACKGROUND
, self
.OEB
) 
 326         self
.bmps 
= [None] * 5 
 329     def SetBMP(self
, bmp
, method
): 
 330         self
.bmps
[method
] = bmp
 
 336     def OnPaint(self
, evt
): 
 337         dc 
= wx
.BufferedPaintDC(self
) 
 338         dc
.SetBackground(wx
.Brush(self
.GetBackgroundColour())) 
 341         for idx
, bmp 
in enumerate(self
.bmps
): 
 343                 dc
.DrawText(str(idx
), 15, y
) 
 344                 dc
.DrawBitmap(bmp
, 30,y
, True) 
 345                 y 
+= bmp
.GetHeight() + 15