2 #----------------------------------------------------------------------------
4 # Purpose: Testing lots of stuff, controls, window types, etc.
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 from wxPython
import *
18 #---------------------------------------------------------------------------
20 class TestSimpleControlsDlg(wxDialog
):
21 def __init__(self
, parent
, log
):
23 wxDialog
.__init
__(self
, parent
, -1, "Test Simple Controls",
24 wxPyDefaultPosition
, wxSize(350, 350))
27 sampleList
= ['zero', 'one', 'two', 'three', 'four', 'five',
28 'six', 'seven', 'eight']
33 wxStaticText(self
, -1, "wxTextCtrl", wxPoint(5, y_pos
), wxSize(75, 20))
34 wxTextCtrl(self
, 10, "", wxPoint(80, y_pos
), wxSize(150, 20))
35 EVT_TEXT(self
, 10, self
.EvtText
)
38 wxCheckBox(self
, 20, "wxCheckBox", wxPoint(80, y_pos
), wxSize(150, 20))
39 EVT_CHECKBOX(self
, 20, self
.EvtCheckBox
)
42 rb
= wxRadioBox(self
, 30, "wxRadioBox", wxPoint(80, y_pos
), wxPyDefaultSize
,
43 sampleList
, 3, wxRA_HORIZONTAL
)
44 EVT_RADIOBOX(self
, 30, self
.EvtRadioBox
)
45 width
, height
= rb
.GetSize()
46 y_pos
= y_pos
+ height
+ 5
48 wxStaticText(self
, -1, "wxChoice", wxPoint(5, y_pos
), wxSize(75, 20))
49 wxChoice(self
, 40, wxPoint(80, y_pos
), wxSize(95, 20), #wxPyDefaultSize,
51 EVT_CHOICE(self
, 40, self
.EvtChoice
)
54 wxStaticText(self
, -1, "wxComboBox", wxPoint(5, y_pos
), wxSize(75, 18))
55 wxComboBox(self
, 50, "default value", wxPoint(80, y_pos
), wxSize(95, 20),
56 sampleList
, wxCB_DROPDOWN
)
57 EVT_COMBOBOX(self
, 50, self
.EvtComboBox
)
60 wxStaticText(self
, -1, "wxListBox", wxPoint(5, y_pos
), wxSize(75, 18))
61 lb
= wxListBox(self
, 60, wxPoint(80, y_pos
), wxPyDefaultSize
,
62 sampleList
, wxLB_SINGLE
)
63 EVT_LISTBOX(self
, 60, self
.EvtListBox
)
64 EVT_LISTBOX_DCLICK(self
, 60, self
.EvtListBoxDClick
)
66 width
, height
= lb
.GetSize()
67 y_pos
= y_pos
+ height
+ 5
72 wxButton(self
, wxID_OK
, ' OK ', wxPoint(80, y_pos
), wxPyDefaultSize
).SetDefault()
73 wxButton(self
, wxID_CANCEL
, ' Cancel ', wxPoint(140, y_pos
))
76 def EvtText(self
, event
):
77 self
.log
.WriteText('EvtText: %s\n' % event
.GetString())
79 def EvtCheckBox(self
, event
):
80 self
.log
.WriteText('EvtCheckBox: %d\n' % event
.GetInt())
82 def EvtRadioBox(self
, event
):
83 self
.log
.WriteText('EvtRadioBox: %d\n' % event
.GetInt())
85 def EvtChoice(self
, event
):
86 self
.log
.WriteText('EvtChoice: %s\n' % event
.GetString())
88 def EvtComboBox(self
, event
):
89 self
.log
.WriteText('EvtComboBox: %s\n' % event
.GetString())
91 def EvtListBox(self
, event
):
92 self
.log
.WriteText('EvtListBox: %s\n' % event
.GetString())
94 def EvtListBoxDClick(self
, event
):
95 self
.log
.WriteText('EvtListBoxDClick:\n')
99 #---------------------------------------------------------------------------
101 class TestTimer(wxTimer
):
102 def __init__(self
, log
):
103 wxTimer
.__init
__(self
)
108 self
.log
.WriteText('beep!\n')
111 #---------------------------------------------------------------------------
113 class TestLayoutConstraints(wxFrame
):
114 def __init__(self
, parent
):
115 wxFrame
.__init
__(self
, parent
, -1, 'Test Layout Constraints',
116 wxPyDefaultPosition
, wxSize(500, 300))
118 self
.SetAutoLayout(true
)
119 EVT_BUTTON(self
, 100, self
.OnButton
)
121 self
.panelA
= wxWindow(self
, -1, wxPyDefaultPosition
, wxPyDefaultSize
,
123 self
.panelA
.SetBackgroundColour(wxBLUE
)
124 lc
= wxLayoutConstraints()
125 lc
.top
.SameAs(self
, wxTop
, 10)
126 lc
.left
.SameAs(self
, wxLeft
, 10)
127 lc
.bottom
.SameAs(self
, wxBottom
, 10)
128 lc
.right
.PercentOf(self
, wxRight
, 50)
129 self
.panelA
.SetConstraints(lc
)
131 self
.panelB
= wxWindow(self
, -1, wxPyDefaultPosition
, wxPyDefaultSize
,
133 self
.panelB
.SetBackgroundColour(wxRED
)
134 lc
= wxLayoutConstraints()
135 lc
.top
.SameAs(self
, wxTop
, 10)
136 lc
.right
.SameAs(self
, wxRight
, 10)
137 lc
.bottom
.PercentOf(self
, wxBottom
, 30)
138 lc
.left
.RightOf(self
.panelA
, 10)
139 self
.panelB
.SetConstraints(lc
)
141 self
.panelC
= wxWindow(self
, -1, wxPyDefaultPosition
, wxPyDefaultSize
,
143 self
.panelC
.SetBackgroundColour(wxWHITE
)
144 lc
= wxLayoutConstraints()
145 lc
.top
.Below(self
.panelB
, 10)
146 lc
.right
.SameAs(self
, wxRight
, 10)
147 lc
.bottom
.SameAs(self
, wxBottom
, 10)
148 lc
.left
.RightOf(self
.panelA
, 10)
149 self
.panelC
.SetConstraints(lc
)
151 b
= wxButton(self
.panelA
, 100, ' Panel A ')
152 lc
= wxLayoutConstraints()
153 lc
.centreX
.SameAs (self
.panelA
, wxCentreX
)
154 lc
.centreY
.SameAs (self
.panelA
, wxCentreY
)
156 lc
.width
.PercentOf (self
.panelA
, wxWidth
, 50)
157 b
.SetConstraints(lc
);
159 b
= wxButton(self
.panelB
, 100, ' Panel B ')
160 lc
= wxLayoutConstraints()
161 lc
.top
.SameAs (self
.panelB
, wxTop
, 2)
162 lc
.right
.SameAs (self
.panelB
, wxRight
, 4)
165 b
.SetConstraints(lc
);
167 self
.panelD
= wxWindow(self
.panelC
, -1, wxPyDefaultPosition
, wxPyDefaultSize
,
169 self
.panelD
.SetBackgroundColour(wxGREEN
)
170 wxStaticText(self
.panelD
, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN
)
172 b
= wxButton(self
.panelC
, 100, ' Panel C ')
173 lc
= wxLayoutConstraints()
174 lc
.top
.Below (self
.panelD
)
175 lc
.left
.RightOf (self
.panelD
)
178 b
.SetConstraints(lc
);
180 lc
= wxLayoutConstraints()
181 lc
.bottom
.PercentOf (self
.panelC
, wxHeight
, 50)
182 lc
.right
.PercentOf (self
.panelC
, wxWidth
, 50)
183 lc
.height
.SameAs (b
, wxHeight
)
184 lc
.width
.SameAs (b
, wxWidth
)
185 self
.panelD
.SetConstraints(lc
);
188 def OnButton(self
, event
):
192 def OnCloseWindow(self
, event
):
196 #---------------------------------------------------------------------------
198 class TestGrid(wxFrame
):
199 def __init__(self
, parent
):
200 wxFrame
.__init
__(self
, parent
, -1, 'Test Grid',
201 wxPyDefaultPosition
, wxSize(500, 300))
203 grid
= wxGrid(self
, -1)
205 grid
.CreateGrid(16, 16)
206 grid
.SetColumnWidth(3, 200)
207 grid
.SetRowHeight(4, 45)
208 grid
.SetCellValue("First cell", 0, 0)
209 grid
.SetCellValue("Another cell", 1, 1)
210 grid
.SetCellValue("Yet another cell", 2, 2)
211 grid
.SetCellTextFont(wxFont(12, wxROMAN
, wxITALIC
, wxNORMAL
), 0, 0)
212 grid
.SetCellTextColour(wxRED
, 1, 1)
213 grid
.SetCellBackgroundColour(wxCYAN
, 2, 2)
214 grid
.UpdateDimensions()
215 grid
.AdjustScrollbars()
218 def OnCloseWindow(self
, event
):
222 #---------------------------------------------------------------------------
224 class TestNotebookWindow(wxFrame
):
225 def __init__(self
, parent
):
226 wxFrame
.__init
__(self
, parent
, -1, 'Test wxNotebook',
227 wxPyDefaultPosition
, wxPyDefaultSize
)
229 nb
= wxNotebook(self
, -1)
231 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
232 win
.SetBackgroundColour(wxBLUE
)
233 nb
.AddPage(win
, "Blue")
235 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
236 win
.SetBackgroundColour(wxRED
)
237 nb
.AddPage(win
, "Red")
239 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
240 win
.SetBackgroundColour(wxGREEN
)
241 nb
.AddPage(win
, "Green")
243 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
244 win
.SetBackgroundColour(wxCYAN
)
245 nb
.AddPage(win
, "Cyan")
247 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
248 win
.SetBackgroundColour(wxWHITE
)
249 nb
.AddPage(win
, "White")
251 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
252 win
.SetBackgroundColour(wxBLACK
)
253 nb
.AddPage(win
, "Black")
255 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
256 win
.SetBackgroundColour(wxNamedColour('MIDNIGHT BLUE'))
257 nb
.AddPage(win
, "MIDNIGHT BLUE")
259 win
= wxWindow(nb
, -1, wxPyDefaultPosition
, wxPyDefaultSize
, wxRAISED_BORDER
)
260 win
.SetBackgroundColour(wxNamedColour('INDIAN RED'))
261 nb
.AddPage(win
, "INDIAN RED")
265 self
.SetSize(wxSize(500, 300)) # force a redraw so the notebook will draw
268 def OnCloseWindow(self
, event
):
271 #---------------------------------------------------------------------------
273 class AppFrame(wxFrame
):
274 def __init__(self
, parent
, id, title
):
275 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
,
277 if wxPlatform
== '__WXMSW__':
278 self
.icon
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
)
279 self
.SetIcon(self
.icon
)
281 self
.mainmenu
= wxMenuBar()
283 menu
.Append(200, 'E&xit', 'Get the heck outta here!')
284 EVT_MENU(self
, 200, self
.OnFileExit
)
285 self
.mainmenu
.Append(menu
, '&File')
287 menu
= self
.MakeTestsMenu()
288 self
.mainmenu
.Append(menu
, '&Tests')
289 self
.SetMenuBar(self
.mainmenu
)
291 self
.log
= wxTextCtrl(self
, -1, '', wxPyDefaultPosition
, wxPyDefaultSize
,
292 wxTE_MULTILINE|wxTE_READONLY
)
293 self
.log
.WriteText('Test 4:\n')
294 (w
, self
.charHeight
) = self
.log
.GetTextExtent('X')
297 def MakeTestsMenu(self
):
301 menu
.Append(mID
, '&Simple Controls')
302 EVT_MENU(self
, mID
, self
.OnTestSimpleControls
)
305 menu
.Append(mID
, '&Timer', '', true
)
306 EVT_MENU(self
, mID
, self
.OnTestTimer
)
311 menu
.Append(mID
, '&Layout Constraints')
312 EVT_MENU(self
, mID
, self
.OnTestLayoutConstraints
)
315 menu
.Append(mID
, '&Grid')
316 EVT_MENU(self
, mID
, self
.OnTestGrid
)
319 smenu
= wxMenu() # make a sub-menu
322 smenu
.Append(mID
, '&Colour')
323 EVT_MENU(self
, mID
, self
.OnTestColourDlg
)
326 smenu
.Append(mID
, '&Directory')
327 EVT_MENU(self
, mID
, self
.OnTestDirDlg
)
330 smenu
.Append(mID
, '&File')
331 EVT_MENU(self
, mID
, self
.OnTestFileDlg
)
334 smenu
.Append(mID
, '&Single Choice')
335 EVT_MENU(self
, mID
, self
.OnTestSingleChoiceDlg
)
338 smenu
.Append(mID
, '&TextEntry')
339 EVT_MENU(self
, mID
, self
.OnTestTextEntryDlg
)
342 smenu
.Append(mID
, '&Font')
343 EVT_MENU(self
, mID
, self
.OnTestFontDlg
)
346 smenu
.Append(mID
, '&PageSetup')
347 EVT_MENU(self
, mID
, self
.OnTestPageSetupDlg
)
350 smenu
.Append(mID
, '&Print')
351 EVT_MENU(self
, mID
, self
.OnTestPrintDlg
)
354 smenu
.Append(mID
, '&Message')
355 EVT_MENU(self
, mID
, self
.OnTestMessageDlg
)
358 menu
.AppendMenu(NewId(), '&Common Dialogs', smenu
)
362 menu
.Append(mID
, '&Notebook')
363 EVT_MENU(self
, mID
, self
.OnTestNotebook
)
370 def WriteText(self
, str):
371 self
.log
.WriteText(str)
372 if wxPlatform
== '__WXMSW__':
373 w
, h
= self
.log
.GetClientSize()
374 numLines
= h
/self
.charHeight
375 x
, y
= self
.log
.PositionToXY(self
.log
.GetLastPosition())
376 self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
+1))
378 def OnFileExit(self
, event
):
381 def OnCloseWindow(self
, event
):
387 def OnTestSimpleControls(self
, event
):
388 dlg
= TestSimpleControlsDlg(self
, self
)
393 def OnTestTimer(self
, event
):
395 self
.mainmenu
.Check(self
.timerID
, false
)
399 self
.mainmenu
.Check(self
.timerID
, true
)
400 self
.timer
= TestTimer(self
)
401 self
.timer
.Start(1000)
403 def OnTestLayoutConstraints(self
, event
):
404 win
= TestLayoutConstraints(self
)
407 def OnTestGrid(self
, event
):
410 win
.SetSize(wxSize(505, 300)) # have to force a resize, or the grid doesn't
411 # show up for some reason....
413 def OnTestColourDlg(self
, event
):
414 data
= wxColourData()
415 data
.SetChooseFull(true
)
416 dlg
= wxColourDialog(self
, data
)
417 if dlg
.ShowModal() == wxID_OK
:
418 data
= dlg
.GetColourData()
419 self
.log
.WriteText('You selected: %s\n' % str(data
.GetColour().Get()))
422 def OnTestDirDlg(self
, event
):
423 dlg
= wxDirDialog(self
)
424 if dlg
.ShowModal() == wxID_OK
:
425 self
.log
.WriteText('You selected: %s\n' % dlg
.GetPath())
428 def OnTestFileDlg(self
, event
):
429 dlg
= wxFileDialog(self
, "Choose a file", ".", "", "*.*", wxOPEN
)
430 if dlg
.ShowModal() == wxID_OK
:
431 self
.log
.WriteText('You selected: %s\n' % dlg
.GetPath())
434 def OnTestSingleChoiceDlg(self
, event
):
435 dlg
= wxSingleChoiceDialog(self
, 'Test Single Choice', 'The Caption',
436 ['zero', 'one', 'two', 'three', 'four', 'five',
437 'six', 'seven', 'eight'])
438 if dlg
.ShowModal() == wxID_OK
:
439 self
.log
.WriteText('You selected: %s\n' % dlg
.GetStringSelection())
442 def OnTestTextEntryDlg(self
, event
):
443 dlg
= wxTextEntryDialog(self
, 'What is your favorite programming language?',
445 #dlg.SetValue("Python is the best!") #### this doesn't work?
446 if dlg
.ShowModal() == wxID_OK
:
447 self
.log
.WriteText('You entered: %s\n' % dlg
.GetValue())
451 def OnTestFontDlg(self
, event
):
452 dlg
= wxFontDialog(self
)
453 if dlg
.ShowModal() == wxID_OK
:
454 data
= dlg
.GetFontData()
455 font
= data
.GetChosenFont()
456 self
.log
.WriteText('You selected: "%s", %d points, color %s\n' %
457 (font
.GetFaceName(), font
.GetPointSize(),
458 data
.GetColour().Get()))
462 def OnTestPageSetupDlg(self
, event
):
463 data
= wxPageSetupData()
464 data
.SetMarginTopLeft(wxPoint(50,50))
465 data
.SetMarginBottomRight(wxPoint(50,50))
466 dlg
= wxPageSetupDialog(self
, data
)
467 if dlg
.ShowModal() == wxID_OK
:
468 data
= dlg
.GetPageSetupData()
469 tl
= data
.GetMarginTopLeft()
470 br
= data
.GetMarginBottomRight()
471 self
.log
.WriteText('Margins are: %s %s\n' % (str(tl
), str(br
)))
474 def OnTestPrintDlg(self
, event
):
476 data
.EnablePrintToFile(true
)
477 data
.EnablePageNumbers(true
)
478 data
.EnableSelection(true
)
479 dlg
= wxPrintDialog(self
, data
)
480 if dlg
.ShowModal() == wxID_OK
:
481 self
.log
.WriteText('\n')
484 def OnTestMessageDlg(self
, event
):
485 dlg
= wxMessageDialog(self
, 'Hello from Python and wxWindows!',
486 'A Message Box', wxOK | wxICON_INFORMATION
)
491 def OnTestNotebook(self
, event
):
492 win
= TestNotebookWindow(self
)
495 #---------------------------------------------------------------------------
500 frame
= AppFrame(NULL
, -1, "Test 4: (lots of little tests...)")
502 self
.SetTopWindow(frame
)
505 #---------------------------------------------------------------------------
512 print wxPython
.gdi
.wxBLUE
513 print wxPython
.gdi
.wxBLUE
.this
523 # for focused testing...
527 frame
= TestLayoutConstraints(NULL
)
529 self
.SetTopWindow(frame
)
536 if __name__
== '__main__':
540 #----------------------------------------------------------------------------
543 # Revision 1.3 1998/08/27 00:01:17 RD
545 # - have discovered some problems but not yet discovered solutions...
547 # Revision 1.2 1998/08/22 19:51:18 RD
548 # some tweaks for wxGTK
550 # Revision 1.1 1998/08/09 08:28:05 RD