]> git.saurik.com Git - wxWidgets.git/blame - wxPython/tests/test4.py
added url of Fink Unix to Mac OS X porting instructions
[wxWidgets.git] / wxPython / tests / test4.py
CommitLineData
7bf85405
RD
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
b8b8dda7 15from wxPython.wx import *
7bf85405 16
9c039d08 17import time
7bf85405
RD
18
19#---------------------------------------------------------------------------
20
21class TestSimpleControlsDlg(wxDialog):
22 def __init__(self, parent, log):
23 self.log = log
24 wxDialog.__init__(self, parent, -1, "Test Simple Controls",
cf694132 25 wxDefaultPosition, wxSize(350, 400))
7bf85405
RD
26
27
62abd41e
RD
28 sampleList = ["zero", "one", "two", "three", "four", "five",
29 "six", "seven", "eight", "nine", "ten"]
7bf85405
RD
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
d5c9047a 39 wxCheckBox(self, 20, "wxCheckBox", wxPoint(80, y_pos), wxSize(150, 20), wxNO_BORDER)
7bf85405
RD
40 EVT_CHECKBOX(self, 20, self.EvtCheckBox)
41 y_pos = y_pos + delta
42
08127323 43 rb = wxRadioBox(self, 30, "wxRadioBox", wxPoint(80, y_pos), wxDefaultSize,
022380e0 44 sampleList, 3, wxRA_SPECIFY_COLS | wxNO_BORDER)
7bf85405 45 EVT_RADIOBOX(self, 30, self.EvtRadioBox)
b8b8dda7 46 width, height = rb.GetSizeTuple()
7bf85405
RD
47 y_pos = y_pos + height + 5
48
49 wxStaticText(self, -1, "wxChoice", wxPoint(5, y_pos), wxSize(75, 20))
08127323 50 wxChoice(self, 40, wxPoint(80, y_pos), wxSize(95, 20), #wxDefaultSize,
7bf85405
RD
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))
f581a26d 56 wxComboBox(self, 50, "default value", wxPoint(80, y_pos), wxSize(95, -1),
7bf85405
RD
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))
f581a26d 62 lb = wxListBox(self, 60, wxPoint(80, y_pos), wxSize(95, 80),
7bf85405
RD
63 sampleList, wxLB_SINGLE)
64 EVT_LISTBOX(self, 60, self.EvtListBox)
65 EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
66 lb.SetSelection(0)
b8b8dda7 67 width, height = lb.GetSizeTuple()
7bf85405
RD
68 y_pos = y_pos + height + 5
69
70
71
72 y_pos = y_pos + 15
08127323 73 wxButton(self, wxID_OK, ' OK ', wxPoint(80, y_pos), wxDefaultSize).SetDefault()
7bf85405
RD
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
102class 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
114class TestLayoutConstraints(wxFrame):
115 def __init__(self, parent):
116 wxFrame.__init__(self, parent, -1, 'Test Layout Constraints',
08127323 117 wxDefaultPosition, wxSize(500, 300))
7bf85405
RD
118
119 self.SetAutoLayout(true)
120 EVT_BUTTON(self, 100, self.OnButton)
121
08127323 122 self.panelA = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
7bf85405
RD
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
08127323 132 self.panelB = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
7bf85405
RD
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
08127323 142 self.panelC = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
7bf85405
RD
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
08127323 168 self.panelD = wxWindow(self.panelC, -1, wxDefaultPosition, wxDefaultSize,
7bf85405
RD
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
199class TestGrid(wxFrame):
b639c3c5 200 def __init__(self, parent, log):
7bf85405 201 wxFrame.__init__(self, parent, -1, 'Test Grid',
08127323 202 wxDefaultPosition, wxSize(500, 300))
b639c3c5 203 self.log = log
7bf85405
RD
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
b639c3c5
RD
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
7bf85405
RD
225
226 def OnCloseWindow(self, event):
227 self.Destroy()
228
b639c3c5
RD
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))
7bf85405
RD
240
241#---------------------------------------------------------------------------
242
9c039d08
RD
243
244class ColoredPanel(wxWindow):
245 def __init__(self, parent, color):
246 wxWindow.__init__(self, parent, -1,
08127323 247 wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER)
9c039d08
RD
248 self.SetBackgroundColour(color)
249
250
7bf85405 251class TestNotebookWindow(wxFrame):
630d84f2 252 def __init__(self, parent, log):
cf694132 253 wxFrame.__init__(self, parent, -1, 'Test wxNotebook')
7bf85405 254
cf694132 255 nb = wxNotebook(self, -1, wxPoint(0,0), self.GetClientSize())
7bf85405 256
9c039d08 257 win = ColoredPanel(nb, wxBLUE)
7bf85405 258 nb.AddPage(win, "Blue")
630d84f2
RD
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))
9c039d08
RD
267 st.SetForegroundColour(wxWHITE)
268 st.SetBackgroundColour(wxBLUE)
7bf85405 269
630d84f2
RD
270 win = TestTreeCtrlPanel(nb, log)
271 nb.AddPage(win, "TreeCtrl")
272
af309447
RD
273 win = TestListCtrlPanel(nb, log)
274 nb.AddPage(win, "ListCtrl")
275
9c039d08 276 win = ColoredPanel(nb, wxRED)
7bf85405
RD
277 nb.AddPage(win, "Red")
278
9c039d08 279 win = ColoredPanel(nb, wxGREEN)
7bf85405
RD
280 nb.AddPage(win, "Green")
281
9c039d08 282 win = ColoredPanel(nb, wxCYAN)
7bf85405
RD
283 nb.AddPage(win, "Cyan")
284
9c039d08 285 win = ColoredPanel(nb, wxWHITE)
7bf85405
RD
286 nb.AddPage(win, "White")
287
9c039d08 288 win = ColoredPanel(nb, wxBLACK)
7bf85405
RD
289 nb.AddPage(win, "Black")
290
9c039d08 291 win = ColoredPanel(nb, wxNamedColour('MIDNIGHT BLUE'))
7bf85405
RD
292 nb.AddPage(win, "MIDNIGHT BLUE")
293
9c039d08 294 win = ColoredPanel(nb, wxNamedColour('INDIAN RED'))
7bf85405
RD
295 nb.AddPage(win, "INDIAN RED")
296
7bf85405 297 nb.SetSelection(0)
cf694132 298 self.SetSize(wxSize(350, 300))
9c039d08
RD
299
300
301 def OnCloseWindow(self, event):
302 self.Destroy()
303
304#---------------------------------------------------------------------------
305
306class TestSplitterWindow(wxFrame):
307 def __init__(self, parent):
308 wxFrame.__init__(self, parent, -1, 'Test wxSplitterWindow',
08127323 309 wxDefaultPosition, wxSize(500, 300))
9c039d08
RD
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
328class 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())
af309447 342 (w,h) = dc.GetTextExtent('X')
9c039d08
RD
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)
105e45b9 369 print "%s, %s" % (rect.x, rect.y)
9c039d08
RD
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
375class TestCustomStatusBar(wxFrame):
376 def __init__(self, parent):
377 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
08127323 378 wxDefaultPosition, wxSize(500, 300))
b8b8dda7 379 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
7bf85405 380
9c039d08
RD
381 self.sb = CustomStatusBar(self)
382 self.SetStatusBar(self.sb)
7bf85405
RD
383
384 def OnCloseWindow(self, event):
9c039d08 385 self.sb.timer.Stop()
7bf85405
RD
386 self.Destroy()
387
9c039d08
RD
388
389#---------------------------------------------------------------------------
390
391class TestToolBar(wxFrame):
392 def __init__(self, parent, log):
393 wxFrame.__init__(self, parent, -1, 'Test ToolBar',
08127323 394 wxDefaultPosition, wxSize(500, 300))
9c039d08
RD
395 self.log = log
396
b8b8dda7 397 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
9c039d08 398
b8b8dda7 399 tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
08127323 400 #tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize,
9c039d08
RD
401 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
402 #self.SetToolBar(tb)
403
08127323
RD
404 self.CreateStatusBar()
405
9c039d08 406 tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
08127323 407 wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
9c039d08
RD
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),
2e850e68 412 wxNullBitmap, false, -1, -1, "Open")
9c039d08
RD
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),
2e850e68 418 wxNullBitmap, false, -1, -1, "Copy")
9c039d08
RD
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),
2e850e68 423 wxNullBitmap, false, -1, -1, "Paste")
9c039d08
RD
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),
2e850e68 430 wxNullBitmap, true, -1, -1, "Toggle this")
9c039d08
RD
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
630d84f2
RD
453#---------------------------------------------------------------------------
454
455class 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):
b8b8dda7 476 w,h = self.GetClientSizeTuple()
630d84f2
RD
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
495class TestTreeCtrl(wxFrame):
496 def __init__(self, parent, log):
497 wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
08127323 498 wxDefaultPosition, wxSize(250, 300))
630d84f2
RD
499
500 p = TestTreeCtrlPanel(self, log)
501
502
af309447
RD
503#---------------------------------------------------------------------------
504
505class 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
cf694132
RD
519 #self.list.SetToolTip(wxToolTip("This is a ToolTip!"))
520 #wxToolTip_Enable(true)
af309447
RD
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
542class 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
08127323
RD
550#---------------------------------------------------------------------------
551
552class 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
9c039d08
RD
679#---------------------------------------------------------------------------
680#---------------------------------------------------------------------------
7bf85405
RD
681#---------------------------------------------------------------------------
682
683class AppFrame(wxFrame):
684 def __init__(self, parent, id, title):
08127323 685 wxFrame.__init__(self, parent, id, title, wxDefaultPosition,
7bf85405 686 wxSize(420, 200))
f57d7932
RD
687 if wxPlatform == '__WXMSW__':
688 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
689 self.SetIcon(self.icon)
7bf85405
RD
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
08127323 701 self.log = wxTextCtrl(self, -1, '', wxDefaultPosition, wxDefaultSize,
7bf85405
RD
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
9c039d08
RD
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
630d84f2
RD
787 mID = NewId()
788 menu.Append(mID, 'T&ree Control')
789 EVT_MENU(self, mID, self.OnTestTreeCtrl)
790
af309447
RD
791 mID = NewId()
792 menu.Append(mID, '&List Control')
793 EVT_MENU(self, mID, self.OnTestListCtrl)
794
08127323
RD
795 mID = NewId()
796 menu.Append(mID, 'S&ash Window and Layout Algorithm')
797 EVT_MENU(self, mID, self.OnTestSashWindow)
798
7bf85405
RD
799 return menu
800
801
802
803
804 def WriteText(self, str):
805 self.log.WriteText(str)
21f4bf45 806 if wxPlatform == '__WXMSW__':
b8b8dda7 807 w, h = self.log.GetClientSizeTuple()
21f4bf45
RD
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))
7bf85405
RD
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)
7bf85405 823 dlg.Centre()
f57d7932 824 dlg.ShowModal()
7bf85405
RD
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):
b639c3c5 842 win = TestGrid(self, self)
7bf85405
RD
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):
cf694132 897 data = wxPageSetupDialogData()
7bf85405
RD
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):
cf694132 909 data = wxPrintDialogData()
7bf85405
RD
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):
630d84f2 926 win = TestNotebookWindow(self, self)
7bf85405
RD
927 win.Show(true)
928
9c039d08
RD
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
630d84f2
RD
941 def OnTestTreeCtrl(self, event):
942 win = TestTreeCtrl(self, self)
943 win.Show(true)
944
af309447
RD
945 def OnTestListCtrl(self, event):
946 win = TestListCtrl(self, self)
947 win.Show(true)
948
08127323
RD
949 def OnTestSashWindow(self, event):
950 win = TestSashWindow(self, self)
951 win.Show(true)
9c039d08 952
7bf85405
RD
953#---------------------------------------------------------------------------
954
955
956class 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
966def main():
967 app = MyApp(0)
968 app.MainLoop()
969
970
971def t():
972 import pdb
973 pdb.run('main()')
974
21f4bf45
RD
975
976# for focused testing...
0d6f9504 977def main2():
21f4bf45
RD
978 class T2App(wxApp):
979 def OnInit(self):
980 frame = TestLayoutConstraints(NULL)
981 frame.Show(true)
982 self.SetTopWindow(frame)
0d6f9504 983 return true
21f4bf45
RD
984
985 app = T2App(0)
986 app.MainLoop()
987
0d6f9504
RD
988def t2():
989 import pdb
990 pdb.run('main2()')
991
21f4bf45
RD
992
993
7bf85405
RD
994if __name__ == '__main__':
995 main()
996
997
998#----------------------------------------------------------------------------
999#
1000# $Log$
1b62f00d
RD
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#
c368d904 1011# Revision 1.3 2000/10/30 21:05:22 robind
1b62f00d 1012#
c368d904 1013# Merged wxPython 2.2.2 over to the main branch
f6bcfd97
BP
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#
f581a26d 1022# Revision 1.17 1999/08/05 05:06:50 RD
f6bcfd97 1023#
f581a26d
RD
1024# Some minor tweaks
1025#
cf694132 1026# Revision 1.16 1999/04/30 03:29:54 RD
f581a26d 1027#
cf694132
RD
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#
62abd41e 1035# Revision 1.15 1999/03/05 07:23:42 RD
cf694132 1036#
62abd41e
RD
1037# Minor wxPython changes for wxWin 2.0
1038#
022380e0 1039# Revision 1.14 1999/02/27 04:20:50 RD
62abd41e 1040#
022380e0
RD
1041# minor tweaks for testing
1042#
af309447
RD
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#
08127323 1055# Revision 1.12 1999/01/30 07:31:33 RD
af309447 1056#
08127323
RD
1057# Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc.
1058#
1059# Various cleanup, tweaks, minor additions, etc. to maintain
1060# compatibility with the current wxWindows.
1061#
2e850e68
HH
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#
105e45b9 1066# Revision 1.10 1998/12/16 22:12:47 RD
2e850e68 1067#
105e45b9
RD
1068# Tweaks needed to be able to build wxPython with wxGTK.
1069#
b8b8dda7
RD
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#
b639c3c5 1089# Revision 1.8 1998/11/25 08:47:11 RD
b8b8dda7 1090#
b639c3c5
RD
1091# Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
1092# Added events for wxGrid
1093# Other various fixes and additions
1094#
630d84f2 1095# Revision 1.7 1998/11/11 03:13:19 RD
b639c3c5 1096#
630d84f2
RD
1097# Additions for wxTreeCtrl
1098#
d5c9047a
RD
1099# Revision 1.6 1998/10/20 06:45:33 RD
1100# New wxTreeCtrl wrappers (untested)
1101# some changes in helpers
1102# etc.
1103#
9c039d08 1104# Revision 1.5 1998/10/02 06:42:28 RD
d5c9047a 1105#
9c039d08
RD
1106# Version 0.4 of wxPython for MSW.
1107#
0d6f9504
RD
1108# Revision 1.4 1998/08/27 21:59:51 RD
1109# Some chicken-and-egg problems solved for wxPython on wxGTK
1110#
21f4bf45
RD
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#
f57d7932
RD
1115# Revision 1.2 1998/08/22 19:51:18 RD
1116# some tweaks for wxGTK
1117#
7bf85405
RD
1118# Revision 1.1 1998/08/09 08:28:05 RD
1119# Initial version
1120#
1121#