]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test4.py
fix for stupid segfault
[wxWidgets.git] / 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 wxDefaultPosition, wxSize(350, 400))
26
27
28 sampleList = ["zero", "one", "two", "three", "four", "five",
29 "six", "seven", "eight", "nine", "ten"]
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), wxDefaultSize,
44 sampleList, 3, wxRA_SPECIFY_COLS | 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), #wxDefaultSize,
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, -1),
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), wxSize(95, 80),
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), wxDefaultSize).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 wxDefaultPosition, wxSize(500, 300))
118
119 self.SetAutoLayout(true)
120 EVT_BUTTON(self, 100, self.OnButton)
121
122 self.panelA = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
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, wxDefaultPosition, wxDefaultSize,
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, wxDefaultPosition, wxDefaultSize,
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, wxDefaultPosition, wxDefaultSize,
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 wxDefaultPosition, 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 wxDefaultPosition, wxDefaultSize, 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
255 nb = wxNotebook(self, -1, wxPoint(0,0), self.GetClientSize())
256
257 win = ColoredPanel(nb, wxBLUE)
258 nb.AddPage(win, "Blue")
259 st = wxStaticText(win, -1,
260 "You can put nearly any type of window here!",
261 wxPoint(10, 10))
262 st.SetForegroundColour(wxWHITE)
263 st.SetBackgroundColour(wxBLUE)
264 st = wxStaticText(win, -1,
265 "Check the next tab for an example...",
266 wxPoint(10, 30))
267 st.SetForegroundColour(wxWHITE)
268 st.SetBackgroundColour(wxBLUE)
269
270 win = TestTreeCtrlPanel(nb, log)
271 nb.AddPage(win, "TreeCtrl")
272
273 win = TestListCtrlPanel(nb, log)
274 nb.AddPage(win, "ListCtrl")
275
276 win = ColoredPanel(nb, wxRED)
277 nb.AddPage(win, "Red")
278
279 win = ColoredPanel(nb, wxGREEN)
280 nb.AddPage(win, "Green")
281
282 win = ColoredPanel(nb, wxCYAN)
283 nb.AddPage(win, "Cyan")
284
285 win = ColoredPanel(nb, wxWHITE)
286 nb.AddPage(win, "White")
287
288 win = ColoredPanel(nb, wxBLACK)
289 nb.AddPage(win, "Black")
290
291 win = ColoredPanel(nb, wxNamedColour('MIDNIGHT BLUE'))
292 nb.AddPage(win, "MIDNIGHT BLUE")
293
294 win = ColoredPanel(nb, wxNamedColour('INDIAN RED'))
295 nb.AddPage(win, "INDIAN RED")
296
297 nb.SetSelection(0)
298 self.SetSize(wxSize(350, 300))
299
300
301 def OnCloseWindow(self, event):
302 self.Destroy()
303
304 #---------------------------------------------------------------------------
305
306 class TestSplitterWindow(wxFrame):
307 def __init__(self, parent):
308 wxFrame.__init__(self, parent, -1, 'Test wxSplitterWindow',
309 wxDefaultPosition, wxSize(500, 300))
310
311 splitter = wxSplitterWindow(self, -1)
312
313 p1 = ColoredPanel(splitter, wxRED)
314 wxStaticText(p1, -1, "Panel One", wxPoint(5,5)).SetBackgroundColour(wxRED)
315
316 p2 = ColoredPanel(splitter, wxBLUE)
317 wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
318
319 splitter.SplitVertically(p1, p2)
320
321
322 def OnCloseWindow(self, event):
323 self.Destroy()
324
325
326 #---------------------------------------------------------------------------
327
328 class CustomStatusBar(wxStatusBar):
329 def __init__(self, parent):
330 wxStatusBar.__init__(self, parent, -1)
331 self.SetFieldsCount(3)
332
333 self.SetStatusText("A Custom StatusBar...", 0)
334
335 self.cb = wxCheckBox(self, 1001, "toggle clock")
336 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
337 self.cb.SetValue(true)
338
339 # figure out how tall to make it.
340 dc = wxClientDC(self)
341 dc.SetFont(self.GetFont())
342 (w,h) = dc.GetTextExtent('X')
343 h = int(h * 1.8)
344 self.SetSize(wxSize(100, h))
345
346 # start our timer
347 self.timer = wxPyTimer(self.Notify)
348 self.timer.Start(1000)
349 self.Notify()
350
351
352 # Time-out handler
353 def Notify(self):
354 t = time.localtime(time.time())
355 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
356 self.SetStatusText(st, 2)
357
358 # the checkbox was clicked
359 def OnToggleClock(self, event):
360 if self.cb.GetValue():
361 self.timer.Start(1000)
362 self.Notify()
363 else:
364 self.timer.Stop()
365
366 # reposition the checkbox
367 def OnSize(self, event):
368 rect = self.GetFieldRect(1)
369 print "%s, %s" % (rect.x, rect.y)
370 self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
371 self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
372
373
374
375 class TestCustomStatusBar(wxFrame):
376 def __init__(self, parent):
377 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
378 wxDefaultPosition, wxSize(500, 300))
379 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
380
381 self.sb = CustomStatusBar(self)
382 self.SetStatusBar(self.sb)
383
384 def OnCloseWindow(self, event):
385 self.sb.timer.Stop()
386 self.Destroy()
387
388
389 #---------------------------------------------------------------------------
390
391 class TestToolBar(wxFrame):
392 def __init__(self, parent, log):
393 wxFrame.__init__(self, parent, -1, 'Test ToolBar',
394 wxDefaultPosition, wxSize(500, 300))
395 self.log = log
396
397 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
398
399 tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
400 #tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize,
401 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
402 #self.SetToolBar(tb)
403
404 self.CreateStatusBar()
405
406 tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
407 wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
408 EVT_TOOL(self, 10, self.OnToolClick)
409 EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
410
411 tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
412 wxNullBitmap, false, -1, -1, "Open")
413 EVT_TOOL(self, 20, self.OnToolClick)
414 EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
415
416 tb.AddSeparator()
417 tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
418 wxNullBitmap, false, -1, -1, "Copy")
419 EVT_TOOL(self, 30, self.OnToolClick)
420 EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
421
422 tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
423 wxNullBitmap, false, -1, -1, "Paste")
424 EVT_TOOL(self, 40, self.OnToolClick)
425 EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
426
427 tb.AddSeparator()
428
429 tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
430 wxNullBitmap, true, -1, -1, "Toggle this")
431 EVT_TOOL(self, 50, self.OnToolClick)
432 EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
433
434 tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
435 wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
436 true, -1, -1, "Toggle with 2 bitmaps")
437 EVT_TOOL(self, 60, self.OnToolClick)
438 EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
439
440 tb.Realize()
441
442
443 def OnCloseWindow(self, event):
444 self.Destroy()
445
446 def OnToolClick(self, event):
447 self.log.WriteText("tool %s clicked\n" % event.GetId())
448
449 def OnToolRClick(self, event):
450 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
451
452
453 #---------------------------------------------------------------------------
454
455 class TestTreeCtrlPanel(wxPanel):
456 def __init__(self, parent, log):
457 wxPanel.__init__(self, parent, -1)
458
459 self.log = log
460 tID = 1101
461
462 self.tree = wxTreeCtrl(self, tID)
463 root = self.tree.AddRoot("The Root Item")
464 for x in range(10):
465 child = self.tree.AppendItem(root, "Item %d" % x)
466 for y in range(5):
467 last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
468
469 self.tree.Expand(root)
470 EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
471 EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
472 EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
473
474
475 def OnSize(self, event):
476 w,h = self.GetClientSizeTuple()
477 self.tree.SetDimensions(0, 0, w, h)
478
479
480 def OnItemExpanded(self, event):
481 item = event.GetItem()
482 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
483
484 def OnItemCollapsed(self, event):
485 item = event.GetItem()
486 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
487
488 def OnSelChanged(self, event):
489 item = event.GetItem()
490 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
491
492
493
494
495 class TestTreeCtrl(wxFrame):
496 def __init__(self, parent, log):
497 wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
498 wxDefaultPosition, wxSize(250, 300))
499
500 p = TestTreeCtrlPanel(self, log)
501
502
503 #---------------------------------------------------------------------------
504
505 class TestListCtrlPanel(wxPanel):
506 def __init__(self, parent, log):
507 wxPanel.__init__(self, parent, -1)
508
509 self.log = log
510 tID = 1101
511
512 self.il = wxImageList(16, 16)
513 idx1 = self.il.Add(wxNoRefBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP))
514
515 self.list = wxListCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
516 wxLC_REPORT|wxSUNKEN_BORDER)
517 self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
518
519 #self.list.SetToolTip(wxToolTip("This is a ToolTip!"))
520 #wxToolTip_Enable(true)
521
522 self.list.InsertColumn(0, "Column 0")
523 self.list.InsertColumn(1, "Column 1")
524 self.list.InsertColumn(2, "One More Column (2)")
525 for x in range(50):
526 self.list.InsertImageStringItem(x, "This is item %d" % x, idx1)
527 self.list.SetStringItem(x, 1, "Col 1, item %d" % x)
528 self.list.SetStringItem(x, 2, "item %d in column 2" % x)
529
530 self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
531 self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
532 self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
533
534
535 def OnSize(self, event):
536 w,h = self.GetClientSizeTuple()
537 self.list.SetDimensions(0, 0, w, h)
538
539
540
541
542 class TestListCtrl(wxFrame):
543 def __init__(self, parent, log):
544 wxFrame.__init__(self, parent, -1, 'Test ListCtrl',
545 wxDefaultPosition, wxSize(250, 300))
546
547 p = TestListCtrlPanel(self, log)
548
549
550 #---------------------------------------------------------------------------
551
552 class TestSashWindow(wxMDIParentFrame):
553 NEW_WINDOW = 5000
554 TOGGLE_WINDOW = 5001
555 QUIT = 5002
556 ID_WINDOW_TOP = 5100
557 ID_WINDOW_LEFT1 = 5101
558 ID_WINDOW_LEFT2 = 5102
559 ID_WINDOW_BOTTOM = 5103
560
561
562 def __init__(self, parent, log):
563 wxMDIParentFrame.__init__(self, parent, -1, 'Test Sash Window',
564 wxDefaultPosition, wxSize(250, 300))
565
566 self.log = log
567 menu = wxMenu()
568 menu.Append(self.NEW_WINDOW, "&New Window")
569 menu.Append(self.TOGGLE_WINDOW, "&Toggle window")
570 menu.Append(self.QUIT, "E&xit")
571
572 menubar = wxMenuBar()
573 menubar.Append(menu, "&File")
574
575 self.SetMenuBar(menubar)
576 self.CreateStatusBar()
577
578 EVT_MENU(self, self.NEW_WINDOW, self.OnNewWindow)
579 EVT_MENU(self, self.TOGGLE_WINDOW, self.OnToggleWindow)
580 EVT_MENU(self, self.QUIT, self.OnQuit)
581
582 EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
583 self.ID_WINDOW_BOTTOM, self.OnSashDrag)
584
585
586 # Create some layout windows
587 # A window like a toolbar
588 win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, wxDefaultPosition,
589 wxSize(200, 30), wxNO_BORDER|wxSW_3D)
590 win.SetDefaultSize(wxSize(1000, 30))
591 win.SetOrientation(wxLAYOUT_HORIZONTAL)
592 win.SetAlignment(wxLAYOUT_TOP)
593 win.SetBackgroundColour(wxColour(255, 0, 0))
594 win.SetSashVisible(wxSASH_BOTTOM, true)
595
596 self.topWindow = win
597
598
599 # A window like a statusbar
600 win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM,
601 wxDefaultPosition, wxSize(200, 30),
602 wxNO_BORDER|wxSW_3D)
603 win.SetDefaultSize(wxSize(1000, 30))
604 win.SetOrientation(wxLAYOUT_HORIZONTAL)
605 win.SetAlignment(wxLAYOUT_BOTTOM)
606 win.SetBackgroundColour(wxColour(0, 0, 255))
607 win.SetSashVisible(wxSASH_TOP, true)
608
609 self.bottomWindow = win
610
611
612 # A window to the left of the client window
613 win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1,
614 wxDefaultPosition, wxSize(200, 30),
615 wxNO_BORDER|wxSW_3D)
616 win.SetDefaultSize(wxSize(120, 1000))
617 win.SetOrientation(wxLAYOUT_VERTICAL)
618 win.SetAlignment(wxLAYOUT_LEFT)
619 win.SetBackgroundColour(wxColour(0, 255, 0))
620 win.SetSashVisible(wxSASH_RIGHT, TRUE)
621 win.SetExtraBorderSize(10)
622
623 textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
624 wxTE_MULTILINE|wxSUNKEN_BORDER)
625 textWindow.SetValue("A help window")
626
627 self.leftWindow1 = win
628
629
630 # Another window to the left of the client window
631 win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2,
632 wxDefaultPosition, wxSize(200, 30),
633 wxNO_BORDER|wxSW_3D)
634 win.SetDefaultSize(wxSize(120, 1000))
635 win.SetOrientation(wxLAYOUT_VERTICAL)
636 win.SetAlignment(wxLAYOUT_LEFT)
637 win.SetBackgroundColour(wxColour(0, 255, 255))
638 win.SetSashVisible(wxSASH_RIGHT, TRUE)
639
640 self.leftWindow2 = win
641
642
643 def OnNewWindow(self, event):
644 pass
645
646 def OnToggleWindow(self, event):
647 pass
648
649 def OnQuit(self, event):
650 self.Close(true)
651
652 def OnSashDrag(self, event):
653 if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
654 return
655
656 eID = event.GetId()
657 if eID == self.ID_WINDOW_TOP:
658 self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
659
660 elif eID == self.ID_WINDOW_LEFT1:
661 self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
662
663
664 elif eID == self.ID_WINDOW_LEFT2:
665 self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
666
667 elif eID == self.ID_WINDOW_BOTTOM:
668 self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
669
670 wxLayoutAlgorithm().LayoutMDIFrame(self)
671
672 # Leaves bits of itself behind sometimes
673 self.GetClientWindow().Refresh()
674
675
676 def OnSize(self, event):
677 wxLayoutAlgorithm().LayoutMDIFrame(self)
678
679 #---------------------------------------------------------------------------
680 #---------------------------------------------------------------------------
681 #---------------------------------------------------------------------------
682
683 class AppFrame(wxFrame):
684 def __init__(self, parent, id, title):
685 wxFrame.__init__(self, parent, id, title, wxDefaultPosition,
686 wxSize(420, 200))
687 if wxPlatform == '__WXMSW__':
688 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
689 self.SetIcon(self.icon)
690
691 self.mainmenu = wxMenuBar()
692 menu = wxMenu()
693 menu.Append(200, 'E&xit', 'Get the heck outta here!')
694 EVT_MENU(self, 200, self.OnFileExit)
695 self.mainmenu.Append(menu, '&File')
696
697 menu = self.MakeTestsMenu()
698 self.mainmenu.Append(menu, '&Tests')
699 self.SetMenuBar(self.mainmenu)
700
701 self.log = wxTextCtrl(self, -1, '', wxDefaultPosition, wxDefaultSize,
702 wxTE_MULTILINE|wxTE_READONLY)
703 self.log.WriteText('Test 4:\n')
704 (w, self.charHeight) = self.log.GetTextExtent('X')
705
706
707 def MakeTestsMenu(self):
708 menu = wxMenu()
709
710 mID = NewId()
711 menu.Append(mID, '&Simple Controls')
712 EVT_MENU(self, mID, self.OnTestSimpleControls)
713
714 mID = NewId()
715 menu.Append(mID, '&Timer', '', true)
716 EVT_MENU(self, mID, self.OnTestTimer)
717 self.timerID = mID
718 self.timer = None
719
720 mID = NewId()
721 menu.Append(mID, '&Layout Constraints')
722 EVT_MENU(self, mID, self.OnTestLayoutConstraints)
723
724 mID = NewId()
725 menu.Append(mID, '&Grid')
726 EVT_MENU(self, mID, self.OnTestGrid)
727
728
729 smenu = wxMenu() # make a sub-menu
730
731 mID = NewId()
732 smenu.Append(mID, '&Colour')
733 EVT_MENU(self, mID, self.OnTestColourDlg)
734
735 mID = NewId()
736 smenu.Append(mID, '&Directory')
737 EVT_MENU(self, mID, self.OnTestDirDlg)
738
739 mID = NewId()
740 smenu.Append(mID, '&File')
741 EVT_MENU(self, mID, self.OnTestFileDlg)
742
743 mID = NewId()
744 smenu.Append(mID, '&Single Choice')
745 EVT_MENU(self, mID, self.OnTestSingleChoiceDlg)
746
747 mID = NewId()
748 smenu.Append(mID, '&TextEntry')
749 EVT_MENU(self, mID, self.OnTestTextEntryDlg)
750
751 mID = NewId()
752 smenu.Append(mID, '&Font')
753 EVT_MENU(self, mID, self.OnTestFontDlg)
754
755 mID = NewId()
756 smenu.Append(mID, '&PageSetup')
757 EVT_MENU(self, mID, self.OnTestPageSetupDlg)
758
759 mID = NewId()
760 smenu.Append(mID, '&Print')
761 EVT_MENU(self, mID, self.OnTestPrintDlg)
762
763 mID = NewId()
764 smenu.Append(mID, '&Message')
765 EVT_MENU(self, mID, self.OnTestMessageDlg)
766
767
768 menu.AppendMenu(NewId(), '&Common Dialogs', smenu)
769
770
771 mID = NewId()
772 menu.Append(mID, '&Notebook')
773 EVT_MENU(self, mID, self.OnTestNotebook)
774
775 mID = NewId()
776 menu.Append(mID, '&Splitter Window')
777 EVT_MENU(self, mID, self.OnTestSplitter)
778
779 mID = NewId()
780 menu.Append(mID, '&Custom StatusBar')
781 EVT_MENU(self, mID, self.OnTestCustomStatusBar)
782
783 mID = NewId()
784 menu.Append(mID, '&ToolBar')
785 EVT_MENU(self, mID, self.OnTestToolBar)
786
787 mID = NewId()
788 menu.Append(mID, 'T&ree Control')
789 EVT_MENU(self, mID, self.OnTestTreeCtrl)
790
791 mID = NewId()
792 menu.Append(mID, '&List Control')
793 EVT_MENU(self, mID, self.OnTestListCtrl)
794
795 mID = NewId()
796 menu.Append(mID, 'S&ash Window and Layout Algorithm')
797 EVT_MENU(self, mID, self.OnTestSashWindow)
798
799 return menu
800
801
802
803
804 def WriteText(self, str):
805 self.log.WriteText(str)
806 if wxPlatform == '__WXMSW__':
807 w, h = self.log.GetClientSizeTuple()
808 numLines = h/self.charHeight
809 x, y = self.log.PositionToXY(self.log.GetLastPosition())
810 self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
811
812 def OnFileExit(self, event):
813 self.Close()
814
815 def OnCloseWindow(self, event):
816 self.Destroy()
817
818
819
820
821 def OnTestSimpleControls(self, event):
822 dlg = TestSimpleControlsDlg(self, self)
823 dlg.Centre()
824 dlg.ShowModal()
825 dlg.Destroy()
826
827 def OnTestTimer(self, event):
828 if self.timer:
829 self.mainmenu.Check(self.timerID, false)
830 self.timer.Stop()
831 self.timer = None
832 else:
833 self.mainmenu.Check(self.timerID, true)
834 self.timer = TestTimer(self)
835 self.timer.Start(1000)
836
837 def OnTestLayoutConstraints(self, event):
838 win = TestLayoutConstraints(self)
839 win.Show(true)
840
841 def OnTestGrid(self, event):
842 win = TestGrid(self, self)
843 win.Show(true)
844 win.SetSize(wxSize(505, 300)) # have to force a resize, or the grid doesn't
845 # show up for some reason....
846
847 def OnTestColourDlg(self, event):
848 data = wxColourData()
849 data.SetChooseFull(true)
850 dlg = wxColourDialog(self, data)
851 if dlg.ShowModal() == wxID_OK:
852 data = dlg.GetColourData()
853 self.log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
854 dlg.Destroy()
855
856 def OnTestDirDlg(self, event):
857 dlg = wxDirDialog(self)
858 if dlg.ShowModal() == wxID_OK:
859 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
860 dlg.Destroy()
861
862 def OnTestFileDlg(self, event):
863 dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
864 if dlg.ShowModal() == wxID_OK:
865 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
866 dlg.Destroy()
867
868 def OnTestSingleChoiceDlg(self, event):
869 dlg = wxSingleChoiceDialog(self, 'Test Single Choice', 'The Caption',
870 ['zero', 'one', 'two', 'three', 'four', 'five',
871 'six', 'seven', 'eight'])
872 if dlg.ShowModal() == wxID_OK:
873 self.log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
874 dlg.Destroy()
875
876 def OnTestTextEntryDlg(self, event):
877 dlg = wxTextEntryDialog(self, 'What is your favorite programming language?',
878 'Duh??', 'Python')
879 #dlg.SetValue("Python is the best!") #### this doesn't work?
880 if dlg.ShowModal() == wxID_OK:
881 self.log.WriteText('You entered: %s\n' % dlg.GetValue())
882 dlg.Destroy()
883
884
885 def OnTestFontDlg(self, event):
886 dlg = wxFontDialog(self)
887 if dlg.ShowModal() == wxID_OK:
888 data = dlg.GetFontData()
889 font = data.GetChosenFont()
890 self.log.WriteText('You selected: "%s", %d points, color %s\n' %
891 (font.GetFaceName(), font.GetPointSize(),
892 data.GetColour().Get()))
893 dlg.Destroy()
894
895
896 def OnTestPageSetupDlg(self, event):
897 data = wxPageSetupDialogData()
898 data.SetMarginTopLeft(wxPoint(50,50))
899 data.SetMarginBottomRight(wxPoint(50,50))
900 dlg = wxPageSetupDialog(self, data)
901 if dlg.ShowModal() == wxID_OK:
902 data = dlg.GetPageSetupData()
903 tl = data.GetMarginTopLeft()
904 br = data.GetMarginBottomRight()
905 self.log.WriteText('Margins are: %s %s\n' % (str(tl), str(br)))
906 dlg.Destroy()
907
908 def OnTestPrintDlg(self, event):
909 data = wxPrintDialogData()
910 data.EnablePrintToFile(true)
911 data.EnablePageNumbers(true)
912 data.EnableSelection(true)
913 dlg = wxPrintDialog(self, data)
914 if dlg.ShowModal() == wxID_OK:
915 self.log.WriteText('\n')
916 dlg.Destroy()
917
918 def OnTestMessageDlg(self, event):
919 dlg = wxMessageDialog(self, 'Hello from Python and wxWindows!',
920 'A Message Box', wxOK | wxICON_INFORMATION)
921 dlg.ShowModal()
922 dlg.Destroy()
923
924
925 def OnTestNotebook(self, event):
926 win = TestNotebookWindow(self, self)
927 win.Show(true)
928
929 def OnTestSplitter(self, event):
930 win = TestSplitterWindow(self)
931 win.Show(true)
932
933 def OnTestCustomStatusBar(self, event):
934 win = TestCustomStatusBar(self)
935 win.Show(true)
936
937 def OnTestToolBar(self, event):
938 win = TestToolBar(self, self)
939 win.Show(true)
940
941 def OnTestTreeCtrl(self, event):
942 win = TestTreeCtrl(self, self)
943 win.Show(true)
944
945 def OnTestListCtrl(self, event):
946 win = TestListCtrl(self, self)
947 win.Show(true)
948
949 def OnTestSashWindow(self, event):
950 win = TestSashWindow(self, self)
951 win.Show(true)
952
953 #---------------------------------------------------------------------------
954
955
956 class MyApp(wxApp):
957 def OnInit(self):
958 frame = AppFrame(NULL, -1, "Test 4: (lots of little tests...)")
959 frame.Show(true)
960 self.SetTopWindow(frame)
961 return true
962
963 #---------------------------------------------------------------------------
964
965
966 def main():
967 app = MyApp(0)
968 app.MainLoop()
969
970
971 def t():
972 import pdb
973 pdb.run('main()')
974
975
976 # for focused testing...
977 def main2():
978 class T2App(wxApp):
979 def OnInit(self):
980 frame = TestLayoutConstraints(NULL)
981 frame.Show(true)
982 self.SetTopWindow(frame)
983 return true
984
985 app = T2App(0)
986 app.MainLoop()
987
988 def t2():
989 import pdb
990 pdb.run('main2()')
991
992
993
994 if __name__ == '__main__':
995 main()
996
997
998 #----------------------------------------------------------------------------
999 #
1000 # $Log$
1001 # Revision 1.4 2001/02/16 08:19:38 robind
1002 # Copied/merged from the 2.2 branch.
1003 #
1004 # Changes needed to build with new event system
1005 #
1006 # Revision 1.1.2.2 2001/01/30 20:54:16 robind
1007 #
1008 # Gobs of changes move from the main trunk to the 2.2 branch in
1009 # preparataion for 2.2.5 release. See CHANGES.txt for details.
1010 #
1011 # Revision 1.3 2000/10/30 21:05:22 robind
1012 #
1013 # Merged wxPython 2.2.2 over to the main branch
1014 #
1015 # Revision 1.1.2.1 2000/05/16 02:07:02 RD
1016 #
1017 # Moved and reorganized wxPython directories
1018 #
1019 # Now builds into an intermediate wxPython package directory before
1020 # installing
1021 #
1022 # Revision 1.17 1999/08/05 05:06:50 RD
1023 #
1024 # Some minor tweaks
1025 #
1026 # Revision 1.16 1999/04/30 03:29:54 RD
1027 #
1028 # wxPython 2.0b9, first phase (win32)
1029 # Added gobs of stuff, see wxPython/README.txt for details
1030 #
1031 # Revision 1.15.2.1 1999/03/16 06:05:50 RD
1032 #
1033 # wxPython 2.0b7
1034 #
1035 # Revision 1.15 1999/03/05 07:23:42 RD
1036 #
1037 # Minor wxPython changes for wxWin 2.0
1038 #
1039 # Revision 1.14 1999/02/27 04:20:50 RD
1040 #
1041 # minor tweaks for testing
1042 #
1043 # Revision 1.13 1999/02/20 09:04:44 RD
1044 # Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
1045 # window handle. If you can get the window handle into the python code,
1046 # it should just work... More news on this later.
1047 #
1048 # Added wxImageList, wxToolTip.
1049 #
1050 # Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
1051 # wxRegConfig class.
1052 #
1053 # As usual, some bug fixes, tweaks, etc.
1054 #
1055 # Revision 1.12 1999/01/30 07:31:33 RD
1056 #
1057 # Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc.
1058 #
1059 # Various cleanup, tweaks, minor additions, etc. to maintain
1060 # compatibility with the current wxWindows.
1061 #
1062 # Revision 1.11 1999/01/29 16:17:59 HH
1063 # In test4's toolbar sample, changed NULL to wxNullBitmap to prevent SIGSEVS
1064 # with wxGTK. The sample works now.
1065 #
1066 # Revision 1.10 1998/12/16 22:12:47 RD
1067 #
1068 # Tweaks needed to be able to build wxPython with wxGTK.
1069 #
1070 # Revision 1.9 1998/12/15 20:44:35 RD
1071 # Changed the import semantics from "from wxPython import *" to "from
1072 # wxPython.wx import *" This is for people who are worried about
1073 # namespace pollution, they can use "from wxPython import wx" and then
1074 # prefix all the wxPython identifiers with "wx."
1075 #
1076 # Added wxTaskbarIcon for wxMSW.
1077 #
1078 # Made the events work for wxGrid.
1079 #
1080 # Added wxConfig.
1081 #
1082 # Added wxMiniFrame for wxGTK, (untested.)
1083 #
1084 # Changed many of the args and return values that were pointers to gdi
1085 # objects to references to reflect changes in the wxWindows API.
1086 #
1087 # Other assorted fixes and additions.
1088 #
1089 # Revision 1.8 1998/11/25 08:47:11 RD
1090 #
1091 # Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
1092 # Added events for wxGrid
1093 # Other various fixes and additions
1094 #
1095 # Revision 1.7 1998/11/11 03:13:19 RD
1096 #
1097 # Additions for wxTreeCtrl
1098 #
1099 # Revision 1.6 1998/10/20 06:45:33 RD
1100 # New wxTreeCtrl wrappers (untested)
1101 # some changes in helpers
1102 # etc.
1103 #
1104 # Revision 1.5 1998/10/02 06:42:28 RD
1105 #
1106 # Version 0.4 of wxPython for MSW.
1107 #
1108 # Revision 1.4 1998/08/27 21:59:51 RD
1109 # Some chicken-and-egg problems solved for wxPython on wxGTK
1110 #
1111 # Revision 1.3 1998/08/27 00:01:17 RD
1112 # - more tweaks
1113 # - have discovered some problems but not yet discovered solutions...
1114 #
1115 # Revision 1.2 1998/08/22 19:51:18 RD
1116 # some tweaks for wxGTK
1117 #
1118 # Revision 1.1 1998/08/09 08:28:05 RD
1119 # Initial version
1120 #
1121 #