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