]>
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 | ||
1e4a197e | 14 | import sys, os, time |
cf694132 | 15 | |
1fded56b RD |
16 | import wx # This module uses the new wx namespace |
17 | import wx.html | |
606d919c | 18 | |
96bfd053 RD |
19 | import images |
20 | ||
1e4a197e | 21 | |
cf694132 RD |
22 | #--------------------------------------------------------------------------- |
23 | ||
24 | ||
25 | _treeList = [ | |
9c67cbec | 26 | # new stuff |
1e4a197e | 27 | ('Recent Additions', [ |
1e4a197e | 28 | 'wxScrolledPanel', |
1fded56b RD |
29 | 'ShapedWindow', |
30 | 'NewNamespace', | |
31 | 'PopupMenu', | |
32 | 'AnalogClockWindow', | |
33 | 'MaskedEditControls', | |
34 | 'wxTreeListCtrl', | |
35 | 'wxGrid_MegaExample', | |
9c67cbec RD |
36 | ]), |
37 | ||
1e4a197e | 38 | # managed windows == things with a (optional) caption you can close |
9c67cbec RD |
39 | ('Base Frames and Dialogs', [ |
40 | 'wxDialog', | |
41 | 'wxFrame', | |
42 | 'wxMDIWindows', | |
43 | 'wxMiniFrame', | |
af83019e | 44 | 'wxWizard', |
9c67cbec RD |
45 | ]), |
46 | ||
47 | # the common dialogs | |
48 | ('Common Dialogs', [ | |
49 | 'wxColourDialog', | |
50 | 'wxDirDialog', | |
51 | 'wxFileDialog', | |
1fded56b | 52 | 'wxFileDialog_Save', |
9c67cbec RD |
53 | 'wxFindReplaceDialog', |
54 | 'wxFontDialog', | |
55 | 'wxMessageDialog', | |
56 | 'wxPageSetupDialog', | |
57 | 'wxPrintDialog', | |
58 | 'wxProgressDialog', | |
59 | 'wxSingleChoiceDialog', | |
60 | 'wxTextEntryDialog', | |
61 | ]), | |
62 | ||
af83019e | 63 | # dialogs from libraries |
9c67cbec RD |
64 | ('More Dialogs', [ |
65 | 'ErrorDialogs', | |
66 | 'ImageBrowser', | |
67 | 'wxMultipleChoiceDialog', | |
68 | 'wxScrolledMessageDialog', | |
69 | ]), | |
70 | ||
71 | # core controls | |
72 | ('Core Windows/Controls', [ | |
1fded56b | 73 | 'PopupMenu', |
9c67cbec RD |
74 | 'wxButton', |
75 | 'wxCheckBox', | |
76 | 'wxCheckListBox', | |
77 | 'wxChoice', | |
78 | 'wxComboBox', | |
79 | 'wxGauge', | |
80 | 'wxGenericDirCtrl', | |
81 | 'wxGrid', | |
1fded56b | 82 | 'wxGrid_MegaExample', |
9c67cbec RD |
83 | 'wxListBox', |
84 | 'wxListCtrl', | |
6f48b1b5 | 85 | 'wxListCtrl_virtual', |
3115ef3e | 86 | 'wxMenu', |
9c67cbec RD |
87 | 'wxNotebook', |
88 | 'wxPopupWindow', | |
89 | 'wxRadioBox', | |
1e4a197e | 90 | 'wxRadioButton', |
9c67cbec | 91 | 'wxSashWindow', |
9c67cbec | 92 | 'wxScrolledWindow', |
1e4a197e | 93 | 'wxSlider', |
9c67cbec RD |
94 | 'wxSpinButton', |
95 | 'wxSpinCtrl', | |
1e4a197e | 96 | 'wxSplitterWindow', |
9c67cbec | 97 | 'wxStaticBitmap', |
1e4a197e | 98 | 'wxStaticText', |
9c67cbec RD |
99 | 'wxStatusBar', |
100 | 'wxTextCtrl', | |
9c67cbec RD |
101 | 'wxToggleButton', |
102 | 'wxToolBar', | |
103 | 'wxTreeCtrl', | |
104 | 'wxValidator', | |
105 | ]), | |
106 | ||
107 | # controls coming from other librairies | |
108 | ('More Windows/Controls', [ | |
1e4a197e RD |
109 | #'wxFloatBar', deprecated |
110 | #'wxMVCTree', deprecated | |
1fded56b RD |
111 | #'wxRightTextCtrl', deprecated as we have wxTE_RIGHT now. |
112 | 'AnalogClockWindow', | |
9c67cbec RD |
113 | 'ColourSelect', |
114 | 'ContextHelp', | |
115 | 'FancyText', | |
116 | 'FileBrowseButton', | |
117 | 'GenericButtons', | |
1fded56b RD |
118 | 'MaskedEditControls', |
119 | 'PyShell', | |
9c67cbec | 120 | 'PyCrust', |
9c67cbec RD |
121 | 'SplitTree', |
122 | 'TablePrint', | |
1e4a197e | 123 | 'Throbber', |
9c67cbec RD |
124 | 'wxCalendar', |
125 | 'wxCalendarCtrl', | |
1e4a197e | 126 | 'wxPyColourChooser', |
9c67cbec RD |
127 | 'wxDynamicSashWindow', |
128 | 'wxEditableListBox', | |
129 | 'wxEditor', | |
9c67cbec | 130 | 'wxHtmlWindow', |
c731eb47 | 131 | 'wxIEHtmlWin', |
1e4a197e | 132 | 'wxIntCtrl', |
9c67cbec RD |
133 | 'wxLEDNumberCtrl', |
134 | 'wxMimeTypesManager', | |
1e4a197e RD |
135 | 'wxMultiSash', |
136 | 'wxPopupControl', | |
9c67cbec RD |
137 | 'wxStyledTextCtrl_1', |
138 | 'wxStyledTextCtrl_2', | |
1e4a197e | 139 | 'wxTimeCtrl', |
1fded56b | 140 | 'wxTreeListCtrl', |
9c67cbec RD |
141 | ]), |
142 | ||
143 | # How to lay out the controls in a frame/dialog | |
144 | ('Window Layout', [ | |
145 | 'LayoutAnchors', | |
146 | 'Layoutf', | |
147 | 'RowColSizer', | |
148 | 'Sizers', | |
149 | 'wxLayoutConstraints', | |
1e4a197e | 150 | 'wxScrolledPanel', |
628c7f79 RD |
151 | 'wxXmlResource', |
152 | 'wxXmlResourceHandler', | |
9c67cbec RD |
153 | ]), |
154 | ||
155 | # ditto | |
156 | ('Process and Events', [ | |
1e4a197e | 157 | 'EventManager', |
9c67cbec RD |
158 | 'infoframe', |
159 | 'OOR', | |
160 | 'PythonEvents', | |
161 | 'Threads', | |
1e4a197e | 162 | 'wxKeyEvents', |
9c67cbec RD |
163 | 'wxProcess', |
164 | 'wxTimer', | |
165 | ]), | |
166 | ||
167 | # Clipboard and DnD | |
168 | ('Clipboard and DnD', [ | |
169 | 'CustomDragAndDrop', | |
170 | 'DragAndDrop', | |
171 | 'URLDragAndDrop', | |
172 | ]), | |
173 | ||
174 | # Images | |
1e4a197e RD |
175 | ('Using Images', [ |
176 | 'Throbber', | |
177 | 'wxArtProvider', | |
9c67cbec RD |
178 | 'wxDragImage', |
179 | 'wxImage', | |
180 | 'wxImageFromStream', | |
181 | 'wxMask', | |
182 | ]), | |
183 | ||
184 | # Other stuff | |
185 | ('Miscellaneous', [ | |
186 | 'ColourDB', | |
187 | 'DialogUnits', | |
188 | 'DrawXXXList', | |
189 | 'FontEnumerator', | |
190 | 'PrintFramework', | |
1e4a197e | 191 | 'Throbber', |
9c67cbec RD |
192 | 'Unicode', |
193 | 'wxFileHistory', | |
194 | 'wxJoystick', | |
195 | 'wxOGL', | |
196 | 'wxWave', | |
197 | ]), | |
198 | ||
199 | # need libs not coming with the demo | |
200 | ('Objects using an external library', [ | |
201 | 'ActiveXWrapper_Acrobat', | |
202 | 'ActiveXWrapper_IE', | |
203 | 'wxGLCanvas', | |
204 | 'wxPlotCanvas', | |
9c67cbec RD |
205 | ]), |
206 | ||
70a357c2 | 207 | |
9c67cbec RD |
208 | ('Check out the samples dir too', [ |
209 | ]), | |
210 | ||
9c67cbec RD |
211 | ] |
212 | ||
213 | ||
cf694132 RD |
214 | |
215 | #--------------------------------------------------------------------------- | |
216 | ||
1fded56b | 217 | class MyLog(wx.PyLog): |
76bfdc78 | 218 | def __init__(self, textCtrl, logTime=0): |
1fded56b | 219 | wx.PyLog.__init__(self) |
76bfdc78 RD |
220 | self.tc = textCtrl |
221 | self.logTime = logTime | |
222 | ||
223 | def DoLogString(self, message, timeStamp): | |
224 | if self.logTime: | |
225 | message = time.strftime("%X", time.localtime(timeStamp)) + \ | |
226 | ": " + message | |
1e4a197e RD |
227 | if self.tc: |
228 | self.tc.AppendText(message + '\n') | |
76bfdc78 RD |
229 | |
230 | ||
1fded56b | 231 | class MyTP(wx.PyTipProvider): |
861a0196 RD |
232 | def GetTip(self): |
233 | return "This is my tip" | |
234 | ||
1fded56b RD |
235 | #--------------------------------------------------------------------------- |
236 | # A class to be used to display source code in the demo. Try using the | |
237 | # wxSTC in the wxStyledTextCtrl_2 sample first, fall back to wxTextCtrl | |
238 | # if there is an error, such as the stc module not being present. | |
239 | ||
240 | try: | |
241 | ##raise ImportError | |
242 | from wx import stc | |
243 | from wxStyledTextCtrl_2 import PythonSTC | |
244 | class DemoCodeViewer(PythonSTC): | |
245 | def __init__(self, parent, ID): | |
246 | PythonSTC.__init__(self, parent, ID) | |
247 | self.SetEdgeMode(stc.STC_EDGE_NONE) | |
248 | self.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)) | |
249 | self.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)) | |
250 | ||
251 | # Some methods to make it compatible with how the wxTextCtrl is used | |
252 | def SetValue(self, value): | |
253 | self.SetReadOnly(False) | |
254 | self.SetText(value) | |
255 | self.SetReadOnly(True) | |
256 | ||
257 | def Clear(self): | |
258 | self.ClearAll() | |
259 | ||
260 | def SetInsertionPoint(self, pos): | |
261 | self.SetCurrentPos(pos) | |
262 | ||
263 | def ShowPosition(self, pos): | |
264 | self.GotoPos(pos) | |
265 | ||
266 | def GetLastPosition(self): | |
267 | return self.GetLength() | |
268 | ||
269 | def GetRange(self, start, end): | |
270 | return self.GetTextRange(start, end) | |
271 | ||
272 | def GetSelection(self): | |
273 | return self.GetAnchor(), self.GetCurrentPos() | |
274 | ||
275 | def SetSelection(self, start, end): | |
276 | self.SetSelectionStart(start) | |
277 | self.SetSelectionEnd(end) | |
278 | ||
279 | ||
280 | except ImportError: | |
281 | class DemoCodeViewer(wx.TextCtrl): | |
282 | def __init__(self, parent, ID): | |
283 | wx.TextCtrl.__init__(self, parent, ID, style = | |
284 | wx.TE_MULTILINE | wx.TE_READONLY | | |
285 | wx.HSCROLL | wx.TE_RICH2 | wx.TE_NOHIDESEL) | |
286 | ||
287 | ||
6c5ae2d2 RD |
288 | #--------------------------------------------------------------------------- |
289 | ||
290 | def opj(path): | |
291 | """Convert paths to the platform-specific separator""" | |
1e4a197e | 292 | return apply(os.path.join, tuple(path.split('/'))) |
6c5ae2d2 RD |
293 | |
294 | ||
76bfdc78 RD |
295 | #--------------------------------------------------------------------------- |
296 | ||
1fded56b | 297 | class wxPythonDemo(wx.Frame): |
e9159fe8 | 298 | overviewText = "wxPython Overview" |
c368d904 | 299 | |
cf694132 | 300 | def __init__(self, parent, id, title): |
1fded56b RD |
301 | wx.Frame.__init__(self, parent, -1, title, size = (800, 600), |
302 | style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) | |
2f90df85 | 303 | |
694759cf | 304 | self.cwd = os.getcwd() |
3ca6a5f0 | 305 | self.curOverview = "" |
1e4a197e | 306 | self.window = None |
694759cf | 307 | |
afb810d9 | 308 | icon = images.getMondrianIcon() |
96bfd053 | 309 | self.SetIcon(icon) |
c368d904 | 310 | |
1fded56b | 311 | if wx.Platform == '__WXMSW__': |
c368d904 | 312 | # setup a taskbar icon, and catch some events from it |
1fded56b | 313 | self.tbicon = wx.TaskBarIcon() |
c368d904 | 314 | self.tbicon.SetIcon(icon, "wxPython Demo") |
1fded56b RD |
315 | wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) |
316 | wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) | |
317 | wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate) | |
318 | wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose) | |
c368d904 | 319 | |
1fded56b | 320 | wx.CallAfter(self.ShowTip) |
cf694132 RD |
321 | |
322 | self.otherWin = None | |
1fded56b RD |
323 | wx.EVT_IDLE(self, self.OnIdle) |
324 | wx.EVT_CLOSE(self, self.OnCloseWindow) | |
325 | wx.EVT_ICONIZE(self, self.OnIconfiy) | |
326 | wx.EVT_MAXIMIZE(self, self.OnMaximize) | |
cf694132 | 327 | |
1fded56b RD |
328 | self.Centre(wx.BOTH) |
329 | self.CreateStatusBar(1, wx.ST_SIZEGRIP) | |
5a7823f5 | 330 | |
1fded56b RD |
331 | splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D|wx.SP_3D) |
332 | splitter2 = wx.SplitterWindow(splitter, -1, style=wx.NO_3D|wx.SP_3D) | |
5a7823f5 | 333 | |
d56cebe7 | 334 | def EmptyHandler(evt): pass |
1fded56b RD |
335 | wx.EVT_ERASE_BACKGROUND(splitter, EmptyHandler) |
336 | wx.EVT_ERASE_BACKGROUND(splitter2, EmptyHandler) | |
cf694132 | 337 | |
1e4a197e RD |
338 | # Prevent TreeCtrl from displaying all items after destruction when True |
339 | self.dying = False | |
cf694132 RD |
340 | |
341 | # Make a File menu | |
1fded56b RD |
342 | self.mainmenu = wx.MenuBar() |
343 | menu = wx.Menu() | |
344 | exitID = wx.NewId() | |
f0261a72 | 345 | menu.Append(exitID, 'E&xit\tAlt-X', 'Get the heck outta here!') |
1fded56b RD |
346 | wx.EVT_MENU(self, exitID, self.OnFileExit) |
347 | wx.App_SetMacExitMenuItemId(exitID) | |
cf694132 RD |
348 | self.mainmenu.Append(menu, '&File') |
349 | ||
ec3e670f | 350 | # Make a Demo menu |
1fded56b | 351 | menu = wx.Menu() |
ec3e670f | 352 | for item in _treeList: |
1fded56b | 353 | submenu = wx.Menu() |
ec3e670f | 354 | for childItem in item[1]: |
1fded56b | 355 | mID = wx.NewId() |
ec3e670f | 356 | submenu.Append(mID, childItem) |
1fded56b RD |
357 | wx.EVT_MENU(self, mID, self.OnDemoMenu) |
358 | menu.AppendMenu(wx.NewId(), item[0], submenu) | |
ec3e670f RD |
359 | self.mainmenu.Append(menu, '&Demo') |
360 | ||
361 | ||
cf694132 | 362 | # Make a Help menu |
1fded56b RD |
363 | helpID = wx.NewId() |
364 | findID = wx.NewId() | |
365 | findnextID = wx.NewId() | |
366 | menu = wx.Menu() | |
1e4a197e RD |
367 | menu.Append(findID, '&Find\tCtrl-F', 'Find in the Demo Code') |
368 | menu.Append(findnextID, 'Find &Next\tF3', 'Find Next') | |
369 | menu.AppendSeparator() | |
2f90df85 | 370 | menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!') |
1fded56b RD |
371 | wx.App_SetMacAboutMenuItemId(helpID) |
372 | wx.EVT_MENU(self, helpID, self.OnHelpAbout) | |
373 | wx.EVT_MENU(self, findID, self.OnHelpFind) | |
374 | wx.EVT_MENU(self, findnextID, self.OnFindNext) | |
375 | wx.EVT_COMMAND_FIND(self, -1, self.OnFind) | |
376 | wx.EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind) | |
377 | wx.EVT_COMMAND_FIND_CLOSE(self, -1 , self.OnFindClose) | |
cf694132 RD |
378 | self.mainmenu.Append(menu, '&Help') |
379 | self.SetMenuBar(self.mainmenu) | |
380 | ||
1fded56b | 381 | self.finddata = wx.FindReplaceData() |
1e4a197e RD |
382 | |
383 | if 0: | |
384 | # This is another way to set Accelerators, in addition to | |
385 | # using the '\t<key>' syntax in the menu items. | |
1fded56b RD |
386 | aTable = wx.AcceleratorTable([(wx.ACCEL_ALT, ord('X'), exitID), |
387 | (wx.ACCEL_CTRL, ord('H'), helpID), | |
388 | (wx.ACCEL_CTRL, ord('F'), findID), | |
389 | (wx.ACCEL_NORMAL, WXK_F3, findnextID) | |
390 | ]) | |
1e4a197e | 391 | self.SetAcceleratorTable(aTable) |
2f90df85 | 392 | |
bb0054cd | 393 | |
cf694132 | 394 | # Create a TreeCtrl |
1fded56b | 395 | tID = wx.NewId() |
f6bcfd97 | 396 | self.treeMap = {} |
1fded56b RD |
397 | self.tree = wx.TreeCtrl(splitter, tID, |
398 | style=wx.TR_HAS_BUTTONS | | |
399 | wx.TR_HAS_VARIABLE_ROW_HEIGHT | |
eb0f373c | 400 | ) |
afb810d9 | 401 | |
e9159fe8 | 402 | root = self.tree.AddRoot("wxPython Overview") |
f6bcfd97 BP |
403 | firstChild = None |
404 | for item in _treeList: | |
405 | child = self.tree.AppendItem(root, item[0]) | |
406 | if not firstChild: firstChild = child | |
407 | for childItem in item[1]: | |
408 | theDemo = self.tree.AppendItem(child, childItem) | |
409 | self.treeMap[childItem] = theDemo | |
410 | ||
411 | self.tree.Expand(root) | |
412 | self.tree.Expand(firstChild) | |
1fded56b RD |
413 | wx.EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded) |
414 | wx.EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed) | |
415 | wx.EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged) | |
416 | wx.EVT_LEFT_DOWN (self.tree, self.OnTreeLeftDown) | |
cf694132 | 417 | |
cf694132 | 418 | # Create a Notebook |
1fded56b | 419 | self.nb = wx.Notebook(splitter2, -1, style=wx.CLIP_CHILDREN) |
cf694132 | 420 | |
1fded56b | 421 | # Set up a wx.html.HtmlWindow on the Overview Notebook page |
0bdca46d RD |
422 | # we put it in a panel first because there seems to be a |
423 | # refresh bug of some sort (wxGTK) when it is directly in | |
424 | # the notebook... | |
425 | if 0: # the old way | |
1fded56b | 426 | self.ovr = wx.html.HtmlWindow(self.nb, -1, size=(400, 400)) |
0bdca46d RD |
427 | self.nb.AddPage(self.ovr, self.overviewText) |
428 | ||
1fded56b RD |
429 | else: # hopefully I can remove this hacky code soon, see SF bug #216861 |
430 | panel = wx.Panel(self.nb, -1, style=wx.CLIP_CHILDREN) | |
431 | self.ovr = wx.html.HtmlWindow(panel, -1, size=(400, 400)) | |
0bdca46d RD |
432 | self.nb.AddPage(panel, self.overviewText) |
433 | ||
434 | def OnOvrSize(evt, ovr=self.ovr): | |
435 | ovr.SetSize(evt.GetSize()) | |
436 | ||
1fded56b RD |
437 | wx.EVT_SIZE(panel, OnOvrSize) |
438 | wx.EVT_ERASE_BACKGROUND(panel, EmptyHandler) | |
0bdca46d | 439 | |
c368d904 | 440 | |
e9159fe8 | 441 | self.SetOverview(self.overviewText, overview) |
cf694132 RD |
442 | |
443 | ||
1fded56b RD |
444 | # Set up a notebook page for viewing the source code of each sample |
445 | self.txt = DemoCodeViewer(self.nb, -1) | |
cf694132 | 446 | self.nb.AddPage(self.txt, "Demo Code") |
1fded56b | 447 | self.GetDemoFile('Main.py') |
cf694132 RD |
448 | |
449 | ||
cf694132 | 450 | # Set up a log on the View Log Notebook page |
1fded56b RD |
451 | self.log = wx.TextCtrl(splitter2, -1, |
452 | style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL) | |
342639eb | 453 | |
f6bcfd97 | 454 | # Set the wxWindows log target to be this textctrl |
1fded56b | 455 | #wx.Log_SetActiveTarget(wx.LogTextCtrl(self.log)) |
342639eb | 456 | |
1fded56b RD |
457 | # But instead of the above we want to show how to use our own wx.Log class |
458 | wx.Log_SetActiveTarget(MyLog(self.log)) | |
cf694132 | 459 | |
f9b24f07 | 460 | # for serious debugging |
1fded56b RD |
461 | #wx.Log_SetActiveTarget(wx.LogStderr()) |
462 | #wx.Log_SetTraceMask(wx.TraceMessages) | |
5a7823f5 | 463 | |
1e4a197e | 464 | self.Show(True) |
5a7823f5 | 465 | |
f9b24f07 | 466 | |
f6bcfd97 | 467 | # add the windows to the splitter and split it. |
1e4a197e RD |
468 | splitter2.SplitHorizontally(self.nb, self.log, 450) |
469 | splitter.SplitVertically(self.tree, splitter2, 180) | |
afb810d9 | 470 | |
f6bcfd97 | 471 | splitter.SetMinimumPaneSize(20) |
afb810d9 RD |
472 | splitter2.SetMinimumPaneSize(20) |
473 | ||
cf694132 | 474 | |
cf694132 | 475 | |
bb0054cd RD |
476 | # select initial items |
477 | self.nb.SetSelection(0) | |
f6bcfd97 | 478 | self.tree.SelectItem(root) |
ec3e670f RD |
479 | |
480 | if len(sys.argv) == 2: | |
481 | try: | |
482 | selectedDemo = self.treeMap[sys.argv[1]] | |
483 | except: | |
484 | selectedDemo = None | |
f6bcfd97 | 485 | if selectedDemo: |
ec3e670f RD |
486 | self.tree.SelectItem(selectedDemo) |
487 | self.tree.EnsureVisible(selectedDemo) | |
488 | ||
bb0054cd | 489 | |
1fded56b | 490 | wx.LogMessage('window handle: %s' % self.GetHandle()) |
2abc0a0f RD |
491 | |
492 | ||
cf694132 RD |
493 | #--------------------------------------------- |
494 | def WriteText(self, text): | |
f6bcfd97 BP |
495 | if text[-1:] == '\n': |
496 | text = text[:-1] | |
1fded56b | 497 | wx.LogMessage(text) |
f6bcfd97 | 498 | |
cf694132 RD |
499 | |
500 | def write(self, txt): | |
501 | self.WriteText(txt) | |
502 | ||
503 | #--------------------------------------------- | |
504 | def OnItemExpanded(self, event): | |
505 | item = event.GetItem() | |
1fded56b | 506 | wx.LogMessage("OnItemExpanded: %s" % self.tree.GetItemText(item)) |
c368d904 | 507 | event.Skip() |
cf694132 RD |
508 | |
509 | #--------------------------------------------- | |
510 | def OnItemCollapsed(self, event): | |
511 | item = event.GetItem() | |
1fded56b | 512 | wx.LogMessage("OnItemCollapsed: %s" % self.tree.GetItemText(item)) |
c368d904 | 513 | event.Skip() |
f6bcfd97 BP |
514 | |
515 | #--------------------------------------------- | |
516 | def OnTreeLeftDown(self, event): | |
517 | pt = event.GetPosition(); | |
518 | item, flags = self.tree.HitTest(pt) | |
519 | if item == self.tree.GetSelection(): | |
d975da9b | 520 | self.SetOverview(self.tree.GetItemText(item)+" Overview", self.curOverview) |
185d7c3e | 521 | event.Skip() |
cf694132 RD |
522 | |
523 | #--------------------------------------------- | |
524 | def OnSelChanged(self, event): | |
525 | if self.dying: | |
526 | return | |
527 | ||
5a7823f5 RD |
528 | item = event.GetItem() |
529 | itemText = self.tree.GetItemText(item) | |
530 | self.RunDemo(itemText) | |
531 | ||
532 | ||
533 | #--------------------------------------------- | |
534 | def RunDemo(self, itemText): | |
694759cf | 535 | os.chdir(self.cwd) |
cf694132 RD |
536 | if self.nb.GetPageCount() == 3: |
537 | if self.nb.GetSelection() == 2: | |
538 | self.nb.SetSelection(0) | |
1e4a197e RD |
539 | # inform the window that it's time to quit if it cares |
540 | if self.window is not None: | |
541 | if hasattr(self.window, "ShutdownDemo"): | |
542 | self.window.ShutdownDemo() | |
1fded56b | 543 | wx.SafeYield() # in case the page has pending events |
cf694132 RD |
544 | self.nb.DeletePage(2) |
545 | ||
e9159fe8 | 546 | if itemText == self.overviewText: |
cf694132 | 547 | self.GetDemoFile('Main.py') |
e9159fe8 | 548 | self.SetOverview(self.overviewText, overview) |
cf694132 | 549 | self.nb.Refresh(); |
e91a9dfc | 550 | self.window = None |
cf694132 RD |
551 | |
552 | else: | |
553 | if os.path.exists(itemText + '.py'): | |
1fded56b RD |
554 | wx.BeginBusyCursor() |
555 | wx.LogMessage("Running demo %s.py..." % itemText) | |
f6bcfd97 BP |
556 | try: |
557 | self.GetDemoFile(itemText + '.py') | |
558 | module = __import__(itemText, globals()) | |
e9159fe8 | 559 | self.SetOverview(itemText + " Overview", module.overview) |
f6bcfd97 | 560 | finally: |
1fded56b | 561 | wx.EndBusyCursor() |
5a1eefc7 | 562 | self.tree.Refresh() |
cf694132 RD |
563 | |
564 | # in case runTest is modal, make sure things look right... | |
565 | self.nb.Refresh(); | |
1fded56b | 566 | wx.SafeYield() |
cf694132 | 567 | |
f6bcfd97 | 568 | self.window = module.runTest(self, self.nb, self) ### |
1e4a197e | 569 | if self.window is not None: |
e91a9dfc | 570 | self.nb.AddPage(self.window, 'Demo') |
cf694132 | 571 | self.nb.SetSelection(2) |
eb28fd47 | 572 | self.nb.Refresh() # without this wxMac has troubles showing the just added page |
cf694132 RD |
573 | |
574 | else: | |
f6bcfd97 | 575 | self.ovr.SetPage("") |
cf694132 | 576 | self.txt.Clear() |
e91a9dfc | 577 | self.window = None |
cf694132 | 578 | |
2f90df85 | 579 | |
cf694132 RD |
580 | |
581 | #--------------------------------------------- | |
582 | # Get the Demo files | |
583 | def GetDemoFile(self, filename): | |
584 | self.txt.Clear() | |
bb0054cd RD |
585 | try: |
586 | self.txt.SetValue(open(filename).read()) | |
8bf5d46e | 587 | except IOError: |
1fded56b | 588 | self.txt.SetValue("Cannot open %s file." % filename) |
cf694132 RD |
589 | |
590 | self.txt.SetInsertionPoint(0) | |
591 | self.txt.ShowPosition(0) | |
592 | ||
593 | #--------------------------------------------- | |
594 | def SetOverview(self, name, text): | |
f6bcfd97 BP |
595 | self.curOverview = text |
596 | lead = text[:6] | |
597 | if lead != '<html>' and lead != '<HTML>': | |
1e4a197e | 598 | text = '<br>'.join(text.split('\n')) |
f6bcfd97 | 599 | self.ovr.SetPage(text) |
cf694132 | 600 | self.nb.SetPageText(0, name) |
cf694132 RD |
601 | |
602 | #--------------------------------------------- | |
603 | # Menu methods | |
c368d904 | 604 | def OnFileExit(self, *event): |
cf694132 RD |
605 | self.Close() |
606 | ||
cf694132 | 607 | def OnHelpAbout(self, event): |
e166644c | 608 | from About import MyAboutBox |
ec3e670f | 609 | about = MyAboutBox(self) |
cf694132 RD |
610 | about.ShowModal() |
611 | about.Destroy() | |
612 | ||
1e4a197e RD |
613 | def OnHelpFind(self, event): |
614 | self.nb.SetSelection(1) | |
1fded56b RD |
615 | self.finddlg = wx.FindReplaceDialog(self, self.finddata, "Find", |
616 | wx.FR_NOUPDOWN | | |
617 | wx.FR_NOMATCHCASE | | |
618 | wx.FR_NOWHOLEWORD) | |
1e4a197e RD |
619 | self.finddlg.Show(True) |
620 | ||
621 | def OnFind(self, event): | |
622 | self.nb.SetSelection(1) | |
623 | end = self.txt.GetLastPosition() | |
624 | textstring = self.txt.GetRange(0, end).lower() | |
625 | start = self.txt.GetSelection()[1] | |
626 | findstring = self.finddata.GetFindString().lower() | |
627 | loc = textstring.find(findstring, start) | |
628 | if loc == -1 and start != 0: | |
629 | # string not found, start at beginning | |
630 | start = 0 | |
631 | loc = textstring.find(findstring, start) | |
632 | if loc == -1: | |
1fded56b | 633 | dlg = wx.MessageDialog(self, 'Find String Not Found', |
1e4a197e | 634 | 'Find String Not Found in Demo File', |
1fded56b | 635 | wx.OK | wx.ICON_INFORMATION) |
1e4a197e RD |
636 | dlg.ShowModal() |
637 | dlg.Destroy() | |
638 | if self.finddlg: | |
639 | if loc == -1: | |
640 | self.finddlg.SetFocus() | |
641 | return | |
642 | else: | |
643 | self.finddlg.Destroy() | |
1e4a197e | 644 | self.txt.ShowPosition(loc) |
1fded56b | 645 | self.txt.SetSelection(loc, loc + len(findstring)) |
1e4a197e RD |
646 | |
647 | ||
648 | ||
649 | def OnFindNext(self, event): | |
650 | if self.finddata.GetFindString(): | |
651 | self.OnFind(event) | |
652 | else: | |
653 | self.OnHelpFind(event) | |
654 | ||
655 | def OnFindClose(self, event): | |
656 | event.GetDialog().Destroy() | |
657 | ||
cf694132 RD |
658 | |
659 | #--------------------------------------------- | |
660 | def OnCloseWindow(self, event): | |
1e4a197e | 661 | self.dying = True |
e91a9dfc | 662 | self.window = None |
26197023 | 663 | self.mainmenu = None |
c368d904 RD |
664 | if hasattr(self, "tbicon"): |
665 | del self.tbicon | |
cf694132 RD |
666 | self.Destroy() |
667 | ||
c368d904 | 668 | |
cf694132 RD |
669 | #--------------------------------------------- |
670 | def OnIdle(self, event): | |
671 | if self.otherWin: | |
672 | self.otherWin.Raise() | |
e91a9dfc | 673 | self.window = self.otherWin |
cf694132 RD |
674 | self.otherWin = None |
675 | ||
ccf691a4 RD |
676 | |
677 | #--------------------------------------------- | |
678 | def ShowTip(self): | |
679 | try: | |
680 | showTipText = open(opj("data/showTips")).read() | |
681 | showTip, index = eval(showTipText) | |
682 | except IOError: | |
683 | showTip, index = (1, 0) | |
684 | if showTip: | |
1fded56b | 685 | tp = wx.CreateFileTipProvider(opj("data/tips.txt"), index) |
861a0196 | 686 | ##tp = MyTP(0) |
1fded56b | 687 | showTip = wx.ShowTip(self, tp) |
ccf691a4 RD |
688 | index = tp.GetCurrentTip() |
689 | open(opj("data/showTips"), "w").write(str( (showTip, index) )) | |
690 | ||
691 | ||
ec3e670f RD |
692 | #--------------------------------------------- |
693 | def OnDemoMenu(self, event): | |
f6bcfd97 BP |
694 | try: |
695 | selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())] | |
696 | except: | |
697 | selectedDemo = None | |
698 | if selectedDemo: | |
699 | self.tree.SelectItem(selectedDemo) | |
700 | self.tree.EnsureVisible(selectedDemo) | |
ec3e670f | 701 | |
c368d904 RD |
702 | |
703 | #--------------------------------------------- | |
704 | def OnTaskBarActivate(self, evt): | |
705 | if self.IsIconized(): | |
1e4a197e | 706 | self.Iconize(False) |
c368d904 | 707 | if not self.IsShown(): |
1e4a197e | 708 | self.Show(True) |
c368d904 RD |
709 | self.Raise() |
710 | ||
711 | #--------------------------------------------- | |
712 | ||
713 | TBMENU_RESTORE = 1000 | |
714 | TBMENU_CLOSE = 1001 | |
715 | ||
716 | def OnTaskBarMenu(self, evt): | |
1fded56b | 717 | menu = wx.Menu() |
c368d904 RD |
718 | menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo") |
719 | menu.Append(self.TBMENU_CLOSE, "Close") | |
720 | self.tbicon.PopupMenu(menu) | |
721 | menu.Destroy() | |
722 | ||
723 | #--------------------------------------------- | |
724 | def OnTaskBarClose(self, evt): | |
725 | self.Close() | |
726 | ||
1fded56b | 727 | # because of the way wx.TaskBarIcon.PopupMenu is implemented we have to |
c368d904 | 728 | # prod the main idle handler a bit to get the window to actually close |
1fded56b | 729 | wx.GetApp().ProcessIdle() |
c368d904 RD |
730 | |
731 | ||
f3d9dc1d RD |
732 | #--------------------------------------------- |
733 | def OnIconfiy(self, evt): | |
1fded56b | 734 | wx.LogMessage("OnIconfiy") |
f3d9dc1d RD |
735 | evt.Skip() |
736 | ||
737 | #--------------------------------------------- | |
738 | def OnMaximize(self, evt): | |
1fded56b | 739 | wx.LogMessage("OnMaximize") |
f3d9dc1d RD |
740 | evt.Skip() |
741 | ||
742 | ||
743 | ||
744 | ||
cf694132 RD |
745 | #--------------------------------------------------------------------------- |
746 | #--------------------------------------------------------------------------- | |
747 | ||
1fded56b | 748 | class MySplashScreen(wx.SplashScreen): |
b5a5d647 | 749 | def __init__(self): |
1fded56b RD |
750 | bmp = wx.Image(opj("bitmaps/splash.gif")).ConvertToBitmap() |
751 | wx.SplashScreen.__init__(self, bmp, | |
752 | wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, | |
40c4c5a3 | 753 | 4000, None, -1, |
1fded56b RD |
754 | style = wx.SIMPLE_BORDER|wx.FRAME_NO_TASKBAR|wx.STAY_ON_TOP) |
755 | wx.EVT_CLOSE(self, self.OnClose) | |
b5a5d647 RD |
756 | |
757 | def OnClose(self, evt): | |
9fb56e0c | 758 | frame = wxPythonDemo(None, -1, "wxPython: (A Demonstration)") |
1e4a197e | 759 | frame.Show() |
ccf691a4 | 760 | evt.Skip() # Make sure the default handler runs too... |
cf694132 | 761 | |
b5a5d647 | 762 | |
1fded56b | 763 | class MyApp(wx.App): |
b5a5d647 RD |
764 | def OnInit(self): |
765 | """ | |
68320e40 | 766 | Create and show the splash screen. It will then create and show |
b5a5d647 RD |
767 | the main frame when it is time to do so. |
768 | """ | |
1e4a197e RD |
769 | |
770 | #import locale | |
1fded56b | 771 | #self.locale = wx.Locale(wx.LANGUAGE_FRENCH) |
1e4a197e RD |
772 | #locale.setlocale(locale.LC_ALL, 'fr') |
773 | ||
1fded56b | 774 | wx.InitAllImageHandlers() |
b5a5d647 RD |
775 | splash = MySplashScreen() |
776 | splash.Show() | |
1e4a197e | 777 | return True |
b5a5d647 RD |
778 | |
779 | ||
780 | ||
cf694132 RD |
781 | #--------------------------------------------------------------------------- |
782 | ||
783 | def main(): | |
e02c03a4 | 784 | try: |
d56cebe7 | 785 | demoPath = os.path.dirname(__file__) |
e02c03a4 RD |
786 | os.chdir(demoPath) |
787 | except: | |
788 | pass | |
1fded56b | 789 | app = MyApp(wx.Platform == "__WXMAC__") |
cf694132 RD |
790 | app.MainLoop() |
791 | ||
792 | ||
793 | #--------------------------------------------------------------------------- | |
794 | ||
795 | ||
796 | ||
f6bcfd97 | 797 | overview = """<html><body> |
1fded56b RD |
798 | <h2>wxPython</h2> |
799 | ||
800 | <p> wxPython is a <b>GUI toolkit</b> for the <a | |
801 | href="http://www.python.org/">Python</a> programming language. It | |
802 | allows Python programmers to create programs with a robust, highly | |
803 | functional graphical user interface, simply and easily. It is | |
804 | implemented as a Python extension module (native code) that wraps the | |
805 | popular <a href="http://wxwindows.org/front.htm">wxWindows</a> cross | |
806 | platform GUI library, which is written in C++. | |
807 | ||
808 | <p> Like Python and wxWindows, wxPython is <b>Open Source</b> which | |
809 | means that it is free for anyone to use and the source code is | |
810 | available for anyone to look at and modify. Or anyone can contribute | |
811 | fixes or enhnacments to the project. | |
812 | ||
813 | <p> wxPython is a <b>cross-platform</b> toolkit. This means that the | |
814 | same program will run on multiple platforms without modification. | |
815 | Currently supported platforms are 32-bit Microsoft Windows, most Unix | |
816 | or unix-like systems, and Macintosh OS X. Since the language is | |
817 | Python, wxPython programs are <b>simple, easy</b> to write and easy to | |
818 | understand. | |
819 | ||
820 | <p> <b>This demo</b> is not only a collection of test cases for | |
821 | wxPython, but is also designed to help you learn about and how to use | |
822 | wxPython. Each sample is listed in the tree control on the left. | |
823 | When a sample is selected in the tree then a module is loaded and run | |
824 | (usually in a tab of this notebook,) and the source code of the module | |
825 | is loaded in another tab for you to browse and learn from. | |
826 | ||
827 | """ | |
cf694132 RD |
828 | |
829 | ||
830 | #---------------------------------------------------------------------------- | |
831 | #---------------------------------------------------------------------------- | |
832 | ||
833 | if __name__ == '__main__': | |
834 | main() | |
835 | ||
836 | #---------------------------------------------------------------------------- | |
837 | ||
838 | ||
839 | ||
840 | ||
841 | ||
842 | ||
843 |