]>
Commit | Line | Data |
---|---|---|
cf694132 RD |
1 | #!/bin/env python |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: Main.py | |
4 | # Purpose: Testing lots of stuff, controls, window types, etc. | |
5 | # | |
f6bcfd97 | 6 | # Author: Robin Dunn |
cf694132 | 7 | # |
f6bcfd97 | 8 | # Created: A long time ago, in a galaxy far, far away... |
cf694132 RD |
9 | # RCS-ID: $Id$ |
10 | # Copyright: (c) 1999 by Total Control Software | |
11 | # Licence: wxWindows license | |
12 | #---------------------------------------------------------------------------- | |
13 | ||
6c5ae2d2 | 14 | import sys, os, time, string |
cf694132 | 15 | from wxPython.wx import * |
f6bcfd97 | 16 | from wxPython.html import wxHtmlWindow |
cf694132 | 17 | |
96bfd053 RD |
18 | import images |
19 | ||
cf694132 RD |
20 | #--------------------------------------------------------------------------- |
21 | ||
22 | ||
9c67cbec RD |
23 | ## _treeList = [ |
24 | ## ('New since last release', ['wxGenericDirCtrl', | |
25 | ## 'wxImageFromStream', | |
26 | ## 'RowColSizer', | |
27 | ## 'Unicode', | |
28 | ## 'wxFileHistory', | |
29 | ## ]), | |
30 | ||
31 | ## ('Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame', | |
32 | ## 'wxGrid', 'wxSashWindow', | |
33 | ## 'wxScrolledWindow', 'wxSplitterWindow', | |
34 | ## 'wxStatusBar', 'wxNotebook', | |
35 | ## 'wxHtmlWindow', | |
36 | ## 'wxStyledTextCtrl_1', 'wxStyledTextCtrl_2', | |
37 | ## 'wxPopupWindow', | |
38 | ## 'wxDynamicSashWindow', | |
39 | ## ]), | |
40 | ||
41 | ## ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog', | |
42 | ## 'wxSingleChoiceDialog', 'wxTextEntryDialog', | |
43 | ## 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog', | |
44 | ## 'wxMessageDialog', 'wxProgressDialog', 'wxFindReplaceDialog', | |
45 | ## ]), | |
46 | ||
47 | ## ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice', | |
48 | ## 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'VirtualListCtrl', | |
49 | ## 'wxTextCtrl', | |
50 | ## 'wxTreeCtrl', 'wxSpinButton', 'wxSpinCtrl', 'wxStaticText', | |
51 | ## 'wxStaticBitmap', 'wxRadioBox', 'wxSlider', 'wxToolBar', | |
52 | ## 'wxCalendarCtrl', 'wxToggleButton', | |
53 | ## 'wxEditableListBox', 'wxLEDNumberCtrl', | |
54 | ## ]), | |
55 | ||
56 | ## ('Window Layout', ['wxLayoutConstraints', 'LayoutAnchors', 'Sizers', 'XML_Resource', | |
57 | ## 'RowColSizer', | |
58 | ## ]), | |
59 | ||
60 | ## ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'URLDragAndDrop', | |
61 | ## 'FontEnumerator', | |
62 | ## 'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits', | |
63 | ## 'wxImage', 'wxMask', 'PrintFramework', 'wxOGL', | |
64 | ## 'PythonEvents', 'Threads', | |
65 | ## 'ActiveXWrapper_Acrobat', 'ActiveXWrapper_IE', | |
66 | ## 'wxDragImage', "wxProcess", "FancyText", "OOR", "wxWave", | |
67 | ## 'wxJoystick', 'DrawXXXList', 'ErrorDialogs', 'wxMimeTypesManager', | |
68 | ## 'ContextHelp', 'SplitTree', 'Unicode', 'wxFileHistory', | |
69 | ## ]), | |
70 | ||
71 | ## ('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog', | |
72 | ## 'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar', | |
73 | ## 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow', | |
74 | ## 'FileBrowseButton', 'GenericButtons', 'wxEditor', | |
75 | ## 'ColourSelect', 'ImageBrowser', | |
76 | ## 'infoframe', 'ColourDB', 'PyCrust', 'PyCrustWithFilling', | |
77 | ## 'TablePrint', | |
78 | ## 'wxRightTextCtrl', | |
79 | ## ]), | |
80 | ||
81 | ## ('Cool Contribs', ['pyTree', 'hangman', | |
82 | ## #'SlashDot', | |
83 | ## 'XMLtreeview' | |
84 | ## ]), | |
85 | ||
86 | ## ] | |
87 | ||
88 | ||
cf694132 | 89 | _treeList = [ |
9c67cbec RD |
90 | # new stuff |
91 | ('New since last release', [ | |
92 | 'RowColSizer', | |
93 | 'Unicode', | |
94 | 'wxFileHistory', | |
95 | 'wxGenericDirCtrl', | |
96 | 'wxImageFromStream', | |
97 | ]), | |
98 | ||
99 | # managed windows == things with a caption you can close | |
100 | ('Base Frames and Dialogs', [ | |
101 | 'wxDialog', | |
102 | 'wxFrame', | |
103 | 'wxMDIWindows', | |
104 | 'wxMiniFrame', | |
105 | ]), | |
106 | ||
107 | # the common dialogs | |
108 | ('Common Dialogs', [ | |
109 | 'wxColourDialog', | |
110 | 'wxDirDialog', | |
111 | 'wxFileDialog', | |
112 | 'wxFindReplaceDialog', | |
113 | 'wxFontDialog', | |
114 | 'wxMessageDialog', | |
115 | 'wxPageSetupDialog', | |
116 | 'wxPrintDialog', | |
117 | 'wxProgressDialog', | |
118 | 'wxSingleChoiceDialog', | |
119 | 'wxTextEntryDialog', | |
120 | ]), | |
121 | ||
122 | # dialogs form libraries | |
123 | ('More Dialogs', [ | |
124 | 'ErrorDialogs', | |
125 | 'ImageBrowser', | |
126 | 'wxMultipleChoiceDialog', | |
127 | 'wxScrolledMessageDialog', | |
128 | ]), | |
129 | ||
130 | # core controls | |
131 | ('Core Windows/Controls', [ | |
132 | 'VirtualListCtrl', | |
133 | 'wxButton', | |
134 | 'wxCheckBox', | |
135 | 'wxCheckListBox', | |
136 | 'wxChoice', | |
137 | 'wxComboBox', | |
138 | 'wxGauge', | |
139 | 'wxGenericDirCtrl', | |
140 | 'wxGrid', | |
141 | 'wxListBox', | |
142 | 'wxListCtrl', | |
143 | 'wxNotebook', | |
144 | 'wxPopupWindow', | |
145 | 'wxRadioBox', | |
146 | 'wxSashWindow', | |
147 | 'wxSlider', | |
148 | 'wxScrolledWindow', | |
149 | 'wxSplitterWindow', | |
150 | 'wxSpinButton', | |
151 | 'wxSpinCtrl', | |
152 | 'wxStaticText', | |
153 | 'wxStaticBitmap', | |
154 | 'wxStatusBar', | |
155 | 'wxTextCtrl', | |
9c67cbec RD |
156 | 'wxToggleButton', |
157 | 'wxToolBar', | |
158 | 'wxTreeCtrl', | |
159 | 'wxValidator', | |
160 | ]), | |
161 | ||
162 | # controls coming from other librairies | |
163 | ('More Windows/Controls', [ | |
164 | 'ColourSelect', | |
165 | 'ContextHelp', | |
166 | 'FancyText', | |
167 | 'FileBrowseButton', | |
168 | 'GenericButtons', | |
169 | 'PyCrust', | |
170 | 'PyCrustWithFilling', | |
171 | 'SplitTree', | |
172 | 'TablePrint', | |
173 | 'wxCalendar', | |
174 | 'wxCalendarCtrl', | |
175 | 'wxDynamicSashWindow', | |
176 | 'wxEditableListBox', | |
177 | 'wxEditor', | |
178 | 'wxFloatBar', | |
179 | 'wxHtmlWindow', | |
180 | 'wxLEDNumberCtrl', | |
181 | 'wxMimeTypesManager', | |
182 | 'wxMVCTree', | |
183 | 'wxStyledTextCtrl_1', | |
184 | 'wxStyledTextCtrl_2', | |
185 | 'wxRightTextCtrl', | |
186 | ]), | |
187 | ||
188 | # How to lay out the controls in a frame/dialog | |
189 | ('Window Layout', [ | |
190 | 'LayoutAnchors', | |
191 | 'Layoutf', | |
192 | 'RowColSizer', | |
193 | 'Sizers', | |
194 | 'wxLayoutConstraints', | |
195 | 'XML_Resource', | |
196 | ]), | |
197 | ||
198 | # ditto | |
199 | ('Process and Events', [ | |
200 | 'infoframe', | |
201 | 'OOR', | |
202 | 'PythonEvents', | |
203 | 'Threads', | |
204 | 'wxProcess', | |
205 | 'wxTimer', | |
206 | ]), | |
207 | ||
208 | # Clipboard and DnD | |
209 | ('Clipboard and DnD', [ | |
210 | 'CustomDragAndDrop', | |
211 | 'DragAndDrop', | |
212 | 'URLDragAndDrop', | |
213 | ]), | |
214 | ||
215 | # Images | |
216 | ('Images', [ | |
217 | 'wxDragImage', | |
218 | 'wxImage', | |
219 | 'wxImageFromStream', | |
220 | 'wxMask', | |
221 | ]), | |
222 | ||
223 | # Other stuff | |
224 | ('Miscellaneous', [ | |
225 | 'ColourDB', | |
226 | 'DialogUnits', | |
227 | 'DrawXXXList', | |
228 | 'FontEnumerator', | |
229 | 'PrintFramework', | |
230 | 'Unicode', | |
231 | 'wxFileHistory', | |
232 | 'wxJoystick', | |
233 | 'wxOGL', | |
234 | 'wxWave', | |
235 | ]), | |
236 | ||
237 | # need libs not coming with the demo | |
238 | ('Objects using an external library', [ | |
239 | 'ActiveXWrapper_Acrobat', | |
240 | 'ActiveXWrapper_IE', | |
241 | 'wxGLCanvas', | |
242 | 'wxPlotCanvas', | |
243 | 'wxVTKRenderWindow', | |
244 | ]), | |
245 | ||
246 | # pyTree, hangman, ... in the samples dir | |
247 | ('Check out the samples dir too', [ | |
248 | ]), | |
249 | ||
9c67cbec RD |
250 | ] |
251 | ||
252 | ||
cf694132 RD |
253 | |
254 | #--------------------------------------------------------------------------- | |
255 | ||
76bfdc78 RD |
256 | class MyLog(wxPyLog): |
257 | def __init__(self, textCtrl, logTime=0): | |
258 | wxPyLog.__init__(self) | |
259 | self.tc = textCtrl | |
260 | self.logTime = logTime | |
261 | ||
262 | def DoLogString(self, message, timeStamp): | |
263 | if self.logTime: | |
264 | message = time.strftime("%X", time.localtime(timeStamp)) + \ | |
265 | ": " + message | |
266 | self.tc.AppendText(message + '\n') | |
267 | ||
268 | ||
6c5ae2d2 RD |
269 | #--------------------------------------------------------------------------- |
270 | ||
271 | def opj(path): | |
272 | """Convert paths to the platform-specific separator""" | |
273 | return apply(os.path.join, tuple(string.split(path, '/'))) | |
274 | ||
275 | ||
76bfdc78 RD |
276 | #--------------------------------------------------------------------------- |
277 | ||
cf694132 | 278 | class wxPythonDemo(wxFrame): |
e9159fe8 | 279 | overviewText = "wxPython Overview" |
c368d904 | 280 | |
cf694132 | 281 | def __init__(self, parent, id, title): |
f6bcfd97 BP |
282 | wxFrame.__init__(self, parent, -1, title, size = (800, 600), |
283 | style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) | |
2f90df85 | 284 | |
694759cf | 285 | self.cwd = os.getcwd() |
3ca6a5f0 | 286 | self.curOverview = "" |
694759cf | 287 | |
afb810d9 | 288 | icon = images.getMondrianIcon() |
96bfd053 | 289 | self.SetIcon(icon) |
c368d904 | 290 | |
96bfd053 | 291 | if wxPlatform == '__WXMSW__': |
c368d904 RD |
292 | # setup a taskbar icon, and catch some events from it |
293 | self.tbicon = wxTaskBarIcon() | |
294 | self.tbicon.SetIcon(icon, "wxPython Demo") | |
295 | EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) | |
296 | EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) | |
297 | EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate) | |
298 | EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose) | |
299 | ||
cf694132 RD |
300 | |
301 | self.otherWin = None | |
ccf691a4 | 302 | self.showTip = true |
cf694132 | 303 | EVT_IDLE(self, self.OnIdle) |
f6bcfd97 | 304 | EVT_CLOSE(self, self.OnCloseWindow) |
f3d9dc1d RD |
305 | EVT_ICONIZE(self, self.OnIconfiy) |
306 | EVT_MAXIMIZE(self, self.OnMaximize) | |
cf694132 RD |
307 | |
308 | self.Centre(wxBOTH) | |
309 | self.CreateStatusBar(1, wxST_SIZEGRIP) | |
5a7823f5 | 310 | |
f6bcfd97 BP |
311 | splitter = wxSplitterWindow(self, -1, style=wxNO_3D|wxSP_3D) |
312 | splitter2 = wxSplitterWindow(splitter, -1, style=wxNO_3D|wxSP_3D) | |
5a7823f5 | 313 | |
d56cebe7 RD |
314 | def EmptyHandler(evt): pass |
315 | EVT_ERASE_BACKGROUND(splitter, EmptyHandler) | |
316 | EVT_ERASE_BACKGROUND(splitter2, EmptyHandler) | |
cf694132 | 317 | |
b1cfebd9 | 318 | # Prevent TreeCtrl from displaying all items after destruction when true |
cf694132 RD |
319 | self.dying = false |
320 | ||
321 | # Make a File menu | |
322 | self.mainmenu = wxMenuBar() | |
323 | menu = wxMenu() | |
2f90df85 | 324 | exitID = wxNewId() |
f0261a72 | 325 | menu.Append(exitID, 'E&xit\tAlt-X', 'Get the heck outta here!') |
2f90df85 | 326 | EVT_MENU(self, exitID, self.OnFileExit) |
cf694132 RD |
327 | self.mainmenu.Append(menu, '&File') |
328 | ||
ec3e670f RD |
329 | # Make a Demo menu |
330 | menu = wxMenu() | |
331 | for item in _treeList: | |
332 | submenu = wxMenu() | |
333 | for childItem in item[1]: | |
334 | mID = wxNewId() | |
335 | submenu.Append(mID, childItem) | |
336 | EVT_MENU(self, mID, self.OnDemoMenu) | |
337 | menu.AppendMenu(wxNewId(), item[0], submenu) | |
338 | self.mainmenu.Append(menu, '&Demo') | |
339 | ||
340 | ||
cf694132 | 341 | # Make a Help menu |
2f90df85 | 342 | helpID = wxNewId() |
cf694132 | 343 | menu = wxMenu() |
2f90df85 RD |
344 | menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!') |
345 | EVT_MENU(self, helpID, self.OnHelpAbout) | |
cf694132 RD |
346 | self.mainmenu.Append(menu, '&Help') |
347 | self.SetMenuBar(self.mainmenu) | |
348 | ||
2f90df85 | 349 | # set the menu accellerator table... |
f0261a72 | 350 | aTable = wxAcceleratorTable([(wxACCEL_ALT, ord('X'), exitID), |
2f90df85 RD |
351 | (wxACCEL_CTRL, ord('H'), helpID)]) |
352 | self.SetAcceleratorTable(aTable) | |
353 | ||
bb0054cd | 354 | |
cf694132 | 355 | # Create a TreeCtrl |
f6bcfd97 BP |
356 | tID = wxNewId() |
357 | self.treeMap = {} | |
358 | self.tree = wxTreeCtrl(splitter, tID, | |
359 | style=wxTR_HAS_BUTTONS | | |
360 | wxTR_EDIT_LABELS | | |
afb810d9 RD |
361 | wxTR_HAS_VARIABLE_ROW_HEIGHT) |
362 | ||
f6bcfd97 | 363 | #self.tree.SetBackgroundColour(wxNamedColour("Pink")) |
e9159fe8 | 364 | root = self.tree.AddRoot("wxPython Overview") |
f6bcfd97 BP |
365 | firstChild = None |
366 | for item in _treeList: | |
367 | child = self.tree.AppendItem(root, item[0]) | |
368 | if not firstChild: firstChild = child | |
369 | for childItem in item[1]: | |
370 | theDemo = self.tree.AppendItem(child, childItem) | |
371 | self.treeMap[childItem] = theDemo | |
372 | ||
373 | self.tree.Expand(root) | |
374 | self.tree.Expand(firstChild) | |
375 | EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded) | |
376 | EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed) | |
377 | EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged) | |
378 | EVT_LEFT_DOWN (self.tree, self.OnTreeLeftDown) | |
cf694132 | 379 | |
cf694132 | 380 | # Create a Notebook |
d56cebe7 | 381 | self.nb = wxNotebook(splitter2, -1, style=wxCLIP_CHILDREN) |
cf694132 | 382 | |
c368d904 | 383 | # Set up a wxHtmlWindow on the Overview Notebook page |
0bdca46d RD |
384 | # we put it in a panel first because there seems to be a |
385 | # refresh bug of some sort (wxGTK) when it is directly in | |
386 | # the notebook... | |
387 | if 0: # the old way | |
388 | self.ovr = wxHtmlWindow(self.nb, -1, size=(400, 400)) | |
389 | self.nb.AddPage(self.ovr, self.overviewText) | |
390 | ||
391 | else: # hopefully I can remove this hacky code soon, see bug #216861 | |
392 | panel = wxPanel(self.nb, -1, style=wxCLIP_CHILDREN) | |
393 | self.ovr = wxHtmlWindow(panel, -1, size=(400, 400)) | |
394 | self.nb.AddPage(panel, self.overviewText) | |
395 | ||
396 | def OnOvrSize(evt, ovr=self.ovr): | |
397 | ovr.SetSize(evt.GetSize()) | |
398 | ||
399 | EVT_SIZE(panel, OnOvrSize) | |
400 | EVT_ERASE_BACKGROUND(panel, EmptyHandler) | |
401 | ||
c368d904 | 402 | |
e9159fe8 | 403 | self.SetOverview(self.overviewText, overview) |
cf694132 RD |
404 | |
405 | ||
406 | # Set up a TextCtrl on the Demo Code Notebook page | |
efc5f224 RD |
407 | self.txt = wxTextCtrl(self.nb, -1, |
408 | style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL) | |
cf694132 RD |
409 | self.nb.AddPage(self.txt, "Demo Code") |
410 | ||
411 | ||
cf694132 | 412 | # Set up a log on the View Log Notebook page |
f6bcfd97 | 413 | self.log = wxTextCtrl(splitter2, -1, |
efc5f224 | 414 | style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL) |
342639eb | 415 | |
f6bcfd97 | 416 | # Set the wxWindows log target to be this textctrl |
76bfdc78 | 417 | #wxLog_SetActiveTarget(wxLogTextCtrl(self.log)) |
342639eb RD |
418 | |
419 | # But instead of the above we want to show how to use our own wxLog class | |
76bfdc78 | 420 | wxLog_SetActiveTarget(MyLog(self.log)) |
cf694132 RD |
421 | |
422 | ||
5a7823f5 | 423 | |
f6bcfd97 | 424 | self.Show(true) |
5a7823f5 | 425 | |
f6bcfd97 BP |
426 | # add the windows to the splitter and split it. |
427 | splitter2.SplitHorizontally(self.nb, self.log) | |
f6bcfd97 | 428 | splitter.SplitVertically(self.tree, splitter2) |
afb810d9 | 429 | |
f6bcfd97 BP |
430 | splitter.SetSashPosition(180, true) |
431 | splitter.SetMinimumPaneSize(20) | |
afb810d9 RD |
432 | splitter2.SetSashPosition(450, true) |
433 | splitter2.SetMinimumPaneSize(20) | |
434 | ||
cf694132 | 435 | |
cf694132 | 436 | |
bb0054cd RD |
437 | # select initial items |
438 | self.nb.SetSelection(0) | |
f6bcfd97 | 439 | self.tree.SelectItem(root) |
ec3e670f RD |
440 | |
441 | if len(sys.argv) == 2: | |
442 | try: | |
443 | selectedDemo = self.treeMap[sys.argv[1]] | |
444 | except: | |
445 | selectedDemo = None | |
f6bcfd97 | 446 | if selectedDemo: |
ec3e670f RD |
447 | self.tree.SelectItem(selectedDemo) |
448 | self.tree.EnsureVisible(selectedDemo) | |
449 | ||
bb0054cd | 450 | |
f6bcfd97 | 451 | wxLogMessage('window handle: %s' % self.GetHandle()) |
2abc0a0f RD |
452 | |
453 | ||
cf694132 RD |
454 | #--------------------------------------------- |
455 | def WriteText(self, text): | |
f6bcfd97 BP |
456 | if text[-1:] == '\n': |
457 | text = text[:-1] | |
458 | wxLogMessage(text) | |
459 | ||
cf694132 RD |
460 | |
461 | def write(self, txt): | |
462 | self.WriteText(txt) | |
463 | ||
464 | #--------------------------------------------- | |
465 | def OnItemExpanded(self, event): | |
466 | item = event.GetItem() | |
f6bcfd97 | 467 | wxLogMessage("OnItemExpanded: %s" % self.tree.GetItemText(item)) |
c368d904 | 468 | event.Skip() |
cf694132 RD |
469 | |
470 | #--------------------------------------------- | |
471 | def OnItemCollapsed(self, event): | |
472 | item = event.GetItem() | |
f6bcfd97 | 473 | wxLogMessage("OnItemCollapsed: %s" % self.tree.GetItemText(item)) |
c368d904 | 474 | event.Skip() |
f6bcfd97 BP |
475 | |
476 | #--------------------------------------------- | |
477 | def OnTreeLeftDown(self, event): | |
478 | pt = event.GetPosition(); | |
479 | item, flags = self.tree.HitTest(pt) | |
480 | if item == self.tree.GetSelection(): | |
d975da9b | 481 | self.SetOverview(self.tree.GetItemText(item)+" Overview", self.curOverview) |
185d7c3e | 482 | event.Skip() |
cf694132 RD |
483 | |
484 | #--------------------------------------------- | |
485 | def OnSelChanged(self, event): | |
486 | if self.dying: | |
487 | return | |
488 | ||
5a7823f5 RD |
489 | item = event.GetItem() |
490 | itemText = self.tree.GetItemText(item) | |
491 | self.RunDemo(itemText) | |
492 | ||
493 | ||
494 | #--------------------------------------------- | |
495 | def RunDemo(self, itemText): | |
694759cf | 496 | os.chdir(self.cwd) |
cf694132 RD |
497 | if self.nb.GetPageCount() == 3: |
498 | if self.nb.GetSelection() == 2: | |
499 | self.nb.SetSelection(0) | |
500 | self.nb.DeletePage(2) | |
501 | ||
e9159fe8 | 502 | if itemText == self.overviewText: |
cf694132 | 503 | self.GetDemoFile('Main.py') |
e9159fe8 | 504 | self.SetOverview(self.overviewText, overview) |
cf694132 | 505 | self.nb.Refresh(); |
e91a9dfc | 506 | self.window = None |
cf694132 RD |
507 | |
508 | else: | |
509 | if os.path.exists(itemText + '.py'): | |
9d8bd15f | 510 | wxBeginBusyCursor() |
f6bcfd97 BP |
511 | wxLogMessage("Running demo %s.py..." % itemText) |
512 | try: | |
513 | self.GetDemoFile(itemText + '.py') | |
514 | module = __import__(itemText, globals()) | |
e9159fe8 | 515 | self.SetOverview(itemText + " Overview", module.overview) |
f6bcfd97 BP |
516 | finally: |
517 | wxEndBusyCursor() | |
cf694132 RD |
518 | |
519 | # in case runTest is modal, make sure things look right... | |
520 | self.nb.Refresh(); | |
521 | wxYield() | |
522 | ||
f6bcfd97 | 523 | self.window = module.runTest(self, self.nb, self) ### |
e91a9dfc RD |
524 | if self.window: |
525 | self.nb.AddPage(self.window, 'Demo') | |
eb28fd47 | 526 | #wxYield() TODO: Is this still needed? |
cf694132 | 527 | self.nb.SetSelection(2) |
eb28fd47 | 528 | self.nb.Refresh() # without this wxMac has troubles showing the just added page |
cf694132 RD |
529 | |
530 | else: | |
f6bcfd97 | 531 | self.ovr.SetPage("") |
cf694132 | 532 | self.txt.Clear() |
e91a9dfc | 533 | self.window = None |
cf694132 | 534 | |
2f90df85 | 535 | |
cf694132 RD |
536 | |
537 | #--------------------------------------------- | |
538 | # Get the Demo files | |
539 | def GetDemoFile(self, filename): | |
540 | self.txt.Clear() | |
bb0054cd RD |
541 | try: |
542 | self.txt.SetValue(open(filename).read()) | |
8bf5d46e | 543 | except IOError: |
cf694132 RD |
544 | self.txt.WriteText("Cannot open %s file." % filename) |
545 | ||
546 | self.txt.SetInsertionPoint(0) | |
547 | self.txt.ShowPosition(0) | |
548 | ||
549 | #--------------------------------------------- | |
550 | def SetOverview(self, name, text): | |
f6bcfd97 BP |
551 | self.curOverview = text |
552 | lead = text[:6] | |
553 | if lead != '<html>' and lead != '<HTML>': | |
554 | text = string.join(string.split(text, '\n'), '<br>') | |
f6bcfd97 | 555 | self.ovr.SetPage(text) |
cf694132 | 556 | self.nb.SetPageText(0, name) |
cf694132 RD |
557 | |
558 | #--------------------------------------------- | |
559 | # Menu methods | |
c368d904 | 560 | def OnFileExit(self, *event): |
cf694132 RD |
561 | self.Close() |
562 | ||
563 | ||
564 | def OnHelpAbout(self, event): | |
e166644c | 565 | from About import MyAboutBox |
ec3e670f | 566 | about = MyAboutBox(self) |
cf694132 RD |
567 | about.ShowModal() |
568 | about.Destroy() | |
569 | ||
570 | ||
571 | #--------------------------------------------- | |
572 | def OnCloseWindow(self, event): | |
573 | self.dying = true | |
e91a9dfc | 574 | self.window = None |
26197023 | 575 | self.mainmenu = None |
c368d904 RD |
576 | if hasattr(self, "tbicon"): |
577 | del self.tbicon | |
cf694132 RD |
578 | self.Destroy() |
579 | ||
c368d904 | 580 | |
cf694132 RD |
581 | #--------------------------------------------- |
582 | def OnIdle(self, event): | |
583 | if self.otherWin: | |
584 | self.otherWin.Raise() | |
e91a9dfc | 585 | self.window = self.otherWin |
cf694132 RD |
586 | self.otherWin = None |
587 | ||
ccf691a4 RD |
588 | if self.showTip: |
589 | self.ShowTip() | |
590 | self.showTip = false | |
591 | ||
592 | ||
593 | #--------------------------------------------- | |
594 | def ShowTip(self): | |
595 | try: | |
596 | showTipText = open(opj("data/showTips")).read() | |
597 | showTip, index = eval(showTipText) | |
598 | except IOError: | |
599 | showTip, index = (1, 0) | |
600 | if showTip: | |
601 | tp = wxCreateFileTipProvider(opj("data/tips.txt"), index) | |
602 | showTip = wxShowTip(self, tp) | |
603 | index = tp.GetCurrentTip() | |
604 | open(opj("data/showTips"), "w").write(str( (showTip, index) )) | |
605 | ||
606 | ||
ec3e670f RD |
607 | #--------------------------------------------- |
608 | def OnDemoMenu(self, event): | |
f6bcfd97 BP |
609 | try: |
610 | selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())] | |
611 | except: | |
612 | selectedDemo = None | |
613 | if selectedDemo: | |
614 | self.tree.SelectItem(selectedDemo) | |
615 | self.tree.EnsureVisible(selectedDemo) | |
ec3e670f | 616 | |
c368d904 RD |
617 | |
618 | #--------------------------------------------- | |
619 | def OnTaskBarActivate(self, evt): | |
620 | if self.IsIconized(): | |
621 | self.Iconize(false) | |
622 | if not self.IsShown(): | |
623 | self.Show(true) | |
624 | self.Raise() | |
625 | ||
626 | #--------------------------------------------- | |
627 | ||
628 | TBMENU_RESTORE = 1000 | |
629 | TBMENU_CLOSE = 1001 | |
630 | ||
631 | def OnTaskBarMenu(self, evt): | |
632 | menu = wxMenu() | |
633 | menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo") | |
634 | menu.Append(self.TBMENU_CLOSE, "Close") | |
635 | self.tbicon.PopupMenu(menu) | |
636 | menu.Destroy() | |
637 | ||
638 | #--------------------------------------------- | |
639 | def OnTaskBarClose(self, evt): | |
640 | self.Close() | |
641 | ||
642 | # because of the way wxTaskBarIcon.PopupMenu is implemented we have to | |
643 | # prod the main idle handler a bit to get the window to actually close | |
644 | wxGetApp().ProcessIdle() | |
645 | ||
646 | ||
f3d9dc1d RD |
647 | #--------------------------------------------- |
648 | def OnIconfiy(self, evt): | |
649 | wxLogMessage("OnIconfiy") | |
650 | evt.Skip() | |
651 | ||
652 | #--------------------------------------------- | |
653 | def OnMaximize(self, evt): | |
654 | wxLogMessage("OnMaximize") | |
655 | evt.Skip() | |
656 | ||
657 | ||
658 | ||
659 | ||
cf694132 RD |
660 | #--------------------------------------------------------------------------- |
661 | #--------------------------------------------------------------------------- | |
662 | ||
b5a5d647 RD |
663 | class MySplashScreen(wxSplashScreen): |
664 | def __init__(self): | |
6c5ae2d2 | 665 | bmp = wxImage(opj("bitmaps/splash.gif")).ConvertToBitmap() |
b5a5d647 RD |
666 | wxSplashScreen.__init__(self, bmp, |
667 | wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, | |
668 | 4000, None, -1) | |
669 | EVT_CLOSE(self, self.OnClose) | |
670 | ||
671 | def OnClose(self, evt): | |
9fb56e0c | 672 | frame = wxPythonDemo(None, -1, "wxPython: (A Demonstration)") |
cf694132 | 673 | frame.Show(true) |
ccf691a4 | 674 | evt.Skip() # Make sure the default handler runs too... |
cf694132 | 675 | |
b5a5d647 RD |
676 | |
677 | class MyApp(wxApp): | |
678 | def OnInit(self): | |
679 | """ | |
68320e40 | 680 | Create and show the splash screen. It will then create and show |
b5a5d647 RD |
681 | the main frame when it is time to do so. |
682 | """ | |
683 | wxInitAllImageHandlers() | |
684 | splash = MySplashScreen() | |
685 | splash.Show() | |
b5a5d647 RD |
686 | return true |
687 | ||
688 | ||
689 | ||
cf694132 RD |
690 | #--------------------------------------------------------------------------- |
691 | ||
692 | def main(): | |
e02c03a4 | 693 | try: |
d56cebe7 | 694 | demoPath = os.path.dirname(__file__) |
e02c03a4 RD |
695 | os.chdir(demoPath) |
696 | except: | |
697 | pass | |
cf694132 RD |
698 | app = MyApp(0) |
699 | app.MainLoop() | |
700 | ||
701 | ||
702 | #--------------------------------------------------------------------------- | |
703 | ||
704 | ||
705 | ||
f6bcfd97 BP |
706 | overview = """<html><body> |
707 | <h2>Python</h2> | |
708 | ||
709 | Python is an interpreted, interactive, object-oriented programming | |
710 | language often compared to Tcl, Perl, Scheme, or Java. | |
711 | ||
712 | <p> Python combines remarkable power with very clear syntax. It has | |
713 | modules, classes, exceptions, very high level dynamic data types, and | |
714 | dynamic typing. There are interfaces to many system calls and | |
715 | libraries, and new built-in modules are easily written in C or | |
716 | C++. Python is also usable as an extension language for applications | |
717 | that need a programmable interface. <p> | |
718 | ||
719 | <h2>wxWindows</h2> | |
720 | ||
721 | wxWindows is a free C++ framework designed to make cross-platform | |
722 | programming child's play. Well, almost. wxWindows 2 supports Windows | |
723 | 3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version | |
724 | underway. Other ports are under consideration. <p> | |
725 | ||
726 | wxWindows is a set of libraries that allows C++ applications to | |
727 | compile and run on several different types of computers, with minimal | |
728 | source code changes. There is one library per supported GUI (such as | |
729 | Motif, or Windows). As well as providing a common API (Application | |
730 | Programming Interface) for GUI functionality, it provides | |
731 | functionality for accessing some commonly-used operating system | |
732 | facilities, such as copying or deleting files. wxWindows is a | |
733 | 'framework' in the sense that it provides a lot of built-in | |
734 | functionality, which the application can use or replace as required, | |
735 | thus saving a great deal of coding effort. Basic data structures such | |
736 | as strings, linked lists and hash tables are also supported. | |
737 | ||
738 | <p> | |
739 | <h2>wxPython</h2> | |
740 | ||
741 | wxPython is a Python extension module that encapsulates the wxWindows | |
742 | GUI classes. Currently it is only available for the Win32 and GTK | |
743 | ports of wxWindows, but as soon as the other ports are brought up to | |
744 | the same level as Win32 and GTK, it should be fairly trivial to | |
745 | enable wxPython to be used with the new GUI. | |
746 | ||
747 | <p> | |
748 | ||
749 | The wxPython extension module attempts to mirror the class heiarchy | |
750 | of wxWindows as closely as possible. This means that there is a | |
751 | wxFrame class in wxPython that looks, smells, tastes and acts almost | |
752 | the same as the wxFrame class in the C++ version. Unfortunately, | |
753 | because of differences in the languages, wxPython doesn't match | |
754 | wxWindows exactly, but the differences should be easy to absorb | |
755 | because they are natural to Python. For example, some methods that | |
756 | return multiple values via argument pointers in C++ will return a | |
757 | tuple of values in Python. | |
758 | ||
759 | <p> | |
760 | ||
761 | There is still much to be done for wxPython, many classes still need | |
762 | to be mirrored. Also, wxWindows is still somewhat of a moving target | |
763 | so it is a bit of an effort just keeping wxPython up to date. On the | |
764 | other hand, there are enough of the core classes completed that | |
765 | useful applications can be written. | |
766 | ||
767 | <p> | |
768 | ||
769 | wxPython is close enough to the C++ version that the majority of | |
770 | the wxPython documentation is actually just notes attached to the C++ | |
771 | documents that describe the places where wxPython is different. There | |
772 | is also a series of sample programs included, and a series of | |
773 | documentation pages that assist the programmer in getting started | |
774 | with wxPython. | |
775 | ||
776 | """ | |
cf694132 RD |
777 | |
778 | ||
779 | #---------------------------------------------------------------------------- | |
780 | #---------------------------------------------------------------------------- | |
781 | ||
782 | if __name__ == '__main__': | |
783 | main() | |
784 | ||
785 | #---------------------------------------------------------------------------- | |
786 | ||
787 | ||
788 | ||
789 | ||
790 | ||
791 | ||
792 |