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