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