]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/tests/test4.py
Additions for wxTreeCtrl
[wxWidgets.git] / utils / wxPython / tests / test4.py
1 #!/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: test4.py
4 # Purpose: Testing lots of stuff, controls, window types, etc.
5 #
6 # Author: Robin Dunn
7 #
8 # Created:
9 # RCS-ID: $Id$
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14
15 from wxPython import *
16
17 import time
18
19 #---------------------------------------------------------------------------
20
21 class TestSimpleControlsDlg(wxDialog):
22 def __init__(self, parent, log):
23 self.log = log
24 wxDialog.__init__(self, parent, -1, "Test Simple Controls",
25 wxPyDefaultPosition, wxSize(350, 350))
26
27
28 sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
29 'six', 'seven', 'eight']
30
31 y_pos = 5
32 delta = 25
33
34 wxStaticText(self, -1, "wxTextCtrl", wxPoint(5, y_pos), wxSize(75, 20))
35 wxTextCtrl(self, 10, "", wxPoint(80, y_pos), wxSize(150, 20))
36 EVT_TEXT(self, 10, self.EvtText)
37 y_pos = y_pos + delta
38
39 wxCheckBox(self, 20, "wxCheckBox", wxPoint(80, y_pos), wxSize(150, 20), wxNO_BORDER)
40 EVT_CHECKBOX(self, 20, self.EvtCheckBox)
41 y_pos = y_pos + delta
42
43 rb = wxRadioBox(self, 30, "wxRadioBox", wxPoint(80, y_pos), wxPyDefaultSize,
44 sampleList, 3, wxRA_HORIZONTAL| wxNO_BORDER)
45 EVT_RADIOBOX(self, 30, self.EvtRadioBox)
46 width, height = rb.GetSize()
47 y_pos = y_pos + height + 5
48
49 wxStaticText(self, -1, "wxChoice", wxPoint(5, y_pos), wxSize(75, 20))
50 wxChoice(self, 40, wxPoint(80, y_pos), wxSize(95, 20), #wxPyDefaultSize,
51 sampleList)
52 EVT_CHOICE(self, 40, self.EvtChoice)
53 y_pos = y_pos + delta
54
55 wxStaticText(self, -1, "wxComboBox", wxPoint(5, y_pos), wxSize(75, 18))
56 wxComboBox(self, 50, "default value", wxPoint(80, y_pos), wxSize(95, 20),
57 sampleList, wxCB_DROPDOWN)
58 EVT_COMBOBOX(self, 50, self.EvtComboBox)
59 y_pos = y_pos + delta
60
61 wxStaticText(self, -1, "wxListBox", wxPoint(5, y_pos), wxSize(75, 18))
62 lb = wxListBox(self, 60, wxPoint(80, y_pos), wxPyDefaultSize,
63 sampleList, wxLB_SINGLE)
64 EVT_LISTBOX(self, 60, self.EvtListBox)
65 EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
66 lb.SetSelection(0)
67 width, height = lb.GetSize()
68 y_pos = y_pos + height + 5
69
70
71
72 y_pos = y_pos + 15
73 wxButton(self, wxID_OK, ' OK ', wxPoint(80, y_pos), wxPyDefaultSize).SetDefault()
74 wxButton(self, wxID_CANCEL, ' Cancel ', wxPoint(140, y_pos))
75
76
77 def EvtText(self, event):
78 self.log.WriteText('EvtText: %s\n' % event.GetString())
79
80 def EvtCheckBox(self, event):
81 self.log.WriteText('EvtCheckBox: %d\n' % event.GetInt())
82
83 def EvtRadioBox(self, event):
84 self.log.WriteText('EvtRadioBox: %d\n' % event.GetInt())
85
86 def EvtChoice(self, event):
87 self.log.WriteText('EvtChoice: %s\n' % event.GetString())
88
89 def EvtComboBox(self, event):
90 self.log.WriteText('EvtComboBox: %s\n' % event.GetString())
91
92 def EvtListBox(self, event):
93 self.log.WriteText('EvtListBox: %s\n' % event.GetString())
94
95 def EvtListBoxDClick(self, event):
96 self.log.WriteText('EvtListBoxDClick:\n')
97
98
99
100 #---------------------------------------------------------------------------
101
102 class TestTimer(wxTimer):
103 def __init__(self, log):
104 wxTimer.__init__(self)
105 self.log = log
106
107 def Notify(self):
108 wxBell()
109 self.log.WriteText('beep!\n')
110
111
112 #---------------------------------------------------------------------------
113
114 class TestLayoutConstraints(wxFrame):
115 def __init__(self, parent):
116 wxFrame.__init__(self, parent, -1, 'Test Layout Constraints',
117 wxPyDefaultPosition, wxSize(500, 300))
118
119 self.SetAutoLayout(true)
120 EVT_BUTTON(self, 100, self.OnButton)
121
122 self.panelA = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
123 wxSIMPLE_BORDER)
124 self.panelA.SetBackgroundColour(wxBLUE)
125 lc = wxLayoutConstraints()
126 lc.top.SameAs(self, wxTop, 10)
127 lc.left.SameAs(self, wxLeft, 10)
128 lc.bottom.SameAs(self, wxBottom, 10)
129 lc.right.PercentOf(self, wxRight, 50)
130 self.panelA.SetConstraints(lc)
131
132 self.panelB = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
133 wxSIMPLE_BORDER)
134 self.panelB.SetBackgroundColour(wxRED)
135 lc = wxLayoutConstraints()
136 lc.top.SameAs(self, wxTop, 10)
137 lc.right.SameAs(self, wxRight, 10)
138 lc.bottom.PercentOf(self, wxBottom, 30)
139 lc.left.RightOf(self.panelA, 10)
140 self.panelB.SetConstraints(lc)
141
142 self.panelC = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
143 wxSIMPLE_BORDER)
144 self.panelC.SetBackgroundColour(wxWHITE)
145 lc = wxLayoutConstraints()
146 lc.top.Below(self.panelB, 10)
147 lc.right.SameAs(self, wxRight, 10)
148 lc.bottom.SameAs(self, wxBottom, 10)
149 lc.left.RightOf(self.panelA, 10)
150 self.panelC.SetConstraints(lc)
151
152 b = wxButton(self.panelA, 100, ' Panel A ')
153 lc = wxLayoutConstraints()
154 lc.centreX.SameAs (self.panelA, wxCentreX)
155 lc.centreY.SameAs (self.panelA, wxCentreY)
156 lc.height.AsIs ()
157 lc.width.PercentOf (self.panelA, wxWidth, 50)
158 b.SetConstraints(lc);
159
160 b = wxButton(self.panelB, 100, ' Panel B ')
161 lc = wxLayoutConstraints()
162 lc.top.SameAs (self.panelB, wxTop, 2)
163 lc.right.SameAs (self.panelB, wxRight, 4)
164 lc.height.AsIs ()
165 lc.width.AsIs ()
166 b.SetConstraints(lc);
167
168 self.panelD = wxWindow(self.panelC, -1, wxPyDefaultPosition, wxPyDefaultSize,
169 wxSIMPLE_BORDER)
170 self.panelD.SetBackgroundColour(wxGREEN)
171 wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
172
173 b = wxButton(self.panelC, 100, ' Panel C ')
174 lc = wxLayoutConstraints()
175 lc.top.Below (self.panelD)
176 lc.left.RightOf (self.panelD)
177 lc.height.AsIs ()
178 lc.width.AsIs ()
179 b.SetConstraints(lc);
180
181 lc = wxLayoutConstraints()
182 lc.bottom.PercentOf (self.panelC, wxHeight, 50)
183 lc.right.PercentOf (self.panelC, wxWidth, 50)
184 lc.height.SameAs (b, wxHeight)
185 lc.width.SameAs (b, wxWidth)
186 self.panelD.SetConstraints(lc);
187
188
189 def OnButton(self, event):
190 self.Close(true)
191
192
193 def OnCloseWindow(self, event):
194 self.Destroy()
195
196
197 #---------------------------------------------------------------------------
198
199 class TestGrid(wxFrame):
200 def __init__(self, parent):
201 wxFrame.__init__(self, parent, -1, 'Test Grid',
202 wxPyDefaultPosition, wxSize(500, 300))
203
204 grid = wxGrid(self, -1)
205
206 grid.CreateGrid(16, 16)
207 grid.SetColumnWidth(3, 200)
208 grid.SetRowHeight(4, 45)
209 grid.SetCellValue("First cell", 0, 0)
210 grid.SetCellValue("Another cell", 1, 1)
211 grid.SetCellValue("Yet another cell", 2, 2)
212 grid.SetCellTextFont(wxFont(12, wxROMAN, wxITALIC, wxNORMAL), 0, 0)
213 grid.SetCellTextColour(wxRED, 1, 1)
214 grid.SetCellBackgroundColour(wxCYAN, 2, 2)
215 grid.UpdateDimensions()
216 grid.AdjustScrollbars()
217
218
219 def OnCloseWindow(self, event):
220 self.Destroy()
221
222
223 #---------------------------------------------------------------------------
224
225
226 class ColoredPanel(wxWindow):
227 def __init__(self, parent, color):
228 wxWindow.__init__(self, parent, -1,
229 wxPyDefaultPosition, wxPyDefaultSize, wxRAISED_BORDER)
230 self.SetBackgroundColour(color)
231
232
233 class TestNotebookWindow(wxFrame):
234 def __init__(self, parent, log):
235 wxFrame.__init__(self, parent, -1, 'Test wxNotebook',
236 wxPyDefaultPosition, wxPyDefaultSize)
237
238 nb = wxNotebook(self, -1)
239
240 win = ColoredPanel(nb, wxBLUE)
241 nb.AddPage(win, "Blue")
242 st = wxStaticText(win, -1,
243 "You can put nearly any type of window here!",
244 wxPoint(10, 10))
245 st.SetForegroundColour(wxWHITE)
246 st.SetBackgroundColour(wxBLUE)
247 st = wxStaticText(win, -1,
248 "Check the next tab for an example...",
249 wxPoint(10, 30))
250 st.SetForegroundColour(wxWHITE)
251 st.SetBackgroundColour(wxBLUE)
252
253 win = TestTreeCtrlPanel(nb, log)
254 nb.AddPage(win, "TreeCtrl")
255
256 win = ColoredPanel(nb, wxRED)
257 nb.AddPage(win, "Red")
258
259 win = ColoredPanel(nb, wxGREEN)
260 nb.AddPage(win, "Green")
261
262 win = ColoredPanel(nb, wxCYAN)
263 nb.AddPage(win, "Cyan")
264
265 win = ColoredPanel(nb, wxWHITE)
266 nb.AddPage(win, "White")
267
268 win = ColoredPanel(nb, wxBLACK)
269 nb.AddPage(win, "Black")
270
271 win = ColoredPanel(nb, wxNamedColour('MIDNIGHT BLUE'))
272 nb.AddPage(win, "MIDNIGHT BLUE")
273
274 win = ColoredPanel(nb, wxNamedColour('INDIAN RED'))
275 nb.AddPage(win, "INDIAN RED")
276
277
278 nb.SetSelection(0)
279 self.SetSize(wxSize(350, 300)) # force a redraw so the notebook will draw
280
281
282 def OnCloseWindow(self, event):
283 self.Destroy()
284
285 #---------------------------------------------------------------------------
286
287 class TestSplitterWindow(wxFrame):
288 def __init__(self, parent):
289 wxFrame.__init__(self, parent, -1, 'Test wxSplitterWindow',
290 wxPyDefaultPosition, wxSize(500, 300))
291
292 splitter = wxSplitterWindow(self, -1)
293
294 p1 = ColoredPanel(splitter, wxRED)
295 wxStaticText(p1, -1, "Panel One", wxPoint(5,5)).SetBackgroundColour(wxRED)
296
297 p2 = ColoredPanel(splitter, wxBLUE)
298 wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
299
300 splitter.SplitVertically(p1, p2)
301
302
303 def OnCloseWindow(self, event):
304 self.Destroy()
305
306
307 #---------------------------------------------------------------------------
308
309 class CustomStatusBar(wxStatusBar):
310 def __init__(self, parent):
311 wxStatusBar.__init__(self, parent, -1)
312 self.SetFieldsCount(3)
313
314 self.SetStatusText("A Custom StatusBar...", 0)
315
316 self.cb = wxCheckBox(self, 1001, "toggle clock")
317 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
318 self.cb.SetValue(true)
319
320 # figure out how tall to make it.
321 dc = wxClientDC(self)
322 dc.SetFont(self.GetFont())
323 (w,h, d,e) = dc.GetTextExtent('X')
324 h = int(h * 1.8)
325 self.SetSize(wxSize(100, h))
326
327 # start our timer
328 self.timer = wxPyTimer(self.Notify)
329 self.timer.Start(1000)
330 self.Notify()
331
332
333 # Time-out handler
334 def Notify(self):
335 t = time.localtime(time.time())
336 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
337 self.SetStatusText(st, 2)
338
339 # the checkbox was clicked
340 def OnToggleClock(self, event):
341 if self.cb.GetValue():
342 self.timer.Start(1000)
343 self.Notify()
344 else:
345 self.timer.Stop()
346
347 # reposition the checkbox
348 def OnSize(self, event):
349 rect = self.GetFieldRect(1)
350 self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
351 self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
352
353
354
355 class TestCustomStatusBar(wxFrame):
356 def __init__(self, parent):
357 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
358 wxPyDefaultPosition, wxSize(500, 300))
359 wxWindow(self, -1)
360
361 self.sb = CustomStatusBar(self)
362 self.SetStatusBar(self.sb)
363
364 def OnCloseWindow(self, event):
365 self.sb.timer.Stop()
366 self.Destroy()
367
368
369 #---------------------------------------------------------------------------
370
371 class TestToolBar(wxFrame):
372 def __init__(self, parent, log):
373 wxFrame.__init__(self, parent, -1, 'Test ToolBar',
374 wxPyDefaultPosition, wxSize(500, 300))
375 self.log = log
376
377 wxWindow(self, -1)
378
379 tb = self.CreateToolBar()
380 #tb = wxToolBar(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
381 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
382 #self.SetToolBar(tb)
383
384 tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
385 NULL, false, -1, -1, "New")
386 EVT_TOOL(self, 10, self.OnToolClick)
387 EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
388
389 tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
390 NULL, false, -1, -1, "Open")
391 EVT_TOOL(self, 20, self.OnToolClick)
392 EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
393
394 tb.AddSeparator()
395 tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
396 NULL, false, -1, -1, "Copy")
397 EVT_TOOL(self, 30, self.OnToolClick)
398 EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
399
400 tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
401 NULL, false, -1, -1, "Paste")
402 EVT_TOOL(self, 40, self.OnToolClick)
403 EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
404
405 tb.AddSeparator()
406
407 tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
408 NULL, true, -1, -1, "Toggle this")
409 EVT_TOOL(self, 50, self.OnToolClick)
410 EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
411
412 tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
413 wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
414 true, -1, -1, "Toggle with 2 bitmaps")
415 EVT_TOOL(self, 60, self.OnToolClick)
416 EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
417
418 tb.Realize()
419
420
421 def OnCloseWindow(self, event):
422 self.Destroy()
423
424 def OnToolClick(self, event):
425 self.log.WriteText("tool %s clicked\n" % event.GetId())
426
427 def OnToolRClick(self, event):
428 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
429
430
431 #---------------------------------------------------------------------------
432
433 class TestTreeCtrlPanel(wxPanel):
434 def __init__(self, parent, log):
435 wxPanel.__init__(self, parent, -1)
436
437 self.log = log
438 tID = 1101
439
440 self.tree = wxTreeCtrl(self, tID)
441 root = self.tree.AddRoot("The Root Item")
442 for x in range(10):
443 child = self.tree.AppendItem(root, "Item %d" % x)
444 for y in range(5):
445 last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
446
447 self.tree.Expand(root)
448 EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
449 EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
450 EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
451
452
453 def OnSize(self, event):
454 w,h = self.GetClientSize()
455 self.tree.SetDimensions(0, 0, w, h)
456
457
458 def OnItemExpanded(self, event):
459 item = event.GetItem()
460 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
461
462 def OnItemCollapsed(self, event):
463 item = event.GetItem()
464 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
465
466 def OnSelChanged(self, event):
467 item = event.GetItem()
468 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
469
470
471
472
473 class TestTreeCtrl(wxFrame):
474 def __init__(self, parent, log):
475 wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
476 wxPyDefaultPosition, wxSize(250, 300))
477
478 p = TestTreeCtrlPanel(self, log)
479
480
481 #---------------------------------------------------------------------------
482 #---------------------------------------------------------------------------
483 #---------------------------------------------------------------------------
484
485 class AppFrame(wxFrame):
486 def __init__(self, parent, id, title):
487 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
488 wxSize(420, 200))
489 if wxPlatform == '__WXMSW__':
490 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
491 self.SetIcon(self.icon)
492
493 self.mainmenu = wxMenuBar()
494 menu = wxMenu()
495 menu.Append(200, 'E&xit', 'Get the heck outta here!')
496 EVT_MENU(self, 200, self.OnFileExit)
497 self.mainmenu.Append(menu, '&File')
498
499 menu = self.MakeTestsMenu()
500 self.mainmenu.Append(menu, '&Tests')
501 self.SetMenuBar(self.mainmenu)
502
503 self.log = wxTextCtrl(self, -1, '', wxPyDefaultPosition, wxPyDefaultSize,
504 wxTE_MULTILINE|wxTE_READONLY)
505 self.log.WriteText('Test 4:\n')
506 (w, self.charHeight) = self.log.GetTextExtent('X')
507
508
509 def MakeTestsMenu(self):
510 menu = wxMenu()
511
512 mID = NewId()
513 menu.Append(mID, '&Simple Controls')
514 EVT_MENU(self, mID, self.OnTestSimpleControls)
515
516 mID = NewId()
517 menu.Append(mID, '&Timer', '', true)
518 EVT_MENU(self, mID, self.OnTestTimer)
519 self.timerID = mID
520 self.timer = None
521
522 mID = NewId()
523 menu.Append(mID, '&Layout Constraints')
524 EVT_MENU(self, mID, self.OnTestLayoutConstraints)
525
526 mID = NewId()
527 menu.Append(mID, '&Grid')
528 EVT_MENU(self, mID, self.OnTestGrid)
529
530
531 smenu = wxMenu() # make a sub-menu
532
533 mID = NewId()
534 smenu.Append(mID, '&Colour')
535 EVT_MENU(self, mID, self.OnTestColourDlg)
536
537 mID = NewId()
538 smenu.Append(mID, '&Directory')
539 EVT_MENU(self, mID, self.OnTestDirDlg)
540
541 mID = NewId()
542 smenu.Append(mID, '&File')
543 EVT_MENU(self, mID, self.OnTestFileDlg)
544
545 mID = NewId()
546 smenu.Append(mID, '&Single Choice')
547 EVT_MENU(self, mID, self.OnTestSingleChoiceDlg)
548
549 mID = NewId()
550 smenu.Append(mID, '&TextEntry')
551 EVT_MENU(self, mID, self.OnTestTextEntryDlg)
552
553 mID = NewId()
554 smenu.Append(mID, '&Font')
555 EVT_MENU(self, mID, self.OnTestFontDlg)
556
557 mID = NewId()
558 smenu.Append(mID, '&PageSetup')
559 EVT_MENU(self, mID, self.OnTestPageSetupDlg)
560
561 mID = NewId()
562 smenu.Append(mID, '&Print')
563 EVT_MENU(self, mID, self.OnTestPrintDlg)
564
565 mID = NewId()
566 smenu.Append(mID, '&Message')
567 EVT_MENU(self, mID, self.OnTestMessageDlg)
568
569
570 menu.AppendMenu(NewId(), '&Common Dialogs', smenu)
571
572
573 mID = NewId()
574 menu.Append(mID, '&Notebook')
575 EVT_MENU(self, mID, self.OnTestNotebook)
576
577 mID = NewId()
578 menu.Append(mID, '&Splitter Window')
579 EVT_MENU(self, mID, self.OnTestSplitter)
580
581 mID = NewId()
582 menu.Append(mID, '&Custom StatusBar')
583 EVT_MENU(self, mID, self.OnTestCustomStatusBar)
584
585 mID = NewId()
586 menu.Append(mID, '&ToolBar')
587 EVT_MENU(self, mID, self.OnTestToolBar)
588
589 mID = NewId()
590 menu.Append(mID, 'T&ree Control')
591 EVT_MENU(self, mID, self.OnTestTreeCtrl)
592
593 return menu
594
595
596
597
598 def WriteText(self, str):
599 self.log.WriteText(str)
600 if wxPlatform == '__WXMSW__':
601 w, h = self.log.GetClientSize()
602 numLines = h/self.charHeight
603 x, y = self.log.PositionToXY(self.log.GetLastPosition())
604 self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
605
606 def OnFileExit(self, event):
607 self.Close()
608
609 def OnCloseWindow(self, event):
610 self.Destroy()
611
612
613
614
615 def OnTestSimpleControls(self, event):
616 dlg = TestSimpleControlsDlg(self, self)
617 dlg.Centre()
618 dlg.ShowModal()
619 dlg.Destroy()
620
621 def OnTestTimer(self, event):
622 if self.timer:
623 self.mainmenu.Check(self.timerID, false)
624 self.timer.Stop()
625 self.timer = None
626 else:
627 self.mainmenu.Check(self.timerID, true)
628 self.timer = TestTimer(self)
629 self.timer.Start(1000)
630
631 def OnTestLayoutConstraints(self, event):
632 win = TestLayoutConstraints(self)
633 win.Show(true)
634
635 def OnTestGrid(self, event):
636 win = TestGrid(self)
637 win.Show(true)
638 win.SetSize(wxSize(505, 300)) # have to force a resize, or the grid doesn't
639 # show up for some reason....
640
641 def OnTestColourDlg(self, event):
642 data = wxColourData()
643 data.SetChooseFull(true)
644 dlg = wxColourDialog(self, data)
645 if dlg.ShowModal() == wxID_OK:
646 data = dlg.GetColourData()
647 self.log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
648 dlg.Destroy()
649
650 def OnTestDirDlg(self, event):
651 dlg = wxDirDialog(self)
652 if dlg.ShowModal() == wxID_OK:
653 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
654 dlg.Destroy()
655
656 def OnTestFileDlg(self, event):
657 dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
658 if dlg.ShowModal() == wxID_OK:
659 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
660 dlg.Destroy()
661
662 def OnTestSingleChoiceDlg(self, event):
663 dlg = wxSingleChoiceDialog(self, 'Test Single Choice', 'The Caption',
664 ['zero', 'one', 'two', 'three', 'four', 'five',
665 'six', 'seven', 'eight'])
666 if dlg.ShowModal() == wxID_OK:
667 self.log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
668 dlg.Destroy()
669
670 def OnTestTextEntryDlg(self, event):
671 dlg = wxTextEntryDialog(self, 'What is your favorite programming language?',
672 'Duh??', 'Python')
673 #dlg.SetValue("Python is the best!") #### this doesn't work?
674 if dlg.ShowModal() == wxID_OK:
675 self.log.WriteText('You entered: %s\n' % dlg.GetValue())
676 dlg.Destroy()
677
678
679 def OnTestFontDlg(self, event):
680 dlg = wxFontDialog(self)
681 if dlg.ShowModal() == wxID_OK:
682 data = dlg.GetFontData()
683 font = data.GetChosenFont()
684 self.log.WriteText('You selected: "%s", %d points, color %s\n' %
685 (font.GetFaceName(), font.GetPointSize(),
686 data.GetColour().Get()))
687 dlg.Destroy()
688
689
690 def OnTestPageSetupDlg(self, event):
691 data = wxPageSetupData()
692 data.SetMarginTopLeft(wxPoint(50,50))
693 data.SetMarginBottomRight(wxPoint(50,50))
694 dlg = wxPageSetupDialog(self, data)
695 if dlg.ShowModal() == wxID_OK:
696 data = dlg.GetPageSetupData()
697 tl = data.GetMarginTopLeft()
698 br = data.GetMarginBottomRight()
699 self.log.WriteText('Margins are: %s %s\n' % (str(tl), str(br)))
700 dlg.Destroy()
701
702 def OnTestPrintDlg(self, event):
703 data = wxPrintData()
704 data.EnablePrintToFile(true)
705 data.EnablePageNumbers(true)
706 data.EnableSelection(true)
707 dlg = wxPrintDialog(self, data)
708 if dlg.ShowModal() == wxID_OK:
709 self.log.WriteText('\n')
710 dlg.Destroy()
711
712 def OnTestMessageDlg(self, event):
713 dlg = wxMessageDialog(self, 'Hello from Python and wxWindows!',
714 'A Message Box', wxOK | wxICON_INFORMATION)
715 dlg.ShowModal()
716 dlg.Destroy()
717
718
719 def OnTestNotebook(self, event):
720 win = TestNotebookWindow(self, self)
721 win.Show(true)
722
723 def OnTestSplitter(self, event):
724 win = TestSplitterWindow(self)
725 win.Show(true)
726
727 def OnTestCustomStatusBar(self, event):
728 win = TestCustomStatusBar(self)
729 win.Show(true)
730
731 def OnTestToolBar(self, event):
732 win = TestToolBar(self, self)
733 win.Show(true)
734
735 def OnTestTreeCtrl(self, event):
736 win = TestTreeCtrl(self, self)
737 win.Show(true)
738
739
740 #---------------------------------------------------------------------------
741
742
743 class MyApp(wxApp):
744 def OnInit(self):
745 frame = AppFrame(NULL, -1, "Test 4: (lots of little tests...)")
746 frame.Show(true)
747 self.SetTopWindow(frame)
748 return true
749
750 #---------------------------------------------------------------------------
751
752
753 def main():
754 app = MyApp(0)
755 app.MainLoop()
756
757
758 def t():
759 import pdb
760 pdb.run('main()')
761
762
763 # for focused testing...
764 def main2():
765 class T2App(wxApp):
766 def OnInit(self):
767 frame = TestLayoutConstraints(NULL)
768 frame.Show(true)
769 self.SetTopWindow(frame)
770 return true
771
772 app = T2App(0)
773 app.MainLoop()
774
775 def t2():
776 import pdb
777 pdb.run('main2()')
778
779
780
781 if __name__ == '__main__':
782 main()
783
784
785 #----------------------------------------------------------------------------
786 #
787 # $Log$
788 # Revision 1.7 1998/11/11 03:13:19 RD
789 # Additions for wxTreeCtrl
790 #
791 # Revision 1.6 1998/10/20 06:45:33 RD
792 # New wxTreeCtrl wrappers (untested)
793 # some changes in helpers
794 # etc.
795 #
796 # Revision 1.5 1998/10/02 06:42:28 RD
797 #
798 # Version 0.4 of wxPython for MSW.
799 #
800 # Revision 1.4 1998/08/27 21:59:51 RD
801 # Some chicken-and-egg problems solved for wxPython on wxGTK
802 #
803 # Revision 1.3 1998/08/27 00:01:17 RD
804 # - more tweaks
805 # - have discovered some problems but not yet discovered solutions...
806 #
807 # Revision 1.2 1998/08/22 19:51:18 RD
808 # some tweaks for wxGTK
809 #
810 # Revision 1.1 1998/08/09 08:28:05 RD
811 # Initial version
812 #
813 #