]> git.saurik.com Git - wxWidgets.git/blame - wxPython/misc/drawwidget.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / misc / drawwidget.py
CommitLineData
d115ca5e
RD
1
2
3import wx
4
5testItems = [
6 "",
7 "BitmapButton",
8 "Button",
9 "CalendarCtrl",
10 "CheckBox",
11 "CheckListBox",
12 "Choice",
13 "ComboBox",
14 "Gauge",
15 "GenericDirCtrl",
16 "ListBox",
17 "ListCtrl",
32478f52 18 "ListCtrl With GridLines",
d115ca5e
RD
19 "RadioBox",
20 "RadioButton",
21 "ScrollBar",
22 "Slider",
23 "SpinButton",
24 "SpinCtrl",
25 "StaticBitmap",
26 "StaticBox",
27 "StaticLine",
28 "StaticText",
29 "TextCtrl",
30 "ToggleButton",
31 "TreeCtrl",
32 "--------------",
33 "Panel",
34 "Panel With Border",
35 "Panel With BG",
36 "Panel With Controls",
37 "Panel With RadioBox",
38 "--------------",
39 "GenericButton",
40
41 ]
42
43import keyword
44testChoices = keyword.kwlist
45
46testChoices2 = "one two three four five six seven eight nine".split()
47
48
49
50
51class Frame(wx.Frame):
52 def __init__(self):
53 wx.Frame.__init__(self, None, title="Draw Widget Test")
54 self.left = wx.Panel(self)
55 self.right = DisplayPanel(self)
56 self.widget = None
57
58 sizer = wx.BoxSizer(wx.HORIZONTAL)
59 sizer.Add(self.left, 1, wx.EXPAND)
60 sizer.Add(self.right, 1, wx.EXPAND)
61 self.SetSizer(sizer)
62
63 menu = wx.Menu()
64 menu.Append(wx.ID_EXIT, "E&xit\tAlt-X")
65 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
66 mbar = wx.MenuBar()
67 mbar.Append(menu, "&File")
68 self.SetMenuBar(mbar)
69
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)
73
74
75 def OnWidgetChosen(self, evt):
76 item = evt.GetString()
77 item = item.replace(" ", "_")
78 func = getattr(self, "Test"+item, None)
79 if func is not None:
80 func(self.left)
81
82 def OnExit(self, evt):
83 self.Close()
84
85
86
87 def DoWidget(self, widget):
88 self.right.Empty()
89 if self.widget is not None:
90 self.widget.Destroy()
91 self.widget = widget
92 if widget is None:
93 return
94
95 visiblePos = (20,80)
96 hiddenPos = (-1000,-1000)
97
98 widget.SetPosition(visiblePos)
99 widget.Update()
100 self.GetBMP(0) # Uses just a DC.Blit, so it must be visible
101
102 # the rest should work when the widget is not visible.
103 widget.SetPosition(hiddenPos)
104 widget.Update()
105 self.Update()
106
32478f52 107 ##self.GetBMP(1)
d115ca5e 108 self.GetBMP(2)
32478f52 109 ##self.GetBMP(4)
d115ca5e
RD
110
111 # make it visible again for the user to compare
112 widget.SetPosition(visiblePos)
113
114
115 def GetBMP(self, method):
116 w = self.widget
117 maskClr = wx.Colour(12, 34, 56)
118 sz = w.GetSize()
119 bmp = wx.EmptyBitmap(sz.width, sz.height)
120 dc = wx.MemoryDC()
121 dc.SelectObject(bmp)
122 dc.SetBackground(wx.Brush(maskClr))
123 dc.Clear()
124
125 if method == 0:
126 wdc = wx.WindowDC(w)
127 dc.Blit(0,0, sz.width, sz.height, wdc, 0, 0)
128 else:
32478f52
RD
129 ##wx.DrawWindowOnDC(w, dc, method)
130 wx.DrawWindowOnDC(w, dc)
131
d115ca5e
RD
132 dc.SelectObject(wx.NullBitmap)
133 bmp.SetMaskColour(maskClr)
134 self.right.SetBMP(bmp, method)
135
136
137
138
139
140 def Test(self, p):
141 self.DoWidget(None)
142
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"))
148
149 def TestCalendarCtrl(self, p):
150 import wx.calendar
151 w = wx.calendar.CalendarCtrl(p, style=wx.calendar.CAL_SEQUENTIAL_MONTH_SELECTION)
152 self.DoWidget(w)
153
154 def TestCheckBox(self, p):
155 self.DoWidget(wx.CheckBox(p, -1, "checkbox"))
156
157 def TestCheckListBox(self, p):
158 w = wx.CheckListBox(p, -1, choices=testChoices)
159 w.SetSelection(2)
160 self.DoWidget(w)
161
162 def TestChoice(self, p):
163 w = wx.Choice(p, -1, choices=testChoices)
164 w.SetSelection(2)
165 self.DoWidget(w)
166
167 def TestComboBox(self, p):
168 w = wx.ComboBox(p, -1, choices=testChoices)
169 w.SetSelection(2)
170 self.DoWidget(w)
171
172 def TestGauge(self, p):
173 w = wx.Gauge(p, -1, 100, size=(150, -1))
174 w.SetValue(65)
175 self.DoWidget(w)
176
177 def TestGenericDirCtrl(self, p):
178 w = wx.GenericDirCtrl(p, size=(150,200), style=wx.DIRCTRL_DIR_ONLY)
179 self.DoWidget(w)
180
181 def TestListBox(self, p):
182 w = wx.ListBox(p, -1, choices=testChoices)
183 w.SetSelection(2)
184 self.DoWidget(w)
185
32478f52
RD
186 def TestListCtrl(self, p, useGridLines=False):
187 style=wx.LC_REPORT
188 if useGridLines:
189 style = style | wx.LC_HRULES | wx.LC_VRULES
190 w = wx.ListCtrl(p, -1, size=(250, 100), style=style)
d115ca5e
RD
191 w.InsertColumn(0, "Col 1")
192 w.InsertColumn(1, "Col 2")
193 w.InsertColumn(2, "Col 3")
194 for x in range(10):
195 w.InsertStringItem(x, str(x))
196 w.SetStringItem(x, 1, str(x))
197 w.SetStringItem(x, 2, str(x))
198 self.DoWidget(w)
32478f52
RD
199
200 def TestListCtrl_With_GridLines(self, p):
201 self.TestListCtrl(p, True)
202
d115ca5e
RD
203 def TestRadioBox(self, p):
204 w = wx.RadioBox(p, -1, "RadioBox",
205 choices=testChoices2, majorDimension=3)
206 self.DoWidget(w)
207
208 def TestRadioButton(self, p):
209 self.DoWidget(wx.RadioButton(p, -1, "RadioButton"))
210
211 def TestScrollBar(self, p):
212 w = wx.ScrollBar(p, -1, size=(150,-1))
213 w.SetScrollbar(25, 5, 100, 10)
214 self.DoWidget(w)
215
216 def TestSlider(self, p):
217 w = wx.Slider(p, -1, size=(150,-1))
218 self.DoWidget(w)
219
220 def TestSpinButton(self, p):
221 w = wx.SpinButton(p, -1)
222 self.DoWidget(w)
223
224 def TestSpinCtrl(self, p):
225 w = wx.SpinCtrl(p, -1)
226 self.DoWidget(w)
227
228 def TestStaticBitmap(self, p):
229 w = wx.StaticBitmap(p, -1, wx.Bitmap("image.png"))
230 self.DoWidget(w)
231
232 def TestStaticBox(self, p):
233 w = wx.StaticBox(p, -1, "StaticBox", size=(150,75))
234 self.DoWidget(w)
235
236 def TestStaticLine(self, p):
237 w = wx.StaticLine(p, -1, size=(150,-1))
238 self.DoWidget(w)
239
240 def TestStaticText(self, p):
241 w = wx.StaticText(p, -1, "This is a wx.StaticText")
242 self.DoWidget(w)
243
244 def TestTextCtrl(self, p):
245 self.DoWidget(wx.TextCtrl(p, -1, "This is a TextCtrl", size=(150,-1)))
246
247 def TestToggleButton(self, p):
248 w = wx.ToggleButton(p, -1, "Toggle Button")
249 self.DoWidget(w)
250
251 def TestTreeCtrl(self, p):
252 w = wx.TreeCtrl(p, -1, size=(150,200))
253 root = w.AddRoot("The Root Item")
254 for x in range(15):
255 child = w.AppendItem(root, "Item %d" % x)
256 w.Expand(root)
257 self.DoWidget(w)
258
259 def TestPanel(self, p):
260 w = wx.Panel(p, size=(100,100))
261 self.DoWidget(w)
262
263 def TestPanel_With_Border(self, p):
264 w = wx.Panel(p, size=(100,100), style=wx.SUNKEN_BORDER)
265 self.DoWidget(w)
266
267 def TestPanel_With_BG(self, p):
268 w = wx.Panel(p, size=(100,100), style=wx.SUNKEN_BORDER)
269 w.SetBackgroundColour("pink")
270 self.DoWidget(w)
271
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)
281 fgs.Add(l1)
282 fgs.Add(t1)
283 fgs.Add(l2)
284 fgs.Add(t2)
285 sizer.Add(fgs, 0, wx.ALL, 10)
286 sizer.Add(btn, 0, wx.ALL, 10)
287 w.SetSizerAndFit(sizer)
288 self.DoWidget(w)
289
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)
294 w.Fit()
295 self.DoWidget(w)
296
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))
301 w.SetBezelWidth(5)
170acdc9 302 w.SetInitialSize()
d115ca5e
RD
303 w.SetBackgroundColour("Navy")
304 w.SetForegroundColour(wx.WHITE)
305 self.DoWidget(w)
306
307 def TestT(self, p):
308 self.DoWidget(w)
309
310 def TestT(self, p):
311 self.DoWidget(w)
312
313 def TestT(self, p):
314 self.DoWidget(w)
315
316 def TestT(self, p):
317 self.DoWidget(w)
318
319
320
321
322
323
324
325class DisplayPanel(wx.Panel):
326 def __init__(self, parent, ID=-1):
327 wx.Panel.__init__(self, parent, ID)
328 self.SetBackgroundColour("sky blue")
329 self.Empty()
330 self.Bind(wx.EVT_PAINT, self.OnPaint)
331 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OEB)
332
333 def Empty(self):
334 self.bmps = [None] * 5
335 self.Refresh()
336
337 def SetBMP(self, bmp, method):
338 self.bmps[method] = bmp
339 self.Refresh()
340
341 def OEB(self, evt):
342 None
343
344 def OnPaint(self, evt):
345 dc = wx.BufferedPaintDC(self)
346 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
347 dc.Clear()
348 y = 25
349 for idx, bmp in enumerate(self.bmps):
350 if bmp is not None:
351 dc.DrawText(str(idx), 15, y)
352 dc.DrawBitmap(bmp, 30,y, True)
353 y += bmp.GetHeight() + 15
354
355
356
357app = wx.App(False)
358f = Frame()
359f.SetSize((600,600))
360f.Show()
361app.MainLoop()