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
23 ##print os.getpid(); raw_input("Press a key...")
26 #---------------------------------------------------------------------------
31 ('Recent Additions', [
36 'XmlResourceSubclass',
42 # managed windows == things with a (optional) caption you can close
43 ('Base Frames and Dialogs', [
67 # dialogs from libraries
71 'MultipleChoiceDialog',
72 'ScrolledMessageDialog',
76 ('Core Windows/Controls', [
111 ('Custom Controls', [
124 # controls coming from other libraries
125 ('More Windows/Controls', [
126 #'RightTextCtrl', deprecated as we have wxTE_RIGHT now.
140 'MaskedEditControls',
156 # How to lay out the controls in a frame/dialog
166 'XmlResourceHandler',
167 'XmlResourceSubclass',
171 ('Process and Events', [
183 ('Clipboard and DnD', [
217 # need libs not coming with the demo
218 ('Objects using an external library', [
219 'ActiveXWrapper_Acrobat',
222 #'PlotCanvas', # deprecated, use PyPlot
226 ('Check out the samples dir too', [
233 #---------------------------------------------------------------------------
234 # Show how to derive a custom wxLog class
236 class MyLog(wx
.PyLog
):
237 def __init__(self
, textCtrl
, logTime
=0):
238 wx
.PyLog
.__init
__(self
)
240 self
.logTime
= logTime
242 def DoLogString(self
, message
, timeStamp
):
244 message
= time
.strftime("%X", time
.localtime(timeStamp
)) + \
247 self
.tc
.AppendText(message
+ '\n')
250 class MyTP(wx
.PyTipProvider
):
252 return "This is my tip"
254 #---------------------------------------------------------------------------
255 # A class to be used to display source code in the demo. Try using the
256 # wxSTC in the StyledTextCtrl_2 sample first, fall back to wxTextCtrl
257 # if there is an error, such as the stc module not being present.
263 from StyledTextCtrl_2
import PythonSTC
264 class DemoCodeViewer(PythonSTC
):
265 def __init__(self
, parent
, ID
):
266 PythonSTC
.__init
__(self
, parent
, ID
)
269 # Some methods to make it compatible with how the wxTextCtrl is used
270 def SetValue(self
, value
):
271 self
.SetReadOnly(False)
273 self
.SetReadOnly(True)
278 def SetInsertionPoint(self
, pos
):
279 self
.SetCurrentPos(pos
)
281 def ShowPosition(self
, pos
):
284 def GetLastPosition(self
):
285 return self
.GetLength()
287 def GetRange(self
, start
, end
):
288 return self
.GetTextRange(start
, end
)
290 def GetSelection(self
):
291 return self
.GetAnchor(), self
.GetCurrentPos()
293 def SetSelection(self
, start
, end
):
294 self
.SetSelectionStart(start
)
295 self
.SetSelectionEnd(end
)
297 def SetUpEditor(self
):
299 This method carries out the work of setting up the demo editor.
300 It's seperate so as not to clutter up the init code.
304 self
.SetLexer(stc
.STC_LEX_PYTHON
)
305 self
.SetKeyWords(0, " ".join(keyword
.kwlist
))
308 self
.SetProperty("fold", "1" )
310 # Highlight tab/space mixing (shouldn't be any)
311 self
.SetProperty("tab.timmy.whinge.level", "1")
313 # Set left and right margins
316 # Set up the numbers in the margin for margin #1
317 self
.SetMarginType(1, wx
.stc
.STC_MARGIN_NUMBER
)
318 # Reasonable value for, say, 4-5 digits using a mono font (40 pix)
319 self
.SetMarginWidth(1, 40)
321 # Indentation and tab stuff
322 self
.SetIndent(4) # Proscribed indent size for wx
323 self
.SetIndentationGuides(True) # Show indent guides
324 self
.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space
325 self
.SetTabIndents(True) # Tab key indents
326 self
.SetTabWidth(4) # Proscribed tab size for wx
327 self
.SetUseTabs(False) # Use spaces rather than tabs, or
328 # TabTimmy will complain!
330 self
.SetViewWhiteSpace(False) # Don't view white space
333 #self.SetEOLMode(wx.stc.STC_EOL_CRLF) # Just leave it at the default (autosense)
334 self
.SetViewEOL(False)
335 # No right-edge mode indicator
336 self
.SetEdgeMode(stc
.STC_EDGE_NONE
)
338 # Setup a margin to hold fold markers
339 self
.SetMarginType(2, stc
.STC_MARGIN_SYMBOL
)
340 self
.SetMarginMask(2, stc
.STC_MASK_FOLDERS
)
341 self
.SetMarginSensitive(2, True)
342 self
.SetMarginWidth(2, 12)
344 # and now set up the fold markers
345 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEREND
, stc
.STC_MARK_BOXPLUSCONNECTED
, "white", "black")
346 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEROPENMID
, stc
.STC_MARK_BOXMINUSCONNECTED
, "white", "black")
347 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERMIDTAIL
, stc
.STC_MARK_TCORNER
, "white", "black")
348 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERTAIL
, stc
.STC_MARK_LCORNER
, "white", "black")
349 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDERSUB
, stc
.STC_MARK_VLINE
, "white", "black")
350 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDER
, stc
.STC_MARK_BOXPLUS
, "white", "black")
351 self
.MarkerDefine(stc
.STC_MARKNUM_FOLDEROPEN
, stc
.STC_MARK_BOXMINUS
, "white", "black")
353 # Global default style
354 if wx
.Platform
== '__WXMSW__':
355 self
.StyleSetSpec(stc
.STC_STYLE_DEFAULT
,
356 'fore:#000000,back:#FFFFFF,face:Courier New,size:9')
358 self
.StyleSetSpec(stc
.STC_STYLE_DEFAULT
,
359 'fore:#000000,back:#FFFFFF,face:Courier,size:12')
361 # Clear styles and revert to default.
364 # Following style specs only indicate differences from default.
365 # The rest remains unchanged.
367 # Line numbers in margin
368 self
.StyleSetSpec(wx
.stc
.STC_STYLE_LINENUMBER
,'fore:#000000,back:#99A9C2')
371 self
.StyleSetSpec(wx
.stc
.STC_STYLE_BRACELIGHT
,'fore:#00009D,back:#FFFF00')
373 self
.StyleSetSpec(wx
.stc
.STC_STYLE_BRACEBAD
,'fore:#00009D,back:#FF0000')
375 self
.StyleSetSpec(wx
.stc
.STC_STYLE_INDENTGUIDE
, "fore:#CDCDCD")
378 self
.StyleSetSpec(wx
.stc
.STC_P_DEFAULT
, 'fore:#000000')
380 self
.StyleSetSpec(wx
.stc
.STC_P_COMMENTLINE
, 'fore:#008000,back:#F0FFF0')
381 self
.StyleSetSpec(wx
.stc
.STC_P_COMMENTBLOCK
, 'fore:#008000,back:#F0FFF0')
383 self
.StyleSetSpec(wx
.stc
.STC_P_NUMBER
, 'fore:#008080')
384 # Strings and characters
385 self
.StyleSetSpec(wx
.stc
.STC_P_STRING
, 'fore:#800080')
386 self
.StyleSetSpec(wx
.stc
.STC_P_CHARACTER
, 'fore:#800080')
388 self
.StyleSetSpec(wx
.stc
.STC_P_WORD
, 'fore:#000080,bold')
390 self
.StyleSetSpec(wx
.stc
.STC_P_TRIPLE
, 'fore:#800080,back:#FFFFEA')
391 self
.StyleSetSpec(wx
.stc
.STC_P_TRIPLEDOUBLE
, 'fore:#800080,back:#FFFFEA')
393 self
.StyleSetSpec(wx
.stc
.STC_P_CLASSNAME
, 'fore:#0000FF,bold')
395 self
.StyleSetSpec(wx
.stc
.STC_P_DEFNAME
, 'fore:#008080,bold')
397 self
.StyleSetSpec(wx
.stc
.STC_P_OPERATOR
, 'fore:#800000,bold')
398 # Identifiers. I leave this as not bold because everything seems
399 # to be an identifier if it doesn't match the above criterae
400 self
.StyleSetSpec(wx
.stc
.STC_P_IDENTIFIER
, 'fore:#000000')
403 self
.SetCaretForeground("BLUE")
404 # Selection background
405 self
.SetSelBackground(1, '#66CCFF')
407 self
.SetSelBackground(True, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_HIGHLIGHT
))
408 self
.SetSelForeground(True, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_HIGHLIGHTTEXT
))
412 class DemoCodeViewer(wx
.TextCtrl
):
413 def __init__(self
, parent
, ID
):
414 wx
.TextCtrl
.__init
__(self
, parent
, ID
, style
=
415 wx
.TE_MULTILINE | wx
.TE_READONLY |
416 wx
.HSCROLL | wx
.TE_RICH2 | wx
.TE_NOHIDESEL
)
419 #---------------------------------------------------------------------------
422 """Convert paths to the platform-specific separator"""
423 return apply(os
.path
.join
, tuple(path
.split('/')))
426 #---------------------------------------------------------------------------
428 class wxPythonDemo(wx
.Frame
):
429 overviewText
= "wxPython Overview"
431 def __init__(self
, parent
, id, title
):
432 wx
.Frame
.__init
__(self
, parent
, -1, title
, size
= (800, 600),
433 style
=wx
.DEFAULT_FRAME_STYLE|wx
.NO_FULL_REPAINT_ON_RESIZE
)
435 self
.cwd
= os
.getcwd()
436 self
.curOverview
= ""
439 icon
= images
.getMondrianIcon()
442 if wx
.Platform
!= '__WXMAC__':
443 # setup a taskbar icon, and catch some events from it
444 icon
= wx
.IconFromBitmap(
445 images
.getMondrianImage().Scale(16,16).ConvertToBitmap() )
446 self
.tbicon
= wx
.TaskBarIcon()
447 self
.tbicon
.SetIcon(icon
, "wxPython Demo")
448 self
.tbicon
.Bind(wx
.EVT_TASKBAR_LEFT_DCLICK
, self
.OnTaskBarActivate
)
449 self
.tbicon
.Bind(wx
.EVT_TASKBAR_RIGHT_UP
, self
.OnTaskBarMenu
)
450 self
.tbicon
.Bind(wx
.EVT_MENU
, self
.OnTaskBarActivate
, id=self
.TBMENU_RESTORE
)
451 self
.tbicon
.Bind(wx
.EVT_MENU
, self
.OnTaskBarClose
, id=self
.TBMENU_CLOSE
)
453 wx
.CallAfter(self
.ShowTip
)
456 self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
)
457 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
458 self
.Bind(wx
.EVT_ICONIZE
, self
.OnIconfiy
)
459 self
.Bind(wx
.EVT_MAXIMIZE
, self
.OnMaximize
)
462 self
.CreateStatusBar(1, wx
.ST_SIZEGRIP
)
464 splitter
= wx
.SplitterWindow(self
, -1)
465 splitter2
= wx
.SplitterWindow(splitter
, -1)
467 def EmptyHandler(evt
): pass
468 #splitter.Bind(wx.EVT_ERASE_BACKGROUND, EmptyHandler)
469 #splitter2.Bind(wx.EVT_ERASE_BACKGROUND, EmptyHandler)
471 # Prevent TreeCtrl from displaying all items after destruction when True
475 self
.mainmenu
= wx
.MenuBar()
478 menu
.Append(exitID
, 'E&xit\tAlt-X', 'Get the heck outta here!')
479 self
.Bind(wx
.EVT_MENU
, self
.OnFileExit
, id=exitID
)
480 wx
.App_SetMacExitMenuItemId(exitID
)
481 self
.mainmenu
.Append(menu
, '&File')
485 for item
in _treeList
:
487 for childItem
in item
[1]:
489 submenu
.Append(mID
, childItem
)
490 self
.Bind(wx
.EVT_MENU
, self
.OnDemoMenu
, id=mID
)
491 menu
.AppendMenu(wx
.NewId(), item
[0], submenu
)
492 self
.mainmenu
.Append(menu
, '&Demo')
498 findnextID
= wx
.NewId()
500 menu
.Append(findID
, '&Find\tCtrl-F', 'Find in the Demo Code')
501 menu
.Append(findnextID
, 'Find &Next\tF3', 'Find Next')
502 menu
.AppendSeparator()
503 menu
.Append(helpID
, '&About\tCtrl-H', 'wxPython RULES!!!')
504 wx
.App_SetMacAboutMenuItemId(helpID
)
505 self
.Bind(wx
.EVT_MENU
, self
.OnHelpAbout
, id=helpID
)
506 self
.Bind(wx
.EVT_MENU
, self
.OnHelpFind
, id=findID
)
507 self
.Bind(wx
.EVT_MENU
, self
.OnFindNext
, id=findnextID
)
508 self
.Bind(wx
.EVT_COMMAND_FIND
, self
.OnFind
)
509 self
.Bind(wx
.EVT_COMMAND_FIND_NEXT
, self
.OnFind
)
510 self
.Bind(wx
.EVT_COMMAND_FIND_CLOSE
, self
.OnFindClose
)
511 self
.mainmenu
.Append(menu
, '&Help')
512 self
.SetMenuBar(self
.mainmenu
)
514 self
.finddata
= wx
.FindReplaceData()
517 # This is another way to set Accelerators, in addition to
518 # using the '\t<key>' syntax in the menu items.
519 aTable
= wx
.AcceleratorTable([(wx
.ACCEL_ALT
, ord('X'), exitID
),
520 (wx
.ACCEL_CTRL
, ord('H'), helpID
),
521 (wx
.ACCEL_CTRL
, ord('F'), findID
),
522 (wx
.ACCEL_NORMAL
, WXK_F3
, findnextID
)
524 self
.SetAcceleratorTable(aTable
)
530 self
.tree
= wx
.TreeCtrl(splitter
, tID
, style
=
531 wx
.TR_DEFAULT_STYLE
#| wx.TR_HAS_VARIABLE_ROW_HEIGHT
534 root
= self
.tree
.AddRoot("wxPython Overview")
536 for item
in _treeList
:
537 child
= self
.tree
.AppendItem(root
, item
[0])
538 if not firstChild
: firstChild
= child
539 for childItem
in item
[1]:
540 theDemo
= self
.tree
.AppendItem(child
, childItem
)
541 self
.treeMap
[childItem
] = theDemo
543 self
.tree
.Expand(root
)
544 self
.tree
.Expand(firstChild
)
545 self
.tree
.Bind(wx
.EVT_TREE_ITEM_EXPANDED
, self
.OnItemExpanded
, id=tID
)
546 self
.tree
.Bind(wx
.EVT_TREE_ITEM_COLLAPSED
, self
.OnItemCollapsed
, id=tID
)
547 self
.tree
.Bind(wx
.EVT_TREE_SEL_CHANGED
, self
.OnSelChanged
, id=tID
)
548 self
.tree
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnTreeLeftDown
)
551 self
.nb
= wx
.Notebook(splitter2
, -1, style
=wx
.CLIP_CHILDREN
)
553 # Set up a wx.html.HtmlWindow on the Overview Notebook page
554 # we put it in a panel first because there seems to be a
555 # refresh bug of some sort (wxGTK) when it is directly in
558 self
.ovr
= wx
.html
.HtmlWindow(self
.nb
, -1, size
=(400, 400))
559 self
.nb
.AddPage(self
.ovr
, self
.overviewText
)
561 else: # hopefully I can remove this hacky code soon, see SF bug #216861
562 panel
= wx
.Panel(self
.nb
, -1, style
=wx
.CLIP_CHILDREN
)
563 self
.ovr
= wx
.html
.HtmlWindow(panel
, -1, size
=(400, 400))
564 self
.nb
.AddPage(panel
, self
.overviewText
)
566 def OnOvrSize(evt
, ovr
=self
.ovr
):
567 ovr
.SetSize(evt
.GetSize())
569 panel
.Bind(wx
.EVT_SIZE
, OnOvrSize
)
570 panel
.Bind(wx
.EVT_ERASE_BACKGROUND
, EmptyHandler
)
573 self
.SetOverview(self
.overviewText
, overview
)
576 # Set up a notebook page for viewing the source code of each sample
577 self
.txt
= DemoCodeViewer(self
.nb
, -1)
578 self
.nb
.AddPage(self
.txt
, "Demo Code")
579 self
.LoadDemoSource('Main.py')
582 # Set up a log on the View Log Notebook page
583 self
.log
= wx
.TextCtrl(splitter2
, -1,
584 style
= wx
.TE_MULTILINE|wx
.TE_READONLY|wx
.HSCROLL
)
586 # Set the wxWindows log target to be this textctrl
587 #wx.Log_SetActiveTarget(wx.LogTextCtrl(self.log))
589 # But instead of the above we want to show how to use our own wx.Log class
590 wx
.Log_SetActiveTarget(MyLog(self
.log
))
592 # for serious debugging
593 #wx.Log_SetActiveTarget(wx.LogStderr())
594 #wx.Log_SetTraceMask(wx.TraceMessages)
597 # add the windows to the splitter and split it.
598 splitter2
.SplitHorizontally(self
.nb
, self
.log
, -120)
599 splitter
.SplitVertically(self
.tree
, splitter2
, 180)
601 splitter
.SetMinimumPaneSize(20)
602 splitter2
.SetMinimumPaneSize(20)
605 # Make the splitter on the right expand the top wind when resized
606 def SplitterOnSize(evt
):
607 splitter
= evt
.GetEventObject()
608 sz
= splitter
.GetSize()
609 splitter
.SetSashPosition(sz
.height
- 120, False)
612 splitter2
.Bind(wx
.EVT_SIZE
, SplitterOnSize
)
615 # select initial items
616 self
.nb
.SetSelection(0)
617 self
.tree
.SelectItem(root
)
619 if len(sys
.argv
) == 2:
621 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
625 self
.tree
.SelectItem(selectedDemo
)
626 self
.tree
.EnsureVisible(selectedDemo
)
629 wx
.LogMessage('window handle: %s' % self
.GetHandle())
632 #---------------------------------------------
633 def WriteText(self
, text
):
634 if text
[-1:] == '\n':
639 def write(self
, txt
):
642 #---------------------------------------------
643 def OnItemExpanded(self
, event
):
644 item
= event
.GetItem()
645 wx
.LogMessage("OnItemExpanded: %s" % self
.tree
.GetItemText(item
))
648 #---------------------------------------------
649 def OnItemCollapsed(self
, event
):
650 item
= event
.GetItem()
651 wx
.LogMessage("OnItemCollapsed: %s" % self
.tree
.GetItemText(item
))
654 #---------------------------------------------
655 def OnTreeLeftDown(self
, event
):
656 pt
= event
.GetPosition();
657 item
, flags
= self
.tree
.HitTest(pt
)
658 if item
== self
.tree
.GetSelection():
659 self
.SetOverview(self
.tree
.GetItemText(item
)+" Overview", self
.curOverview
)
662 #---------------------------------------------
663 def OnSelChanged(self
, event
):
667 item
= event
.GetItem()
668 itemText
= self
.tree
.GetItemText(item
)
669 self
.RunDemo(itemText
)
672 #---------------------------------------------
673 def RunDemo(self
, itemText
):
675 if self
.nb
.GetPageCount() == 3:
676 if self
.nb
.GetSelection() == 2:
677 self
.nb
.SetSelection(0)
678 # inform the window that it's time to quit if it cares
679 if self
.window
is not None:
680 if hasattr(self
.window
, "ShutdownDemo"):
681 self
.window
.ShutdownDemo()
682 wx
.SafeYield() # in case the page has pending events
683 self
.nb
.DeletePage(2)
685 if itemText
== self
.overviewText
:
686 self
.LoadDemoSource('Main.py')
687 self
.SetOverview(self
.overviewText
, overview
)
692 if os
.path
.exists(itemText
+ '.py'):
694 wx
.LogMessage("Running demo %s.py..." % itemText
)
696 self
.LoadDemoSource(itemText
+ '.py')
698 if (sys
.modules
.has_key(itemText
)):
699 reload(sys
.modules
[itemText
])
701 module
= __import__(itemText
, globals())
702 self
.SetOverview(itemText
+ " Overview", module
.overview
)
707 # in case runTest is modal, make sure things look right...
711 self
.window
= module
.runTest(self
, self
.nb
, self
) ###
712 if self
.window
is not None:
713 self
.nb
.AddPage(self
.window
, 'Demo')
714 self
.nb
.SetSelection(2)
715 self
.nb
.Refresh() # without this wxMac has troubles showing the just added page
724 #---------------------------------------------
726 def LoadDemoSource(self
, filename
):
729 self
.txt
.SetValue(open(filename
).read())
731 self
.txt
.SetValue("Cannot open %s file." % filename
)
733 self
.txt
.SetInsertionPoint(0)
734 self
.txt
.ShowPosition(0)
736 #---------------------------------------------
737 def SetOverview(self
, name
, text
):
738 self
.curOverview
= text
740 if lead
!= '<html>' and lead
!= '<HTML>':
741 text
= '<br>'.join(text
.split('\n'))
742 self
.ovr
.SetPage(text
)
743 self
.nb
.SetPageText(0, name
)
745 #---------------------------------------------
747 def OnFileExit(self
, *event
):
750 def OnHelpAbout(self
, event
):
751 from About
import MyAboutBox
752 about
= MyAboutBox(self
)
756 def OnHelpFind(self
, event
):
757 self
.nb
.SetSelection(1)
758 self
.finddlg
= wx
.FindReplaceDialog(self
, self
.finddata
, "Find",
762 self
.finddlg
.Show(True)
764 def OnFind(self
, event
):
765 self
.nb
.SetSelection(1)
766 end
= self
.txt
.GetLastPosition()
767 textstring
= self
.txt
.GetRange(0, end
).lower()
768 start
= self
.txt
.GetSelection()[1]
769 findstring
= self
.finddata
.GetFindString().lower()
770 loc
= textstring
.find(findstring
, start
)
771 if loc
== -1 and start
!= 0:
772 # string not found, start at beginning
774 loc
= textstring
.find(findstring
, start
)
776 dlg
= wx
.MessageDialog(self
, 'Find String Not Found',
777 'Find String Not Found in Demo File',
778 wx
.OK | wx
.ICON_INFORMATION
)
783 self
.finddlg
.SetFocus()
786 self
.finddlg
.Destroy()
787 self
.txt
.ShowPosition(loc
)
788 self
.txt
.SetSelection(loc
, loc
+ len(findstring
))
792 def OnFindNext(self
, event
):
793 if self
.finddata
.GetFindString():
796 self
.OnHelpFind(event
)
798 def OnFindClose(self
, event
):
799 event
.GetDialog().Destroy()
802 #---------------------------------------------
803 def OnCloseWindow(self
, event
):
807 if hasattr(self
, "tbicon"):
812 #---------------------------------------------
813 def OnIdle(self
, event
):
815 self
.otherWin
.Raise()
816 self
.window
= self
.otherWin
820 #---------------------------------------------
823 showTipText
= open(opj("data/showTips")).read()
824 showTip
, index
= eval(showTipText
)
826 showTip
, index
= (1, 0)
828 tp
= wx
.CreateFileTipProvider(opj("data/tips.txt"), index
)
830 showTip
= wx
.ShowTip(self
, tp
)
831 index
= tp
.GetCurrentTip()
832 open(opj("data/showTips"), "w").write(str( (showTip
, index
) ))
835 #---------------------------------------------
836 def OnDemoMenu(self
, event
):
838 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
842 self
.tree
.SelectItem(selectedDemo
)
843 self
.tree
.EnsureVisible(selectedDemo
)
846 #---------------------------------------------
847 def OnTaskBarActivate(self
, evt
):
848 if self
.IsIconized():
850 if not self
.IsShown():
854 #---------------------------------------------
856 TBMENU_RESTORE
= 1000
859 def OnTaskBarMenu(self
, evt
):
861 menu
.Append(self
.TBMENU_RESTORE
, "Restore wxPython Demo")
862 menu
.Append(self
.TBMENU_CLOSE
, "Close")
863 self
.tbicon
.PopupMenu(menu
)
866 #---------------------------------------------
867 def OnTaskBarClose(self
, evt
):
870 # because of the way wx.TaskBarIcon.PopupMenu is implemented we have to
871 # prod the main idle handler a bit to get the window to actually close
872 wx
.GetApp().ProcessIdle()
875 #---------------------------------------------
876 def OnIconfiy(self
, evt
):
877 wx
.LogMessage("OnIconfiy")
880 #---------------------------------------------
881 def OnMaximize(self
, evt
):
882 wx
.LogMessage("OnMaximize")
888 #---------------------------------------------------------------------------
889 #---------------------------------------------------------------------------
891 class MySplashScreen(wx
.SplashScreen
):
893 bmp
= wx
.Image(opj("bitmaps/splash.gif")).ConvertToBitmap()
894 wx
.SplashScreen
.__init
__(self
, bmp
,
895 wx
.SPLASH_CENTRE_ON_SCREEN | wx
.SPLASH_TIMEOUT
,
897 self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
)
899 def OnClose(self
, evt
):
900 frame
= wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
902 evt
.Skip() # Make sure the default handler runs too...
908 Create and show the splash screen. It will then create and show
909 the main frame when it is time to do so.
912 wx
.InitAllImageHandlers()
914 # Normally when using a SplashScreen you would create it, show
915 # it and then continue on with the applicaiton's
916 # initialization, finally creating and showing the main
917 # application window(s). In this case we have nothing else to
918 # do so we'll delay showing the main frame until later (see
919 # OnClose above) so the users can see the SplashScrren effect.
920 splash
= MySplashScreen()
927 #---------------------------------------------------------------------------
931 demoPath
= os
.path
.dirname(__file__
)
935 app
= MyApp(0) #wx.Platform == "__WXMAC__")
939 #---------------------------------------------------------------------------
943 overview
= """<html><body>
946 <p> wxPython is a <b>GUI toolkit</b> for the <a
947 href="http://www.python.org/">Python</a> programming language. It
948 allows Python programmers to create programs with a robust, highly
949 functional graphical user interface, simply and easily. It is
950 implemented as a Python extension module (native code) that wraps the
951 popular <a href="http://wxwindows.org/front.htm">wxWindows</a> cross
952 platform GUI library, which is written in C++.
954 <p> Like Python and wxWindows, wxPython is <b>Open Source</b> which
955 means that it is free for anyone to use and the source code is
956 available for anyone to look at and modify. Or anyone can contribute
957 fixes or enhancements to the project.
959 <p> wxPython is a <b>cross-platform</b> toolkit. This means that the
960 same program will run on multiple platforms without modification.
961 Currently supported platforms are 32-bit Microsoft Windows, most Unix
962 or unix-like systems, and Macintosh OS X. Since the language is
963 Python, wxPython programs are <b>simple, easy</b> to write and easy to
966 <p> <b>This demo</b> is not only a collection of test cases for
967 wxPython, but is also designed to help you learn about and how to use
968 wxPython. Each sample is listed in the tree control on the left.
969 When a sample is selected in the tree then a module is loaded and run
970 (usually in a tab of this notebook,) and the source code of the module
971 is loaded in another tab for you to browse and learn from.
976 #----------------------------------------------------------------------------
977 #----------------------------------------------------------------------------
979 if __name__
== '__main__':
982 #----------------------------------------------------------------------------