]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/tests/test4.py
more files to ignore in cvs commands (setup.h, lex_yy.c, y_tab.c)
[wxWidgets.git] / utils / 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",
08127323 25 wxDefaultPosition, wxSize(350, 350))
7bf85405
RD
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
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,
d5c9047a 44 sampleList, 3, wxRA_HORIZONTAL| 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))
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))
08127323 62 lb = wxListBox(self, 60, wxPoint(80, y_pos), wxDefaultSize,
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):
7bf85405 253 wxFrame.__init__(self, parent, -1, 'Test wxNotebook',
08127323 254 wxDefaultPosition, wxDefaultSize)
7bf85405
RD
255
256 nb = wxNotebook(self, -1)
257
9c039d08 258 win = ColoredPanel(nb, wxBLUE)
7bf85405 259 nb.AddPage(win, "Blue")
630d84f2
RD
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))
9c039d08
RD
268 st.SetForegroundColour(wxWHITE)
269 st.SetBackgroundColour(wxBLUE)
7bf85405 270
630d84f2
RD
271 win = TestTreeCtrlPanel(nb, log)
272 nb.AddPage(win, "TreeCtrl")
273
9c039d08 274 win = ColoredPanel(nb, wxRED)
7bf85405
RD
275 nb.AddPage(win, "Red")
276
9c039d08 277 win = ColoredPanel(nb, wxGREEN)
7bf85405
RD
278 nb.AddPage(win, "Green")
279
9c039d08 280 win = ColoredPanel(nb, wxCYAN)
7bf85405
RD
281 nb.AddPage(win, "Cyan")
282
9c039d08 283 win = ColoredPanel(nb, wxWHITE)
7bf85405
RD
284 nb.AddPage(win, "White")
285
9c039d08 286 win = ColoredPanel(nb, wxBLACK)
7bf85405
RD
287 nb.AddPage(win, "Black")
288
9c039d08 289 win = ColoredPanel(nb, wxNamedColour('MIDNIGHT BLUE'))
7bf85405
RD
290 nb.AddPage(win, "MIDNIGHT BLUE")
291
9c039d08 292 win = ColoredPanel(nb, wxNamedColour('INDIAN RED'))
7bf85405
RD
293 nb.AddPage(win, "INDIAN RED")
294
295
296 nb.SetSelection(0)
630d84f2 297 self.SetSize(wxSize(350, 300)) # force a redraw so the notebook will draw
9c039d08
RD
298
299
300 def OnCloseWindow(self, event):
301 self.Destroy()
302
303#---------------------------------------------------------------------------
304
305class TestSplitterWindow(wxFrame):
306 def __init__(self, parent):
307 wxFrame.__init__(self, parent, -1, 'Test wxSplitterWindow',
08127323 308 wxDefaultPosition, wxSize(500, 300))
9c039d08
RD
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
327class 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)
105e45b9 368 print "%s, %s" % (rect.x, rect.y)
9c039d08
RD
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
374class TestCustomStatusBar(wxFrame):
375 def __init__(self, parent):
376 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
08127323 377 wxDefaultPosition, wxSize(500, 300))
b8b8dda7 378 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
7bf85405 379
9c039d08
RD
380 self.sb = CustomStatusBar(self)
381 self.SetStatusBar(self.sb)
7bf85405
RD
382
383 def OnCloseWindow(self, event):
9c039d08 384 self.sb.timer.Stop()
7bf85405
RD
385 self.Destroy()
386
9c039d08
RD
387
388#---------------------------------------------------------------------------
389
390class TestToolBar(wxFrame):
391 def __init__(self, parent, log):
392 wxFrame.__init__(self, parent, -1, 'Test ToolBar',
08127323 393 wxDefaultPosition, wxSize(500, 300))
9c039d08
RD
394 self.log = log
395
b8b8dda7 396 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
9c039d08 397
b8b8dda7 398 tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
08127323 399 #tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize,
9c039d08
RD
400 # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
401 #self.SetToolBar(tb)
402
08127323
RD
403 self.CreateStatusBar()
404
9c039d08 405 tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
08127323 406 wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
9c039d08
RD
407 EVT_TOOL(self, 10, self.OnToolClick)
408 EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
409
410 tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
2e850e68 411 wxNullBitmap, false, -1, -1, "Open")
9c039d08
RD
412 EVT_TOOL(self, 20, self.OnToolClick)
413 EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
414
415 tb.AddSeparator()
416 tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
2e850e68 417 wxNullBitmap, false, -1, -1, "Copy")
9c039d08
RD
418 EVT_TOOL(self, 30, self.OnToolClick)
419 EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
420
421 tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
2e850e68 422 wxNullBitmap, false, -1, -1, "Paste")
9c039d08
RD
423 EVT_TOOL(self, 40, self.OnToolClick)
424 EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
425
426 tb.AddSeparator()
427
428 tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
2e850e68 429 wxNullBitmap, true, -1, -1, "Toggle this")
9c039d08
RD
430 EVT_TOOL(self, 50, self.OnToolClick)
431 EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
432
433 tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
434 wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
435 true, -1, -1, "Toggle with 2 bitmaps")
436 EVT_TOOL(self, 60, self.OnToolClick)
437 EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
438
439 tb.Realize()
440
441
442 def OnCloseWindow(self, event):
443 self.Destroy()
444
445 def OnToolClick(self, event):
446 self.log.WriteText("tool %s clicked\n" % event.GetId())
447
448 def OnToolRClick(self, event):
449 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
450
451
630d84f2
RD
452#---------------------------------------------------------------------------
453
454class TestTreeCtrlPanel(wxPanel):
455 def __init__(self, parent, log):
456 wxPanel.__init__(self, parent, -1)
457
458 self.log = log
459 tID = 1101
460
461 self.tree = wxTreeCtrl(self, tID)
462 root = self.tree.AddRoot("The Root Item")
463 for x in range(10):
464 child = self.tree.AppendItem(root, "Item %d" % x)
465 for y in range(5):
466 last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
467
468 self.tree.Expand(root)
469 EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
470 EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
471 EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
472
473
474 def OnSize(self, event):
b8b8dda7 475 w,h = self.GetClientSizeTuple()
630d84f2
RD
476 self.tree.SetDimensions(0, 0, w, h)
477
478
479 def OnItemExpanded(self, event):
480 item = event.GetItem()
481 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
482
483 def OnItemCollapsed(self, event):
484 item = event.GetItem()
485 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
486
487 def OnSelChanged(self, event):
488 item = event.GetItem()
489 self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
490
491
492
493
494class TestTreeCtrl(wxFrame):
495 def __init__(self, parent, log):
496 wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
08127323 497 wxDefaultPosition, wxSize(250, 300))
630d84f2
RD
498
499 p = TestTreeCtrlPanel(self, log)
500
501
08127323
RD
502#---------------------------------------------------------------------------
503
504class TestSashWindow(wxMDIParentFrame):
505 NEW_WINDOW = 5000
506 TOGGLE_WINDOW = 5001
507 QUIT = 5002
508 ID_WINDOW_TOP = 5100
509 ID_WINDOW_LEFT1 = 5101
510 ID_WINDOW_LEFT2 = 5102
511 ID_WINDOW_BOTTOM = 5103
512
513
514 def __init__(self, parent, log):
515 wxMDIParentFrame.__init__(self, parent, -1, 'Test Sash Window',
516 wxDefaultPosition, wxSize(250, 300))
517
518 self.log = log
519 menu = wxMenu()
520 menu.Append(self.NEW_WINDOW, "&New Window")
521 menu.Append(self.TOGGLE_WINDOW, "&Toggle window")
522 menu.Append(self.QUIT, "E&xit")
523
524 menubar = wxMenuBar()
525 menubar.Append(menu, "&File")
526
527 self.SetMenuBar(menubar)
528 self.CreateStatusBar()
529
530 EVT_MENU(self, self.NEW_WINDOW, self.OnNewWindow)
531 EVT_MENU(self, self.TOGGLE_WINDOW, self.OnToggleWindow)
532 EVT_MENU(self, self.QUIT, self.OnQuit)
533
534 EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
535 self.ID_WINDOW_BOTTOM, self.OnSashDrag)
536
537
538 # Create some layout windows
539 # A window like a toolbar
540 win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, wxDefaultPosition,
541 wxSize(200, 30), wxNO_BORDER|wxSW_3D)
542 win.SetDefaultSize(wxSize(1000, 30))
543 win.SetOrientation(wxLAYOUT_HORIZONTAL)
544 win.SetAlignment(wxLAYOUT_TOP)
545 win.SetBackgroundColour(wxColour(255, 0, 0))
546 win.SetSashVisible(wxSASH_BOTTOM, true)
547
548 self.topWindow = win
549
550
551 # A window like a statusbar
552 win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM,
553 wxDefaultPosition, wxSize(200, 30),
554 wxNO_BORDER|wxSW_3D)
555 win.SetDefaultSize(wxSize(1000, 30))
556 win.SetOrientation(wxLAYOUT_HORIZONTAL)
557 win.SetAlignment(wxLAYOUT_BOTTOM)
558 win.SetBackgroundColour(wxColour(0, 0, 255))
559 win.SetSashVisible(wxSASH_TOP, true)
560
561 self.bottomWindow = win
562
563
564 # A window to the left of the client window
565 win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1,
566 wxDefaultPosition, wxSize(200, 30),
567 wxNO_BORDER|wxSW_3D)
568 win.SetDefaultSize(wxSize(120, 1000))
569 win.SetOrientation(wxLAYOUT_VERTICAL)
570 win.SetAlignment(wxLAYOUT_LEFT)
571 win.SetBackgroundColour(wxColour(0, 255, 0))
572 win.SetSashVisible(wxSASH_RIGHT, TRUE)
573 win.SetExtraBorderSize(10)
574
575 textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
576 wxTE_MULTILINE|wxSUNKEN_BORDER)
577 textWindow.SetValue("A help window")
578
579 self.leftWindow1 = win
580
581
582 # Another window to the left of the client window
583 win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2,
584 wxDefaultPosition, wxSize(200, 30),
585 wxNO_BORDER|wxSW_3D)
586 win.SetDefaultSize(wxSize(120, 1000))
587 win.SetOrientation(wxLAYOUT_VERTICAL)
588 win.SetAlignment(wxLAYOUT_LEFT)
589 win.SetBackgroundColour(wxColour(0, 255, 255))
590 win.SetSashVisible(wxSASH_RIGHT, TRUE)
591
592 self.leftWindow2 = win
593
594
595 def OnNewWindow(self, event):
596 pass
597
598 def OnToggleWindow(self, event):
599 pass
600
601 def OnQuit(self, event):
602 self.Close(true)
603
604 def OnSashDrag(self, event):
605 if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
606 return
607
608 eID = event.GetId()
609 if eID == self.ID_WINDOW_TOP:
610 self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
611
612 elif eID == self.ID_WINDOW_LEFT1:
613 self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
614
615
616 elif eID == self.ID_WINDOW_LEFT2:
617 self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
618
619 elif eID == self.ID_WINDOW_BOTTOM:
620 self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
621
622 wxLayoutAlgorithm().LayoutMDIFrame(self)
623
624 # Leaves bits of itself behind sometimes
625 self.GetClientWindow().Refresh()
626
627
628 def OnSize(self, event):
629 wxLayoutAlgorithm().LayoutMDIFrame(self)
630
9c039d08
RD
631#---------------------------------------------------------------------------
632#---------------------------------------------------------------------------
7bf85405
RD
633#---------------------------------------------------------------------------
634
635class AppFrame(wxFrame):
636 def __init__(self, parent, id, title):
08127323 637 wxFrame.__init__(self, parent, id, title, wxDefaultPosition,
7bf85405 638 wxSize(420, 200))
f57d7932
RD
639 if wxPlatform == '__WXMSW__':
640 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
641 self.SetIcon(self.icon)
7bf85405
RD
642
643 self.mainmenu = wxMenuBar()
644 menu = wxMenu()
645 menu.Append(200, 'E&xit', 'Get the heck outta here!')
646 EVT_MENU(self, 200, self.OnFileExit)
647 self.mainmenu.Append(menu, '&File')
648
649 menu = self.MakeTestsMenu()
650 self.mainmenu.Append(menu, '&Tests')
651 self.SetMenuBar(self.mainmenu)
652
08127323 653 self.log = wxTextCtrl(self, -1, '', wxDefaultPosition, wxDefaultSize,
7bf85405
RD
654 wxTE_MULTILINE|wxTE_READONLY)
655 self.log.WriteText('Test 4:\n')
656 (w, self.charHeight) = self.log.GetTextExtent('X')
657
658
659 def MakeTestsMenu(self):
660 menu = wxMenu()
661
662 mID = NewId()
663 menu.Append(mID, '&Simple Controls')
664 EVT_MENU(self, mID, self.OnTestSimpleControls)
665
666 mID = NewId()
667 menu.Append(mID, '&Timer', '', true)
668 EVT_MENU(self, mID, self.OnTestTimer)
669 self.timerID = mID
670 self.timer = None
671
672 mID = NewId()
673 menu.Append(mID, '&Layout Constraints')
674 EVT_MENU(self, mID, self.OnTestLayoutConstraints)
675
676 mID = NewId()
677 menu.Append(mID, '&Grid')
678 EVT_MENU(self, mID, self.OnTestGrid)
679
680
681 smenu = wxMenu() # make a sub-menu
682
683 mID = NewId()
684 smenu.Append(mID, '&Colour')
685 EVT_MENU(self, mID, self.OnTestColourDlg)
686
687 mID = NewId()
688 smenu.Append(mID, '&Directory')
689 EVT_MENU(self, mID, self.OnTestDirDlg)
690
691 mID = NewId()
692 smenu.Append(mID, '&File')
693 EVT_MENU(self, mID, self.OnTestFileDlg)
694
695 mID = NewId()
696 smenu.Append(mID, '&Single Choice')
697 EVT_MENU(self, mID, self.OnTestSingleChoiceDlg)
698
699 mID = NewId()
700 smenu.Append(mID, '&TextEntry')
701 EVT_MENU(self, mID, self.OnTestTextEntryDlg)
702
703 mID = NewId()
704 smenu.Append(mID, '&Font')
705 EVT_MENU(self, mID, self.OnTestFontDlg)
706
707 mID = NewId()
708 smenu.Append(mID, '&PageSetup')
709 EVT_MENU(self, mID, self.OnTestPageSetupDlg)
710
711 mID = NewId()
712 smenu.Append(mID, '&Print')
713 EVT_MENU(self, mID, self.OnTestPrintDlg)
714
715 mID = NewId()
716 smenu.Append(mID, '&Message')
717 EVT_MENU(self, mID, self.OnTestMessageDlg)
718
719
720 menu.AppendMenu(NewId(), '&Common Dialogs', smenu)
721
722
723 mID = NewId()
724 menu.Append(mID, '&Notebook')
725 EVT_MENU(self, mID, self.OnTestNotebook)
726
9c039d08
RD
727 mID = NewId()
728 menu.Append(mID, '&Splitter Window')
729 EVT_MENU(self, mID, self.OnTestSplitter)
730
731 mID = NewId()
732 menu.Append(mID, '&Custom StatusBar')
733 EVT_MENU(self, mID, self.OnTestCustomStatusBar)
734
735 mID = NewId()
736 menu.Append(mID, '&ToolBar')
737 EVT_MENU(self, mID, self.OnTestToolBar)
738
630d84f2
RD
739 mID = NewId()
740 menu.Append(mID, 'T&ree Control')
741 EVT_MENU(self, mID, self.OnTestTreeCtrl)
742
08127323
RD
743 mID = NewId()
744 menu.Append(mID, 'S&ash Window and Layout Algorithm')
745 EVT_MENU(self, mID, self.OnTestSashWindow)
746
7bf85405
RD
747 return menu
748
749
750
751
752 def WriteText(self, str):
753 self.log.WriteText(str)
21f4bf45 754 if wxPlatform == '__WXMSW__':
b8b8dda7 755 w, h = self.log.GetClientSizeTuple()
21f4bf45
RD
756 numLines = h/self.charHeight
757 x, y = self.log.PositionToXY(self.log.GetLastPosition())
758 self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
7bf85405
RD
759
760 def OnFileExit(self, event):
761 self.Close()
762
763 def OnCloseWindow(self, event):
764 self.Destroy()
765
766
767
768
769 def OnTestSimpleControls(self, event):
770 dlg = TestSimpleControlsDlg(self, self)
7bf85405 771 dlg.Centre()
f57d7932 772 dlg.ShowModal()
7bf85405
RD
773 dlg.Destroy()
774
775 def OnTestTimer(self, event):
776 if self.timer:
777 self.mainmenu.Check(self.timerID, false)
778 self.timer.Stop()
779 self.timer = None
780 else:
781 self.mainmenu.Check(self.timerID, true)
782 self.timer = TestTimer(self)
783 self.timer.Start(1000)
784
785 def OnTestLayoutConstraints(self, event):
786 win = TestLayoutConstraints(self)
787 win.Show(true)
788
789 def OnTestGrid(self, event):
b639c3c5 790 win = TestGrid(self, self)
7bf85405
RD
791 win.Show(true)
792 win.SetSize(wxSize(505, 300)) # have to force a resize, or the grid doesn't
793 # show up for some reason....
794
795 def OnTestColourDlg(self, event):
796 data = wxColourData()
797 data.SetChooseFull(true)
798 dlg = wxColourDialog(self, data)
799 if dlg.ShowModal() == wxID_OK:
800 data = dlg.GetColourData()
801 self.log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
802 dlg.Destroy()
803
804 def OnTestDirDlg(self, event):
805 dlg = wxDirDialog(self)
806 if dlg.ShowModal() == wxID_OK:
807 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
808 dlg.Destroy()
809
810 def OnTestFileDlg(self, event):
811 dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
812 if dlg.ShowModal() == wxID_OK:
813 self.log.WriteText('You selected: %s\n' % dlg.GetPath())
814 dlg.Destroy()
815
816 def OnTestSingleChoiceDlg(self, event):
817 dlg = wxSingleChoiceDialog(self, 'Test Single Choice', 'The Caption',
818 ['zero', 'one', 'two', 'three', 'four', 'five',
819 'six', 'seven', 'eight'])
820 if dlg.ShowModal() == wxID_OK:
821 self.log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
822 dlg.Destroy()
823
824 def OnTestTextEntryDlg(self, event):
825 dlg = wxTextEntryDialog(self, 'What is your favorite programming language?',
826 'Duh??', 'Python')
827 #dlg.SetValue("Python is the best!") #### this doesn't work?
828 if dlg.ShowModal() == wxID_OK:
829 self.log.WriteText('You entered: %s\n' % dlg.GetValue())
830 dlg.Destroy()
831
832
833 def OnTestFontDlg(self, event):
834 dlg = wxFontDialog(self)
835 if dlg.ShowModal() == wxID_OK:
836 data = dlg.GetFontData()
837 font = data.GetChosenFont()
838 self.log.WriteText('You selected: "%s", %d points, color %s\n' %
839 (font.GetFaceName(), font.GetPointSize(),
840 data.GetColour().Get()))
841 dlg.Destroy()
842
843
844 def OnTestPageSetupDlg(self, event):
845 data = wxPageSetupData()
846 data.SetMarginTopLeft(wxPoint(50,50))
847 data.SetMarginBottomRight(wxPoint(50,50))
848 dlg = wxPageSetupDialog(self, data)
849 if dlg.ShowModal() == wxID_OK:
850 data = dlg.GetPageSetupData()
851 tl = data.GetMarginTopLeft()
852 br = data.GetMarginBottomRight()
853 self.log.WriteText('Margins are: %s %s\n' % (str(tl), str(br)))
854 dlg.Destroy()
855
856 def OnTestPrintDlg(self, event):
857 data = wxPrintData()
858 data.EnablePrintToFile(true)
859 data.EnablePageNumbers(true)
860 data.EnableSelection(true)
861 dlg = wxPrintDialog(self, data)
862 if dlg.ShowModal() == wxID_OK:
863 self.log.WriteText('\n')
864 dlg.Destroy()
865
866 def OnTestMessageDlg(self, event):
867 dlg = wxMessageDialog(self, 'Hello from Python and wxWindows!',
868 'A Message Box', wxOK | wxICON_INFORMATION)
869 dlg.ShowModal()
870 dlg.Destroy()
871
872
873 def OnTestNotebook(self, event):
630d84f2 874 win = TestNotebookWindow(self, self)
7bf85405
RD
875 win.Show(true)
876
9c039d08
RD
877 def OnTestSplitter(self, event):
878 win = TestSplitterWindow(self)
879 win.Show(true)
880
881 def OnTestCustomStatusBar(self, event):
882 win = TestCustomStatusBar(self)
883 win.Show(true)
884
885 def OnTestToolBar(self, event):
886 win = TestToolBar(self, self)
887 win.Show(true)
888
630d84f2
RD
889 def OnTestTreeCtrl(self, event):
890 win = TestTreeCtrl(self, self)
891 win.Show(true)
892
08127323
RD
893 def OnTestSashWindow(self, event):
894 win = TestSashWindow(self, self)
895 win.Show(true)
9c039d08 896
7bf85405
RD
897#---------------------------------------------------------------------------
898
899
900class MyApp(wxApp):
901 def OnInit(self):
902 frame = AppFrame(NULL, -1, "Test 4: (lots of little tests...)")
903 frame.Show(true)
904 self.SetTopWindow(frame)
905 return true
906
907#---------------------------------------------------------------------------
908
909
910def main():
911 app = MyApp(0)
912 app.MainLoop()
913
914
915def t():
916 import pdb
917 pdb.run('main()')
918
21f4bf45
RD
919
920# for focused testing...
0d6f9504 921def main2():
21f4bf45
RD
922 class T2App(wxApp):
923 def OnInit(self):
924 frame = TestLayoutConstraints(NULL)
925 frame.Show(true)
926 self.SetTopWindow(frame)
0d6f9504 927 return true
21f4bf45
RD
928
929 app = T2App(0)
930 app.MainLoop()
931
0d6f9504
RD
932def t2():
933 import pdb
934 pdb.run('main2()')
935
21f4bf45
RD
936
937
7bf85405
RD
938if __name__ == '__main__':
939 main()
940
941
942#----------------------------------------------------------------------------
943#
944# $Log$
08127323
RD
945# Revision 1.12 1999/01/30 07:31:33 RD
946# Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc.
947#
948# Various cleanup, tweaks, minor additions, etc. to maintain
949# compatibility with the current wxWindows.
950#
2e850e68
HH
951# Revision 1.11 1999/01/29 16:17:59 HH
952# In test4's toolbar sample, changed NULL to wxNullBitmap to prevent SIGSEVS
953# with wxGTK. The sample works now.
954#
105e45b9 955# Revision 1.10 1998/12/16 22:12:47 RD
2e850e68 956#
105e45b9
RD
957# Tweaks needed to be able to build wxPython with wxGTK.
958#
b8b8dda7
RD
959# Revision 1.9 1998/12/15 20:44:35 RD
960# Changed the import semantics from "from wxPython import *" to "from
961# wxPython.wx import *" This is for people who are worried about
962# namespace pollution, they can use "from wxPython import wx" and then
963# prefix all the wxPython identifiers with "wx."
964#
965# Added wxTaskbarIcon for wxMSW.
966#
967# Made the events work for wxGrid.
968#
969# Added wxConfig.
970#
971# Added wxMiniFrame for wxGTK, (untested.)
972#
973# Changed many of the args and return values that were pointers to gdi
974# objects to references to reflect changes in the wxWindows API.
975#
976# Other assorted fixes and additions.
977#
b639c3c5 978# Revision 1.8 1998/11/25 08:47:11 RD
b8b8dda7 979#
b639c3c5
RD
980# Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
981# Added events for wxGrid
982# Other various fixes and additions
983#
630d84f2 984# Revision 1.7 1998/11/11 03:13:19 RD
b639c3c5 985#
630d84f2
RD
986# Additions for wxTreeCtrl
987#
d5c9047a
RD
988# Revision 1.6 1998/10/20 06:45:33 RD
989# New wxTreeCtrl wrappers (untested)
990# some changes in helpers
991# etc.
992#
9c039d08 993# Revision 1.5 1998/10/02 06:42:28 RD
d5c9047a 994#
9c039d08
RD
995# Version 0.4 of wxPython for MSW.
996#
0d6f9504
RD
997# Revision 1.4 1998/08/27 21:59:51 RD
998# Some chicken-and-egg problems solved for wxPython on wxGTK
999#
21f4bf45
RD
1000# Revision 1.3 1998/08/27 00:01:17 RD
1001# - more tweaks
1002# - have discovered some problems but not yet discovered solutions...
1003#
f57d7932
RD
1004# Revision 1.2 1998/08/22 19:51:18 RD
1005# some tweaks for wxGTK
1006#
7bf85405
RD
1007# Revision 1.1 1998/08/09 08:28:05 RD
1008# Initial version
1009#
1010#