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