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