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