2 #----------------------------------------------------------------------------
4 # Purpose: Testing lots of stuff, controls, window types, etc.
8 # Created: A long time ago, in a galaxy far, far away...
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
16 import wx
# This module uses the new wx namespace
24 ##raw_input("Press a key...")
27 #---------------------------------------------------------------------------
32 ('Recent Additions', [
37 'XmlResourceSubclass',
42 'ActiveX_FlashWindow',
43 'ActiveX_IEHtmlWindow',
47 # managed windows == things with a (optional) caption you can close
48 ('Base Frames and Dialogs', [
72 # dialogs from libraries
75 'MultipleChoiceDialog',
76 'ScrolledMessageDialog',
80 ('Core Windows/Controls', [
116 ('Custom Controls', [
129 # controls coming from other libraries
130 ('More Windows/Controls', [
131 'ActiveX_FlashWindow',
132 'ActiveX_IEHtmlWindow',
134 #'RightTextCtrl', deprecated as we have wxTE_RIGHT now.
147 'MaskedEditControls',
163 # How to lay out the controls in a frame/dialog
173 'XmlResourceHandler',
174 'XmlResourceSubclass',
178 ('Process and Events', [
189 ('Clipboard and DnD', [
222 # need libs not coming with the demo
223 ('Objects using an external library', [
228 ('Check out the samples dir too', [
235 #---------------------------------------------------------------------------
236 # Show how to derive a custom wxLog class
238 class MyLog(wx
.PyLog
):
239 def __init__(self
, textCtrl
, logTime
=0):
240 wx
.PyLog
.__init
__(self
)
242 self
.logTime
= logTime
244 def DoLogString(self
, message
, timeStamp
):
246 message
= time
.strftime("%X", time
.localtime(timeStamp
)) + \
249 self
.tc
.AppendText(message
+ '\n')
252 class MyTP(wx
.PyTipProvider
):
254 return "This is my tip"
256 #---------------------------------------------------------------------------
257 # A class to be used to display source code in the demo. Try using the
258 # wxSTC in the StyledTextCtrl_2 sample first, fall back to wxTextCtrl
259 # if there is an error, such as the stc module not being present.
265 from StyledTextCtrl_2
import PythonSTC
266 class DemoCodeViewer(PythonSTC
):
267 def __init__(self
, parent
, ID
):
268 PythonSTC
.__init
__(self
, parent
, ID
, wx
.BORDER_NONE
)
271 # Some methods to make it compatible with how the wxTextCtrl is used
272 def SetValue(self
, value
):
273 self
.SetReadOnly(False)
275 self
.SetReadOnly(True)
280 def SetInsertionPoint(self
, pos
):
281 self
.SetCurrentPos(pos
)
283 def ShowPosition(self
, pos
):
286 def GetLastPosition(self
):
287 return self
.GetLength()
289 def GetRange(self
, start
, end
):
290 return self
.GetTextRange(start
, end
)
292 def GetSelection(self
):
293 return self
.GetAnchor(), self
.GetCurrentPos()
295 def SetSelection(self
, start
, end
):
296 self
.SetSelectionStart(start
)
297 self
.SetSelectionEnd(end
)
299 def SetUpEditor(self
):
301 This method carries out the work of setting up the demo editor.
302 It's seperate so as not to clutter up the init code.
306 self
.SetLexer(stc
.STC_LEX_PYTHON
)
307 self
.SetKeyWords(0, " ".join(keyword
.kwlist
))
310 self
.SetProperty("fold", "1" )
312 # Highlight tab/space mixing (shouldn't be any)
313 self
.SetProperty("tab.timmy.whinge.level", "1")
315 # Set left and right margins
318 # Set up the numbers in the margin for margin #1
319 self
.SetMarginType(1, wx
.stc
.STC_MARGIN_NUMBER
)
320 # Reasonable value for, say, 4-5 digits using a mono font (40 pix)
321 self
.SetMarginWidth(1, 40)
323 # Indentation and tab stuff
324 self
.SetIndent(4) # Proscribed indent size for wx
325 self
.SetIndentationGuides(True) # Show indent guides
326 self
.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space
327 self
.SetTabIndents(True) # Tab key indents
328 self
.SetTabWidth(4) # Proscribed tab size for wx
329 self
.SetUseTabs(False) # Use spaces rather than tabs, or
330 # TabTimmy will complain!
332 self
.SetViewWhiteSpace(False) # Don't view white space
335 #self.SetEOLMode(wx.stc.STC_EOL_CRLF) # Just leave it at the default (autosense)
336 self
.SetViewEOL(False)
337 # No right-edge mode indicator
338 self
.SetEdgeMode(stc
.STC_EDGE_NONE
)
340 # Setup a margin to hold fold markers
341 self
.SetMarginType(2, stc
.STC_MARGIN_SYMBOL
)
342 self
.SetMarginMask(2, stc
.STC_MASK_FOLDERS
)
343 self
.SetMarginSensitive(2, True)
344 self
.SetMarginWidth(2, 12)
346 # and now set up the fold markers
347 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEREND
, stc
.STC_MARK_BOXPLUSCONNECTED
, "white", "black")
348 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEROPENMID
, stc
.STC_MARK_BOXMINUSCONNECTED
, "white", "black")
349 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERMIDTAIL
, stc
.STC_MARK_TCORNER
, "white", "black")
350 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERTAIL
, stc
.STC_MARK_LCORNER
, "white", "black")
351 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERSUB
, stc
.STC_MARK_VLINE
, "white", "black")
352 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDER
, stc
.STC_MARK_BOXPLUS
, "white", "black")
353 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEROPEN
, stc
.STC_MARK_BOXMINUS
, "white", "black")
355 # Global default style
356 if wx
.Platform
== '__WXMSW__':
357 self
.StyleSetSpec(stc
.STC_STYLE_DEFAULT
,
358 'fore:#000000,back:#FFFFFF,face:Courier New,size:9')
360 self
.StyleSetSpec(stc
.STC_STYLE_DEFAULT
,
361 'fore:#000000,back:#FFFFFF,face:Courier,size:12')
363 # Clear styles and revert to default.
366 # Following style specs only indicate differences from default.
367 # The rest remains unchanged.
369 # Line numbers in margin
370 self
.StyleSetSpec(wx
.stc
.STC_STYLE_LINENUMBER
,'fore:#000000,back:#99A9C2')
373 self
.StyleSetSpec(wx
.stc
.STC_STYLE_BRACELIGHT
,'fore:#00009D,back:#FFFF00')
375 self
.StyleSetSpec(wx
.stc
.STC_STYLE_BRACEBAD
,'fore:#00009D,back:#FF0000')
377 self
.StyleSetSpec(wx
.stc
.STC_STYLE_INDENTGUIDE
, "fore:#CDCDCD")
380 self
.StyleSetSpec(wx
.stc
.STC_P_DEFAULT
, 'fore:#000000')
382 self
.StyleSetSpec(wx
.stc
.STC_P_COMMENTLINE
, 'fore:#008000,back:#F0FFF0')
383 self
.StyleSetSpec(wx
.stc
.STC_P_COMMENTBLOCK
, 'fore:#008000,back:#F0FFF0')
385 self
.StyleSetSpec(wx
.stc
.STC_P_NUMBER
, 'fore:#008080')
386 # Strings and characters
387 self
.StyleSetSpec(wx
.stc
.STC_P_STRING
, 'fore:#800080')
388 self
.StyleSetSpec(wx
.stc
.STC_P_CHARACTER
, 'fore:#800080')
390 self
.StyleSetSpec(wx
.stc
.STC_P_WORD
, 'fore:#000080,bold')
392 self
.StyleSetSpec(wx
.stc
.STC_P_TRIPLE
, 'fore:#800080,back:#FFFFEA')
393 self
.StyleSetSpec(wx
.stc
.STC_P_TRIPLEDOUBLE
, 'fore:#800080,back:#FFFFEA')
395 self
.StyleSetSpec(wx
.stc
.STC_P_CLASSNAME
, 'fore:#0000FF,bold')
397 self
.StyleSetSpec(wx
.stc
.STC_P_DEFNAME
, 'fore:#008080,bold')
399 self
.StyleSetSpec(wx
.stc
.STC_P_OPERATOR
, 'fore:#800000,bold')
400 # Identifiers. I leave this as not bold because everything seems
401 # to be an identifier if it doesn't match the above criterae
402 self
.StyleSetSpec(wx
.stc
.STC_P_IDENTIFIER
, 'fore:#000000')
405 self
.SetCaretForeground("BLUE")
406 # Selection background
407 self
.SetSelBackground(1, '#66CCFF')
409 self
.SetSelBackground(True, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_HIGHLIGHT
))
410 self
.SetSelForeground(True, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_HIGHLIGHTTEXT
))
414 class DemoCodeViewer(wx
.TextCtrl
):
415 def __init__(self
, parent
, ID
):
416 wx
.TextCtrl
.__init
__(self
, parent
, ID
, style
=
417 wx
.TE_MULTILINE | wx
.TE_READONLY |
418 wx
.HSCROLL | wx
.TE_RICH2 | wx
.TE_NOHIDESEL
)
421 #---------------------------------------------------------------------------
424 """Convert paths to the platform-specific separator"""
425 return apply(os
.path
.join
, tuple(path
.split('/')))
428 #---------------------------------------------------------------------------
430 class wxPythonDemo(wx
.Frame
):
431 overviewText
= "wxPython Overview"
433 def __init__(self
, parent
, id, title
):
434 wx
.Frame
.__init
__(self
, parent
, -1, title
, size
= (800, 600),
435 style
=wx
.DEFAULT_FRAME_STYLE|wx
.NO_FULL_REPAINT_ON_RESIZE
)
438 self
.cwd
= os
.getcwd()
439 self
.curOverview
= ""
442 icon
= images
.getMondrianIcon()
445 if wx
.Platform
!= '__WXMAC__':
446 # setup a taskbar icon, and catch some events from it
447 icon
= wx
.IconFromBitmap(
448 images
.getMondrianImage().Scale(16,16).ConvertToBitmap() )
449 self
.tbicon
= wx
.TaskBarIcon()
450 self
.tbicon
.SetIcon(icon
, "wxPython Demo")
451 self
.tbicon
.Bind(wx
.EVT_TASKBAR_LEFT_DCLICK
, self
.OnTaskBarActivate
)
452 self
.tbicon
.Bind(wx
.EVT_TASKBAR_RIGHT_UP
, self
.OnTaskBarMenu
)
453 self
.tbicon
.Bind(wx
.EVT_MENU
, self
.OnTaskBarActivate
, id=self
.TBMENU_RESTORE
)
454 self
.tbicon
.Bind(wx
.EVT_MENU
, self
.OnTaskBarClose
, id=self
.TBMENU_CLOSE
)
456 wx
.CallAfter(self
.ShowTip
)
459 self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
)
460 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
461 self
.Bind(wx
.EVT_ICONIZE
, self
.OnIconfiy
)
462 self
.Bind(wx
.EVT_MAXIMIZE
, self
.OnMaximize
)
465 self
.CreateStatusBar(1, wx
.ST_SIZEGRIP
)
467 splitter
= wx
.SplitterWindow(self
, -1)
468 splitter2
= wx
.SplitterWindow(splitter
, -1) ##, size=(20,20))
470 # Set up a log on the View Log Notebook page
471 self
.log
= wx
.TextCtrl(splitter2
, -1,
472 style
= wx
.TE_MULTILINE|wx
.TE_READONLY|wx
.HSCROLL
)
474 # Set the wxWindows log target to be this textctrl
475 #wx.Log_SetActiveTarget(wx.LogTextCtrl(self.log))
477 # But instead of the above we want to show how to use our own wx.Log class
478 wx
.Log_SetActiveTarget(MyLog(self
.log
))
480 # for serious debugging
481 #wx.Log_SetActiveTarget(wx.LogStderr())
482 #wx.Log_SetTraceMask(wx.TraceMessages)
486 def EmptyHandler(evt
): pass
487 #splitter.Bind(wx.EVT_ERASE_BACKGROUND, EmptyHandler)
488 #splitter2.Bind(wx.EVT_ERASE_BACKGROUND, EmptyHandler)
490 # Prevent TreeCtrl from displaying all items after destruction when True
494 self
.mainmenu
= wx
.MenuBar()
496 item
= menu
.Append(-1, '&Redirect Output',
497 'Redirect print statements to a window',
499 self
.Bind(wx
.EVT_MENU
, self
.OnToggleRedirect
, item
)
501 item
= menu
.Append(-1, 'E&xit\tAlt-X', 'Get the heck outta here!')
502 self
.Bind(wx
.EVT_MENU
, self
.OnFileExit
, item
)
503 wx
.App_SetMacExitMenuItemId(item
.GetId())
505 self
.mainmenu
.Append(menu
, '&File')
509 for item
in _treeList
:
511 for childItem
in item
[1]:
512 mi
= submenu
.Append(-1, childItem
)
513 self
.Bind(wx
.EVT_MENU
, self
.OnDemoMenu
, mi
)
514 menu
.AppendMenu(wx
.NewId(), item
[0], submenu
)
515 self
.mainmenu
.Append(menu
, '&Demo')
521 findnextID
= wx
.NewId()
523 findItem
= menu
.Append(-1, '&Find\tCtrl-F', 'Find in the Demo Code')
524 findnextItem
= menu
.Append(-1, 'Find &Next\tF3', 'Find Next')
525 menu
.AppendSeparator()
526 helpItem
= menu
.Append(-1, '&About\tCtrl-H', 'wxPython RULES!!!')
527 wx
.App_SetMacAboutMenuItemId(helpItem
.GetId())
528 self
.Bind(wx
.EVT_MENU
, self
.OnHelpAbout
, helpItem
)
529 self
.Bind(wx
.EVT_MENU
, self
.OnHelpFind
, findItem
)
530 self
.Bind(wx
.EVT_MENU
, self
.OnFindNext
, findnextItem
)
531 self
.Bind(wx
.EVT_COMMAND_FIND
, self
.OnFind
)
532 self
.Bind(wx
.EVT_COMMAND_FIND_NEXT
, self
.OnFind
)
533 self
.Bind(wx
.EVT_COMMAND_FIND_CLOSE
, self
.OnFindClose
)
534 self
.mainmenu
.Append(menu
, '&Help')
535 self
.SetMenuBar(self
.mainmenu
)
537 self
.finddata
= wx
.FindReplaceData()
540 # This is another way to set Accelerators, in addition to
541 # using the '\t<key>' syntax in the menu items.
542 aTable
= wx
.AcceleratorTable([(wx
.ACCEL_ALT
, ord('X'), exitID
),
543 (wx
.ACCEL_CTRL
, ord('H'), helpID
),
544 (wx
.ACCEL_CTRL
, ord('F'), findID
),
545 (wx
.ACCEL_NORMAL
, WXK_F3
, findnextID
)
547 self
.SetAcceleratorTable(aTable
)
553 self
.tree
= wx
.TreeCtrl(splitter
, tID
, style
=
554 wx
.TR_DEFAULT_STYLE
#| wx.TR_HAS_VARIABLE_ROW_HEIGHT
557 root
= self
.tree
.AddRoot("wxPython Overview")
559 for item
in _treeList
:
560 child
= self
.tree
.AppendItem(root
, item
[0])
561 if not firstChild
: firstChild
= child
562 for childItem
in item
[1]:
563 theDemo
= self
.tree
.AppendItem(child
, childItem
)
564 self
.treeMap
[childItem
] = theDemo
566 self
.tree
.Expand(root
)
567 self
.tree
.Expand(firstChild
)
568 self
.tree
.Bind(wx
.EVT_TREE_ITEM_EXPANDED
, self
.OnItemExpanded
, id=tID
)
569 self
.tree
.Bind(wx
.EVT_TREE_ITEM_COLLAPSED
, self
.OnItemCollapsed
, id=tID
)
570 self
.tree
.Bind(wx
.EVT_TREE_SEL_CHANGED
, self
.OnSelChanged
, id=tID
)
571 self
.tree
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnTreeLeftDown
)
574 self
.nb
= wx
.Notebook(splitter2
, -1, style
=wx
.CLIP_CHILDREN
)
576 # Set up a wx.html.HtmlWindow on the Overview Notebook page
577 # we put it in a panel first because there seems to be a
578 # refresh bug of some sort (wxGTK) when it is directly in
581 self
.ovr
= wx
.html
.HtmlWindow(self
.nb
, -1, size
=(400, 400))
582 self
.nb
.AddPage(self
.ovr
, self
.overviewText
)
584 else: # hopefully I can remove this hacky code soon, see SF bug #216861
585 panel
= wx
.Panel(self
.nb
, -1, style
=wx
.CLIP_CHILDREN
)
586 self
.ovr
= wx
.html
.HtmlWindow(panel
, -1, size
=(400, 400))
587 self
.nb
.AddPage(panel
, self
.overviewText
)
589 def OnOvrSize(evt
, ovr
=self
.ovr
):
590 ovr
.SetSize(evt
.GetSize())
592 panel
.Bind(wx
.EVT_SIZE
, OnOvrSize
)
593 panel
.Bind(wx
.EVT_ERASE_BACKGROUND
, EmptyHandler
)
596 self
.SetOverview(self
.overviewText
, overview
)
599 # Set up a notebook page for viewing the source code of each sample
600 self
.txt
= DemoCodeViewer(self
.nb
, -1)
601 self
.nb
.AddPage(self
.txt
, "Demo Code")
602 self
.LoadDemoSource('Main.py')
605 # add the windows to the splitter and split it.
606 splitter2
.SplitHorizontally(self
.nb
, self
.log
, -120)
607 splitter
.SplitVertically(self
.tree
, splitter2
, 180)
609 splitter
.SetMinimumPaneSize(20)
610 splitter2
.SetMinimumPaneSize(20)
613 # Make the splitter on the right expand the top window when resized
614 def SplitterOnSize(evt
):
615 splitter
= evt
.GetEventObject()
616 sz
= splitter
.GetSize()
617 splitter
.SetSashPosition(sz
.height
- 120, False)
620 splitter2
.Bind(wx
.EVT_SIZE
, SplitterOnSize
)
623 # select initial items
624 self
.nb
.SetSelection(0)
625 self
.tree
.SelectItem(root
)
627 if len(sys
.argv
) == 2:
629 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
633 self
.tree
.SelectItem(selectedDemo
)
634 self
.tree
.EnsureVisible(selectedDemo
)
637 wx
.LogMessage('window handle: %s' % self
.GetHandle())
640 #---------------------------------------------
641 def WriteText(self
, text
):
642 if text
[-1:] == '\n':
647 def write(self
, txt
):
650 #---------------------------------------------
651 def OnItemExpanded(self
, event
):
652 item
= event
.GetItem()
653 wx
.LogMessage("OnItemExpanded: %s" % self
.tree
.GetItemText(item
))
656 #---------------------------------------------
657 def OnItemCollapsed(self
, event
):
658 item
= event
.GetItem()
659 wx
.LogMessage("OnItemCollapsed: %s" % self
.tree
.GetItemText(item
))
662 #---------------------------------------------
663 def OnTreeLeftDown(self
, event
):
664 pt
= event
.GetPosition();
665 item
, flags
= self
.tree
.HitTest(pt
)
666 if item
== self
.tree
.GetSelection():
667 self
.SetOverview(self
.tree
.GetItemText(item
)+" Overview", self
.curOverview
)
670 #---------------------------------------------
671 def OnSelChanged(self
, event
):
675 item
= event
.GetItem()
676 itemText
= self
.tree
.GetItemText(item
)
677 self
.RunDemo(itemText
)
680 #---------------------------------------------
681 def RunDemo(self
, itemText
):
683 if self
.nb
.GetPageCount() == 3:
684 if self
.nb
.GetSelection() == 2:
685 self
.nb
.SetSelection(0)
686 # inform the window that it's time to quit if it cares
687 if self
.window
is not None:
688 if hasattr(self
.window
, "ShutdownDemo"):
689 self
.window
.ShutdownDemo()
690 wx
.SafeYield() # in case the page has pending events
691 self
.nb
.DeletePage(2)
693 if itemText
== self
.overviewText
:
694 self
.LoadDemoSource('Main.py')
695 self
.SetOverview(self
.overviewText
, overview
)
699 if os
.path
.exists(itemText
+ '.py'):
701 wx
.LogMessage("Running demo %s.py..." % itemText
)
703 self
.LoadDemoSource(itemText
+ '.py')
705 if (sys
.modules
.has_key(itemText
)):
706 reload(sys
.modules
[itemText
])
708 module
= __import__(itemText
, globals())
709 self
.SetOverview(itemText
+ " Overview", module
.overview
)
714 self
.window
= module
.runTest(self
, self
.nb
, self
) ###
715 if self
.window
is not None:
716 self
.nb
.AddPage(self
.window
, 'Demo')
717 self
.nb
.SetSelection(2)
727 #---------------------------------------------
729 def LoadDemoSource(self
, filename
):
732 self
.txt
.SetValue(open(filename
).read())
734 self
.txt
.SetValue("Cannot open %s file." % filename
)
736 self
.txt
.SetInsertionPoint(0)
737 self
.txt
.ShowPosition(0)
739 #---------------------------------------------
740 def SetOverview(self
, name
, text
):
741 self
.curOverview
= text
743 if lead
!= '<html>' and lead
!= '<HTML>':
744 text
= '<br>'.join(text
.split('\n'))
745 self
.ovr
.SetPage(text
)
746 self
.nb
.SetPageText(0, name
)
748 #---------------------------------------------
750 def OnFileExit(self
, *event
):
753 def OnToggleRedirect(self
, event
):
757 print "Print statements and other standard output will now be directed to this window."
760 print "Print statements and other standard output will now be sent to the usual location."
762 def OnHelpAbout(self
, event
):
763 from About
import MyAboutBox
764 about
= MyAboutBox(self
)
768 def OnHelpFind(self
, event
):
769 self
.nb
.SetSelection(1)
770 self
.finddlg
= wx
.FindReplaceDialog(self
, self
.finddata
, "Find",
774 self
.finddlg
.Show(True)
776 def OnFind(self
, event
):
777 self
.nb
.SetSelection(1)
778 end
= self
.txt
.GetLastPosition()
779 textstring
= self
.txt
.GetRange(0, end
).lower()
780 start
= self
.txt
.GetSelection()[1]
781 findstring
= self
.finddata
.GetFindString().lower()
782 loc
= textstring
.find(findstring
, start
)
783 if loc
== -1 and start
!= 0:
784 # string not found, start at beginning
786 loc
= textstring
.find(findstring
, start
)
788 dlg
= wx
.MessageDialog(self
, 'Find String Not Found',
789 'Find String Not Found in Demo File',
790 wx
.OK | wx
.ICON_INFORMATION
)
795 self
.finddlg
.SetFocus()
798 self
.finddlg
.Destroy()
799 self
.txt
.ShowPosition(loc
)
800 self
.txt
.SetSelection(loc
, loc
+ len(findstring
))
804 def OnFindNext(self
, event
):
805 if self
.finddata
.GetFindString():
808 self
.OnHelpFind(event
)
810 def OnFindClose(self
, event
):
811 event
.GetDialog().Destroy()
814 #---------------------------------------------
815 def OnCloseWindow(self
, event
):
822 #---------------------------------------------
823 def OnIdle(self
, event
):
825 self
.otherWin
.Raise()
826 self
.window
= self
.otherWin
830 #---------------------------------------------
833 showTipText
= open(opj("data/showTips")).read()
834 showTip
, index
= eval(showTipText
)
836 showTip
, index
= (1, 0)
838 tp
= wx
.CreateFileTipProvider(opj("data/tips.txt"), index
)
840 showTip
= wx
.ShowTip(self
, tp
)
841 index
= tp
.GetCurrentTip()
842 open(opj("data/showTips"), "w").write(str( (showTip
, index
) ))
845 #---------------------------------------------
846 def OnDemoMenu(self
, event
):
848 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
852 self
.tree
.SelectItem(selectedDemo
)
853 self
.tree
.EnsureVisible(selectedDemo
)
856 #---------------------------------------------
857 def OnTaskBarActivate(self
, evt
):
858 if self
.IsIconized():
860 if not self
.IsShown():
864 #---------------------------------------------
866 TBMENU_RESTORE
= 1000
869 def OnTaskBarMenu(self
, evt
):
871 menu
.Append(self
.TBMENU_RESTORE
, "Restore wxPython Demo")
872 menu
.Append(self
.TBMENU_CLOSE
, "Close")
873 self
.tbicon
.PopupMenu(menu
)
876 #---------------------------------------------
877 def OnTaskBarClose(self
, evt
):
880 # because of the way wx.TaskBarIcon.PopupMenu is implemented we have to
881 # prod the main idle handler a bit to get the window to actually close
882 wx
.GetApp().ProcessIdle()
885 #---------------------------------------------
886 def OnIconfiy(self
, evt
):
887 wx
.LogMessage("OnIconfiy")
890 #---------------------------------------------
891 def OnMaximize(self
, evt
):
892 wx
.LogMessage("OnMaximize")
898 #---------------------------------------------------------------------------
899 #---------------------------------------------------------------------------
901 class MySplashScreen(wx
.SplashScreen
):
903 bmp
= wx
.Image(opj("bitmaps/splash.gif")).ConvertToBitmap()
904 wx
.SplashScreen
.__init
__(self
, bmp
,
905 wx
.SPLASH_CENTRE_ON_SCREEN | wx
.SPLASH_TIMEOUT
,
907 self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
)
909 def OnClose(self
, evt
):
911 frame
= wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
913 evt
.Skip() # Make sure the default handler runs too...
919 Create and show the splash screen. It will then create and show
920 the main frame when it is time to do so.
923 wx
.InitAllImageHandlers()
925 # Normally when using a SplashScreen you would create it, show
926 # it and then continue on with the applicaiton's
927 # initialization, finally creating and showing the main
928 # application window(s). In this case we have nothing else to
929 # do so we'll delay showing the main frame until later (see
930 # OnClose above) so the users can see the SplashScrren effect.
931 splash
= MySplashScreen()
938 #---------------------------------------------------------------------------
942 demoPath
= os
.path
.dirname(__file__
)
946 app
= MyApp(0) ##wx.Platform == "__WXMAC__")
950 #---------------------------------------------------------------------------
954 overview
= """<html><body>
957 <p> wxPython is a <b>GUI toolkit</b> for the <a
958 href="http://www.python.org/">Python</a> programming language. It
959 allows Python programmers to create programs with a robust, highly
960 functional graphical user interface, simply and easily. It is
961 implemented as a Python extension module (native code) that wraps the
962 popular <a href="http://wxwindows.org/front.htm">wxWindows</a> cross
963 platform GUI library, which is written in C++.
965 <p> Like Python and wxWindows, wxPython is <b>Open Source</b> which
966 means that it is free for anyone to use and the source code is
967 available for anyone to look at and modify. Or anyone can contribute
968 fixes or enhancements to the project.
970 <p> wxPython is a <b>cross-platform</b> toolkit. This means that the
971 same program will run on multiple platforms without modification.
972 Currently supported platforms are 32-bit Microsoft Windows, most Unix
973 or unix-like systems, and Macintosh OS X. Since the language is
974 Python, wxPython programs are <b>simple, easy</b> to write and easy to
977 <p> <b>This demo</b> is not only a collection of test cases for
978 wxPython, but is also designed to help you learn about and how to use
979 wxPython. Each sample is listed in the tree control on the left.
980 When a sample is selected in the tree then a module is loaded and run
981 (usually in a tab of this notebook,) and the source code of the module
982 is loaded in another tab for you to browse and learn from.
987 #----------------------------------------------------------------------------
988 #----------------------------------------------------------------------------
990 if __name__
== '__main__':
993 #----------------------------------------------------------------------------