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