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