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