]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/tests/test4.py
In test4's toolbar sample, changed NULL to wxNullBitmap to prevent SIGSEVS
[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.wx 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.GetSizeTuple()
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.GetSizeTuple()
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, log):
201 wxFrame.__init__(self, parent, -1, 'Test Grid',
202 wxPyDefaultPosition, wxSize(500, 300))
203 self.log = log
204
205 grid = wxGrid(self, -1)
206
207 grid.CreateGrid(16, 16)
208 grid.SetColumnWidth(3, 200)
209 grid.SetRowHeight(4, 45)
210 grid.SetCellValue("First cell", 0, 0)
211 grid.SetCellValue("Another cell", 1, 1)
212 grid.SetCellValue("Yet another cell", 2, 2)
213 grid.SetCellTextFont(wxFont(12, wxROMAN, wxITALIC, wxNORMAL), 0, 0)
214 grid.SetCellTextColour(wxRED, 1, 1)
215 grid.SetCellBackgroundColour(wxCYAN, 2, 2)
216 grid.UpdateDimensions()
217 grid.AdjustScrollbars()
218
219 EVT_GRID_SELECT_CELL(grid, self.OnSelectCell)
220 EVT_GRID_CELL_CHANGE(grid, self.OnCellChange)
221 EVT_GRID_CELL_LCLICK(grid, self.OnCellClick)
222 EVT_GRID_LABEL_LCLICK(grid, self.OnLabelClick)
223
224
225
226 def OnCloseWindow(self, event):
227 self.Destroy()
228
229 def OnSelectCell(self, event):
230 self.log.WriteText("OnSelectCell: (%d, %d)\n" % (event.m_row, event.m_col))
231
232 def OnCellChange(self, event):
233 self.log.WriteText("OnCellChange: (%d, %d)\n" % (event.m_row, event.m_col))
234
235 def OnCellClick(self, event):
236 self.log.WriteText("OnCellClick: (%d, %d)\n" % (event.m_row, event.m_col))
237
238 def OnLabelClick(self, event):
239 self.log.WriteText("OnLabelClick: (%d, %d)\n" % (event.m_row, event.m_col))
240
241 #---------------------------------------------------------------------------
242
243
244 class ColoredPanel(wxWindow):
245 def __init__(self, parent, color):
246 wxWindow.__init__(self, parent, -1,
247 wxPyDefaultPosition, wxPyDefaultSize, wxRAISED_BORDER)
248 self.SetBackgroundColour(color)
249
250
251 class TestNotebookWindow(wxFrame):
252 def __init__(self, parent, log):
253 wxFrame.__init__(self, parent, -1, 'Test wxNotebook',
254 wxPyDefaultPosition, wxPyDefaultSize)
255
256 nb = wxNotebook(self, -1)
257
258 win = ColoredPanel(nb, wxBLUE)
259 nb.AddPage(win, "Blue")
260 st = wxStaticText(win, -1,
261 "You can put nearly any type of window here!",
262 wxPoint(10, 10))
263 st.SetForegroundColour(wxWHITE)
264 st.SetBackgroundColour(wxBLUE)
265 st = wxStaticText(win, -1,
266 "Check the next tab for an example...",
267 wxPoint(10, 30))
268 st.SetForegroundColour(wxWHITE)
269 st.SetBackgroundColour(wxBLUE)
270
271 win = TestTreeCtrlPanel(nb, log)
272 nb.AddPage(win, "TreeCtrl")
273
274 win = ColoredPanel(nb, wxRED)
275 nb.AddPage(win, "Red")
276
277 win = ColoredPanel(nb, wxGREEN)
278 nb.AddPage(win, "Green")
279
280 win = ColoredPanel(nb, wxCYAN)
281 nb.AddPage(win, "Cyan")
282
283 win = ColoredPanel(nb, wxWHITE)
284 nb.AddPage(win, "White")
285
286 win = ColoredPanel(nb, wxBLACK)
287 nb.AddPage(win, "Black")
288
289 win = ColoredPanel(nb, wxNamedColour('MIDNIGHT BLUE'))
290 nb.AddPage(win, "MIDNIGHT BLUE")
291
292 win = ColoredPanel(nb, wxNamedColour('INDIAN RED'))
293 nb.AddPage(win, "INDIAN RED")
294
295
296 nb.SetSelection(0)
297 self.SetSize(wxSize(350, 300)) # force a redraw so the notebook will draw
298
299
300 def OnCloseWindow(self, event):
301 self.Destroy()
302
303 #---------------------------------------------------------------------------
304
305 class TestSplitterWindow(wxFrame):
306 def __init__(self, parent):
307 wxFrame.__init__(self, parent, -1, 'Test wxSplitterWindow',
308 wxPyDefaultPosition, wxSize(500, 300))
309
310 splitter = wxSplitterWindow(self, -1)
311
312 p1 = ColoredPanel(splitter, wxRED)
313 wxStaticText(p1, -1, "Panel One", wxPoint(5,5)).SetBackgroundColour(wxRED)
314
315 p2 = ColoredPanel(splitter, wxBLUE)
316 wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
317
318 splitter.SplitVertically(p1, p2)
319
320
321 def OnCloseWindow(self, event):
322 self.Destroy()
323
324
325 #---------------------------------------------------------------------------
326
327 class CustomStatusBar(wxStatusBar):
328 def __init__(self, parent):
329 wxStatusBar.__init__(self, parent, -1)
330 self.SetFieldsCount(3)
331
332 self.SetStatusText("A Custom StatusBar...", 0)
333
334 self.cb = wxCheckBox(self, 1001, "toggle clock")
335 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
336 self.cb.SetValue(true)
337
338 # figure out how tall to make it.
339 dc = wxClientDC(self)
340 dc.SetFont(self.GetFont())
341 (w,h, d,e) = dc.GetTextExtent('X')
342 h = int(h * 1.8)
343 self.SetSize(wxSize(100, h))
344
345 # start our timer
346 self.timer = wxPyTimer(self.Notify)
347 self.timer.Start(1000)
348 self.Notify()
349
350
351 # Time-out handler
352 def Notify(self):
353 t = time.localtime(time.time())
354 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
355 self.SetStatusText(st, 2)
356
357 # the checkbox was clicked
358 def OnToggleClock(self, event):
359 if self.cb.GetValue():
360 self.timer.Start(1000)
361 self.Notify()
362 else:
363 self.timer.Stop()
364
365 # reposition the checkbox
366 def OnSize(self, event):
367 rect = self.GetFieldRect(1)
368 print "%s, %s" % (rect.x, rect.y)
369 self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
370 self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
371
372
373
374 class TestCustomStatusBar(wxFrame):
375 def __init__(self, parent):
376 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
377 wxPyDefaultPosition, wxSize(500, 300))
378 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
379
380 self.sb = CustomStatusBar(self)
381 self.SetStatusBar(self.sb)
382
383 def OnCloseWindow(self, event):
384 self.sb.timer.Stop()
385 self.Destroy()
386
387
388 #---------------------------------------------------------------------------
389
390 class TestToolBar(wxFrame):
391 def __init__(self, parent, log):
392 wxFrame.__init__(self, parent, -1, 'Test ToolBar',
393 wxPyDefaultPosition, wxSize(500, 300))
394 self.log = log
395
396 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
397
398 tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
399 #tb = wxToolBar(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
400 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
401 #self.SetToolBar(tb)
402
403 tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
404 wxNullBitmap, false, -1, -1, "New")
405 EVT_TOOL(self, 10, self.OnToolClick)
406 EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
407
408 tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
409 wxNullBitmap, false, -1, -1, "Open")
410 EVT_TOOL(self, 20, self.OnToolClick)
411 EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
412
413 tb.AddSeparator()
414 tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
415 wxNullBitmap, false, -1, -1, "Copy")
416 EVT_TOOL(self, 30, self.OnToolClick)
417 EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
418
419 tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
420 wxNullBitmap, false, -1, -1, "Paste")
421 EVT_TOOL(self, 40, self.OnToolClick)
422 EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
423
424 tb.AddSeparator()
425
426 tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
427 wxNullBitmap, true, -1, -1, "Toggle this")
428 EVT_TOOL(self, 50, self.OnToolClick)
429 EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
430
431 tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
432 wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
433 true, -1, -1, "Toggle with 2 bitmaps")
434 EVT_TOOL(self, 60, self.OnToolClick)
435 EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
436
437 tb.Realize()
438
439
440 def OnCloseWindow(self, event):
441 self.Destroy()
442
443 def OnToolClick(self, event):
444 self.log.WriteText("tool %s clicked\n" % event.GetId())
445
446 def OnToolRClick(self, event):
447 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
448
449
450 #---------------------------------------------------------------------------
451
452 class TestTreeCtrlPanel(wxPanel):
453 def __init__(self, parent, log):
454 wxPanel.__init__(self, parent, -1)
455
456 self.log = log
457 tID = 1101
458
459 self.tree = wxTreeCtrl(self, tID)
460 root = self.tree.AddRoot("The Root Item")
461 for x in range(10):
462 child = self.tree.AppendItem(root, "Item %d" % x)
463 for y in range(5):
464 last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
465
466 self.tree.Expand(root)
467 EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
468 EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
469 EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
470
471
472 def OnSize(self, event):
473 w,h = self.GetClientSizeTuple()
474 self.tree.SetDimensions(0, 0, w, h)
475
476
477 def OnItemExpanded(self, event):
478 item = event.GetItem()
479 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
480
481 def OnItemCollapsed(self, event):
482 item = event.GetItem()
483 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
484
485 def OnSelChanged(self, event):
486 item = event.GetItem()
487 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
488
489
490
491
492 class TestTreeCtrl(wxFrame):
493 def __init__(self, parent, log):
494 wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
495 wxPyDefaultPosition, wxSize(250, 300))
496
497 p = TestTreeCtrlPanel(self, log)
498
499
500 #---------------------------------------------------------------------------
501 #---------------------------------------------------------------------------
502 #---------------------------------------------------------------------------
503
504 class AppFrame(wxFrame):
505 def __init__(self, parent, id, title):
506 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
507 wxSize(420, 200))
508 if wxPlatform == '__WXMSW__':
509 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
510 self.SetIcon(self.icon)
511
512 self.mainmenu = wxMenuBar()
513 menu = wxMenu()
514 menu.Append(200, 'E&xit', 'Get the heck outta here!')
515 EVT_MENU(self, 200, self.OnFileExit)
516 self.mainmenu.Append(menu, '&File')
517
518 menu = self.MakeTestsMenu()
519 self.mainmenu.Append(menu, '&Tests')
520 self.SetMenuBar(self.mainmenu)
521
522 self.log = wxTextCtrl(self, -1, '', wxPyDefaultPosition, wxPyDefaultSize,
523 wxTE_MULTILINE|wxTE_READONLY)
524 self.log.WriteText('Test 4:\n')
525 (w, self.charHeight) = self.log.GetTextExtent('X')
526
527
528 def MakeTestsMenu(self):
529 menu = wxMenu()
530
531 mID = NewId()
532 menu.Append(mID, '&Simple Controls')
533 EVT_MENU(self, mID, self.OnTestSimpleControls)
534
535 mID = NewId()
536 menu.Append(mID, '&Timer', '', true)
537 EVT_MENU(self, mID, self.OnTestTimer)
538 self.timerID = mID
539 self.timer = None
540
541 mID = NewId()
542 menu.Append(mID, '&Layout Constraints')
543 EVT_MENU(self, mID, self.OnTestLayoutConstraints)
544
545 mID = NewId()
546 menu.Append(mID, '&Grid')
547 EVT_MENU(self, mID, self.OnTestGrid)
548
549
550 smenu = wxMenu() # make a sub-menu
551
552 mID = NewId()
553 smenu.Append(mID, '&Colour')
554 EVT_MENU(self, mID, self.OnTestColourDlg)
555
556 mID = NewId()
557 smenu.Append(mID, '&Directory')
558 EVT_MENU(self, mID, self.OnTestDirDlg)
559
560 mID = NewId()
561 smenu.Append(mID, '&File')
562 EVT_MENU(self, mID, self.OnTestFileDlg)
563
564 mID = NewId()
565 smenu.Append(mID, '&Single Choice')
566 EVT_MENU(self, mID, self.OnTestSingleChoiceDlg)
567
568 mID = NewId()
569 smenu.Append(mID, '&TextEntry')
570 EVT_MENU(self, mID, self.OnTestTextEntryDlg)
571
572 mID = NewId()
573 smenu.Append(mID, '&Font')
574 EVT_MENU(self, mID, self.OnTestFontDlg)
575
576 mID = NewId()
577 smenu.Append(mID, '&PageSetup')
578 EVT_MENU(self, mID, self.OnTestPageSetupDlg)
579
580 mID = NewId()
581 smenu.Append(mID, '&Print')
582 EVT_MENU(self, mID, self.OnTestPrintDlg)
583
584 mID = NewId()
585 smenu.Append(mID, '&Message')
586 EVT_MENU(self, mID, self.OnTestMessageDlg)
587
588
589 menu.AppendMenu(NewId(), '&Common Dialogs', smenu)
590
591
592 mID = NewId()
593 menu.Append(mID, '&Notebook')
594 EVT_MENU(self, mID, self.OnTestNotebook)
595
596 mID = NewId()
597 menu.Append(mID, '&Splitter Window')
598 EVT_MENU(self, mID, self.OnTestSplitter)
599
600 mID = NewId()
601 menu.Append(mID, '&Custom StatusBar')
602 EVT_MENU(self, mID, self.OnTestCustomStatusBar)
603
604 mID = NewId()
605 menu.Append(mID, '&ToolBar')
606 EVT_MENU(self, mID, self.OnTestToolBar)
607
608 mID = NewId()
609 menu.Append(mID, 'T&ree Control')
610 EVT_MENU(self, mID, self.OnTestTreeCtrl)
611
612 return menu
613
614
615
616
617 def WriteText(self, str):
618 self.log.WriteText(str)
619 if wxPlatform == '__WXMSW__':
620 w, h = self.log.GetClientSizeTuple()
621 numLines = h/self.charHeight
622 x, y = self.log.PositionToXY(self.log.GetLastPosition())
623 self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
624
625 def OnFileExit(self, event):
626 self.Close()
627
628 def OnCloseWindow(self, event):
629 self.Destroy()
630
631
632
633
634 def OnTestSimpleControls(self, event):
635 dlg = TestSimpleControlsDlg(self, self)
636 dlg.Centre()
637 dlg.ShowModal()
638 dlg.Destroy()
639
640 def OnTestTimer(self, event):
641 if self.timer:
642 self.mainmenu.Check(self.timerID, false)
643 self.timer.Stop()
644 self.timer = None
645 else:
646 self.mainmenu.Check(self.timerID, true)
647 self.timer = TestTimer(self)
648 self.timer.Start(1000)
649
650 def OnTestLayoutConstraints(self, event):
651 win = TestLayoutConstraints(self)
652 win.Show(true)
653
654 def OnTestGrid(self, event):
655 win = TestGrid(self, self)
656 win.Show(true)
657 win.SetSize(wxSize(505, 300)) # have to force a resize, or the grid doesn't
658 # show up for some reason....
659
660 def OnTestColourDlg(self, event):
661 data = wxColourData()
662 data.SetChooseFull(true)
663 dlg = wxColourDialog(self, data)
664 if dlg.ShowModal() == wxID_OK:
665 data = dlg.GetColourData()
666 self.log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
667 dlg.Destroy()
668
669 def OnTestDirDlg(self, event):
670 dlg = wxDirDialog(self)
671 if dlg.ShowModal() == wxID_OK:
672 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
673 dlg.Destroy()
674
675 def OnTestFileDlg(self, event):
676 dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
677 if dlg.ShowModal() == wxID_OK:
678 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
679 dlg.Destroy()
680
681 def OnTestSingleChoiceDlg(self, event):
682 dlg = wxSingleChoiceDialog(self, 'Test Single Choice', 'The Caption',
683 ['zero', 'one', 'two', 'three', 'four', 'five',
684 'six', 'seven', 'eight'])
685 if dlg.ShowModal() == wxID_OK:
686 self.log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
687 dlg.Destroy()
688
689 def OnTestTextEntryDlg(self, event):
690 dlg = wxTextEntryDialog(self, 'What is your favorite programming language?',
691 'Duh??', 'Python')
692 #dlg.SetValue("Python is the best!") #### this doesn't work?
693 if dlg.ShowModal() == wxID_OK:
694 self.log.WriteText('You entered: %s\n' % dlg.GetValue())
695 dlg.Destroy()
696
697
698 def OnTestFontDlg(self, event):
699 dlg = wxFontDialog(self)
700 if dlg.ShowModal() == wxID_OK:
701 data = dlg.GetFontData()
702 font = data.GetChosenFont()
703 self.log.WriteText('You selected: "%s", %d points, color %s\n' %
704 (font.GetFaceName(), font.GetPointSize(),
705 data.GetColour().Get()))
706 dlg.Destroy()
707
708
709 def OnTestPageSetupDlg(self, event):
710 data = wxPageSetupData()
711 data.SetMarginTopLeft(wxPoint(50,50))
712 data.SetMarginBottomRight(wxPoint(50,50))
713 dlg = wxPageSetupDialog(self, data)
714 if dlg.ShowModal() == wxID_OK:
715 data = dlg.GetPageSetupData()
716 tl = data.GetMarginTopLeft()
717 br = data.GetMarginBottomRight()
718 self.log.WriteText('Margins are: %s %s\n' % (str(tl), str(br)))
719 dlg.Destroy()
720
721 def OnTestPrintDlg(self, event):
722 data = wxPrintData()
723 data.EnablePrintToFile(true)
724 data.EnablePageNumbers(true)
725 data.EnableSelection(true)
726 dlg = wxPrintDialog(self, data)
727 if dlg.ShowModal() == wxID_OK:
728 self.log.WriteText('\n')
729 dlg.Destroy()
730
731 def OnTestMessageDlg(self, event):
732 dlg = wxMessageDialog(self, 'Hello from Python and wxWindows!',
733 'A Message Box', wxOK | wxICON_INFORMATION)
734 dlg.ShowModal()
735 dlg.Destroy()
736
737
738 def OnTestNotebook(self, event):
739 win = TestNotebookWindow(self, self)
740 win.Show(true)
741
742 def OnTestSplitter(self, event):
743 win = TestSplitterWindow(self)
744 win.Show(true)
745
746 def OnTestCustomStatusBar(self, event):
747 win = TestCustomStatusBar(self)
748 win.Show(true)
749
750 def OnTestToolBar(self, event):
751 win = TestToolBar(self, self)
752 win.Show(true)
753
754 def OnTestTreeCtrl(self, event):
755 win = TestTreeCtrl(self, self)
756 win.Show(true)
757
758
759 #---------------------------------------------------------------------------
760
761
762 class MyApp(wxApp):
763 def OnInit(self):
764 frame = AppFrame(NULL, -1, "Test 4: (lots of little tests...)")
765 frame.Show(true)
766 self.SetTopWindow(frame)
767 return true
768
769 #---------------------------------------------------------------------------
770
771
772 def main():
773 app = MyApp(0)
774 app.MainLoop()
775
776
777 def t():
778 import pdb
779 pdb.run('main()')
780
781
782 # for focused testing...
783 def main2():
784 class T2App(wxApp):
785 def OnInit(self):
786 frame = TestLayoutConstraints(NULL)
787 frame.Show(true)
788 self.SetTopWindow(frame)
789 return true
790
791 app = T2App(0)
792 app.MainLoop()
793
794 def t2():
795 import pdb
796 pdb.run('main2()')
797
798
799
800 if __name__ == '__main__':
801 main()
802
803
804 #----------------------------------------------------------------------------
805 #
806 # $Log$
807 # Revision 1.11 1999/01/29 16:17:59 HH
808 # In test4's toolbar sample, changed NULL to wxNullBitmap to prevent SIGSEVS
809 # with wxGTK. The sample works now.
810 #
811 # Revision 1.10 1998/12/16 22:12:47 RD
812 #
813 # Tweaks needed to be able to build wxPython with wxGTK.
814 #
815 # Revision 1.9 1998/12/15 20:44:35 RD
816 # Changed the import semantics from "from wxPython import *" to "from
817 # wxPython.wx import *" This is for people who are worried about
818 # namespace pollution, they can use "from wxPython import wx" and then
819 # prefix all the wxPython identifiers with "wx."
820 #
821 # Added wxTaskbarIcon for wxMSW.
822 #
823 # Made the events work for wxGrid.
824 #
825 # Added wxConfig.
826 #
827 # Added wxMiniFrame for wxGTK, (untested.)
828 #
829 # Changed many of the args and return values that were pointers to gdi
830 # objects to references to reflect changes in the wxWindows API.
831 #
832 # Other assorted fixes and additions.
833 #
834 # Revision 1.8 1998/11/25 08:47:11 RD
835 #
836 # Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
837 # Added events for wxGrid
838 # Other various fixes and additions
839 #
840 # Revision 1.7 1998/11/11 03:13:19 RD
841 #
842 # Additions for wxTreeCtrl
843 #
844 # Revision 1.6 1998/10/20 06:45:33 RD
845 # New wxTreeCtrl wrappers (untested)
846 # some changes in helpers
847 # etc.
848 #
849 # Revision 1.5 1998/10/02 06:42:28 RD
850 #
851 # Version 0.4 of wxPython for MSW.
852 #
853 # Revision 1.4 1998/08/27 21:59:51 RD
854 # Some chicken-and-egg problems solved for wxPython on wxGTK
855 #
856 # Revision 1.3 1998/08/27 00:01:17 RD
857 # - more tweaks
858 # - have discovered some problems but not yet discovered solutions...
859 #
860 # Revision 1.2 1998/08/22 19:51:18 RD
861 # some tweaks for wxGTK
862 #
863 # Revision 1.1 1998/08/09 08:28:05 RD
864 # Initial version
865 #
866 #