18 "ListCtrl With GridLines",
36 "Panel With Controls",
37 "Panel With RadioBox",
44 testChoices
= keyword
.kwlist
46 testChoices2
= "one two three four five six seven eight nine".split()
51 class Frame(wx
.Frame
):
53 wx
.Frame
.__init
__(self
, None, title
="Draw Widget Test")
54 self
.left
= wx
.Panel(self
)
55 self
.right
= DisplayPanel(self
)
58 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
59 sizer
.Add(self
.left
, 1, wx
.EXPAND
)
60 sizer
.Add(self
.right
, 1, wx
.EXPAND
)
64 menu
.Append(wx
.ID_EXIT
, "E&xit\tAlt-X")
65 self
.Bind(wx
.EVT_MENU
, self
.OnExit
, id=wx
.ID_EXIT
)
67 mbar
.Append(menu
, "&File")
70 cb
= wx
.ComboBox(self
.left
, -1, pos
=(20,20),
71 choices
=testItems
, style
=wx
.CB_READONLY
)
72 self
.Bind(wx
.EVT_COMBOBOX
, self
.OnWidgetChosen
, cb
)
75 def OnWidgetChosen(self
, evt
):
76 item
= evt
.GetString()
77 item
= item
.replace(" ", "_")
78 func
= getattr(self
, "Test"+item
, None)
82 def OnExit(self
, evt
):
87 def DoWidget(self
, widget
):
89 if self
.widget
is not None:
96 hiddenPos
= (-1000,-1000)
98 widget
.SetPosition(visiblePos
)
100 self
.GetBMP(0) # Uses just a DC.Blit, so it must be visible
102 # the rest should work when the widget is not visible.
103 widget
.SetPosition(hiddenPos
)
111 # make it visible again for the user to compare
112 widget
.SetPosition(visiblePos
)
115 def GetBMP(self
, method
):
117 maskClr
= wx
.Colour(12, 34, 56)
119 bmp
= wx
.EmptyBitmap(sz
.width
, sz
.height
)
122 dc
.SetBackground(wx
.Brush(maskClr
))
127 dc
.Blit(0,0, sz
.width
, sz
.height
, wdc
, 0, 0)
129 ##wx.DrawWindowOnDC(w, dc, method)
130 wx
.DrawWindowOnDC(w
, dc
)
132 dc
.SelectObject(wx
.NullBitmap
)
133 bmp
.SetMaskColour(maskClr
)
134 self
.right
.SetBMP(bmp
, method
)
143 def TestBitmapButton(self
, p
):
144 self
.DoWidget(wx
.BitmapButton(p
, -1,
145 wx
.Bitmap("image.png")))
146 def TestButton(self
, p
):
147 self
.DoWidget(wx
.Button(p
, -1, "A button"))
149 def TestCalendarCtrl(self
, p
):
151 w
= wx
.calendar
.CalendarCtrl(p
, style
=wx
.calendar
.CAL_SEQUENTIAL_MONTH_SELECTION
)
154 def TestCheckBox(self
, p
):
155 self
.DoWidget(wx
.CheckBox(p
, -1, "checkbox"))
157 def TestCheckListBox(self
, p
):
158 w
= wx
.CheckListBox(p
, -1, choices
=testChoices
)
162 def TestChoice(self
, p
):
163 w
= wx
.Choice(p
, -1, choices
=testChoices
)
167 def TestComboBox(self
, p
):
168 w
= wx
.ComboBox(p
, -1, choices
=testChoices
)
172 def TestGauge(self
, p
):
173 w
= wx
.Gauge(p
, -1, 100, size
=(150, -1))
177 def TestGenericDirCtrl(self
, p
):
178 w
= wx
.GenericDirCtrl(p
, size
=(150,200), style
=wx
.DIRCTRL_DIR_ONLY
)
181 def TestListBox(self
, p
):
182 w
= wx
.ListBox(p
, -1, choices
=testChoices
)
186 def TestListCtrl(self
, p
, useGridLines
=False):
189 style
= style | wx
.LC_HRULES | wx
.LC_VRULES
190 w
= wx
.ListCtrl(p
, -1, size
=(250, 100), style
=style
)
191 w
.InsertColumn(0, "Col 1")
192 w
.InsertColumn(1, "Col 2")
193 w
.InsertColumn(2, "Col 3")
195 w
.InsertStringItem(x
, str(x
))
196 w
.SetStringItem(x
, 1, str(x
))
197 w
.SetStringItem(x
, 2, str(x
))
200 def TestListCtrl_With_GridLines(self
, p
):
201 self
.TestListCtrl(p
, True)
203 def TestRadioBox(self
, p
):
204 w
= wx
.RadioBox(p
, -1, "RadioBox",
205 choices
=testChoices2
, majorDimension
=3)
208 def TestRadioButton(self
, p
):
209 self
.DoWidget(wx
.RadioButton(p
, -1, "RadioButton"))
211 def TestScrollBar(self
, p
):
212 w
= wx
.ScrollBar(p
, -1, size
=(150,-1))
213 w
.SetScrollbar(25, 5, 100, 10)
216 def TestSlider(self
, p
):
217 w
= wx
.Slider(p
, -1, size
=(150,-1))
220 def TestSpinButton(self
, p
):
221 w
= wx
.SpinButton(p
, -1)
224 def TestSpinCtrl(self
, p
):
225 w
= wx
.SpinCtrl(p
, -1)
228 def TestStaticBitmap(self
, p
):
229 w
= wx
.StaticBitmap(p
, -1, wx
.Bitmap("image.png"))
232 def TestStaticBox(self
, p
):
233 w
= wx
.StaticBox(p
, -1, "StaticBox", size
=(150,75))
236 def TestStaticLine(self
, p
):
237 w
= wx
.StaticLine(p
, -1, size
=(150,-1))
240 def TestStaticText(self
, p
):
241 w
= wx
.StaticText(p
, -1, "This is a wx.StaticText")
244 def TestTextCtrl(self
, p
):
245 self
.DoWidget(wx
.TextCtrl(p
, -1, "This is a TextCtrl", size
=(150,-1)))
247 def TestToggleButton(self
, p
):
248 w
= wx
.ToggleButton(p
, -1, "Toggle Button")
251 def TestTreeCtrl(self
, p
):
252 w
= wx
.TreeCtrl(p
, -1, size
=(150,200))
253 root
= w
.AddRoot("The Root Item")
255 child
= w
.AppendItem(root
, "Item %d" % x
)
259 def TestPanel(self
, p
):
260 w
= wx
.Panel(p
, size
=(100,100))
263 def TestPanel_With_Border(self
, p
):
264 w
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
)
267 def TestPanel_With_BG(self
, p
):
268 w
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
)
269 w
.SetBackgroundColour("pink")
272 def TestPanel_With_Controls(self
, p
):
273 w
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
)
274 l1
= wx
.StaticText(w
, -1, "Name:")
275 l2
= wx
.StaticText(w
, -1, "Email:")
276 t1
= wx
.TextCtrl(w
, -1, "", size
=(120,-1))
277 t2
= wx
.TextCtrl(w
, -1, "", size
=(120,-1))
278 btn
= wx
.Button(w
, wx
.ID_OK
)
279 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
280 fgs
= wx
.FlexGridSizer(2,2,5,5)
285 sizer
.Add(fgs
, 0, wx
.ALL
, 10)
286 sizer
.Add(btn
, 0, wx
.ALL
, 10)
287 w
.SetSizerAndFit(sizer
)
290 def TestPanel_With_RadioBox(self
, p
):
291 w
= wx
.Panel(p
, size
=(100,100), style
=wx
.SUNKEN_BORDER
)
292 wx
.RadioBox(w
, -1, "RadioBox", pos
=(10,10),
293 choices
=testChoices2
, majorDimension
=3)
297 def TestGenericButton(self
, p
):
298 import wx
.lib
.buttons
as b
299 w
= b
.GenButton(p
, -1, "Generic Button")
300 w
.SetFont(wx
.Font(20, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False))
303 w
.SetBackgroundColour("Navy")
304 w
.SetForegroundColour(wx
.WHITE
)
325 class DisplayPanel(wx
.Panel
):
326 def __init__(self
, parent
, ID
=-1):
327 wx
.Panel
.__init
__(self
, parent
, ID
)
328 self
.SetBackgroundColour("sky blue")
330 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
331 self
.Bind(wx
.EVT_ERASE_BACKGROUND
, self
.OEB
)
334 self
.bmps
= [None] * 5
337 def SetBMP(self
, bmp
, method
):
338 self
.bmps
[method
] = bmp
344 def OnPaint(self
, evt
):
345 dc
= wx
.BufferedPaintDC(self
)
346 dc
.SetBackground(wx
.Brush(self
.GetBackgroundColour()))
349 for idx
, bmp
in enumerate(self
.bmps
):
351 dc
.DrawText(str(idx
), 15, y
)
352 dc
.DrawBitmap(bmp
, 30,y
, True)
353 y
+= bmp
.GetHeight() + 15