]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/run.py
   2 #---------------------------------------------------------------------------- 
   4 # Purpose:      Simple framework for running individual demos 
   8 # Created:      6-March-2000 
  10 # Copyright:    (c) 2000 by Total Control Software 
  11 # Licence:      wxWindows license 
  12 #---------------------------------------------------------------------------- 
  15 This program will load and run one of the individual demos in this 
  16 directory within its own frame window.  Just specify the module name 
  21 import wx
.lib
.mixins
.inspection
 
  25 print "wx.version:", wx
.version() 
  26 print "pid:", os
.getpid() 
  27 ##raw_input("Press Enter...") 
  29 assertMode 
= wx
.PYAPP_ASSERT_DIALOG
 
  30 ##assertMode = wx.PYAPP_ASSERT_EXCEPTION 
  33 #---------------------------------------------------------------------------- 
  36     def WriteText(self
, text
): 
  43 class RunDemoApp(wx
.App
, wx
.lib
.mixins
.inspection
.InspectionMixin
): 
  44     def __init__(self
, name
, module
, useShell
): 
  46         self
.demoModule 
= module
 
  47         self
.useShell 
= useShell
 
  48         wx
.App
.__init
__(self
, redirect
=False) 
  52         wx
.Log_SetActiveTarget(wx
.LogStderr()) 
  54         self
.SetAssertMode(assertMode
) 
  55         self
.Init()  # InspectionMixin 
  57         frame 
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(200,100), 
  58                         style
=wx
.DEFAULT_FRAME_STYLE
, name
="run a sample") 
  59         frame
.CreateStatusBar() 
  61         menuBar 
= wx
.MenuBar() 
  63         item 
= menu
.Append(-1, "E&xit\tCtrl-Q", "Exit demo") 
  64         self
.Bind(wx
.EVT_MENU
, self
.OnExitApp
, item
) 
  65         menuBar
.Append(menu
, "&File") 
  70         ns
['module'] = self
.demoModule
 
  73         frame
.SetMenuBar(menuBar
) 
  75         frame
.Bind(wx
.EVT_CLOSE
, self
.OnCloseFrame
) 
  77         win 
= self
.demoModule
.runTest(frame
, frame
, Log()) 
  79         # a window will be returned if the demo does not create 
  80         # its own top-level window 
  82             # so set the frame to a good size for showing stuff 
  83             frame
.SetSize((640, 480)) 
  87             frect 
= frame
.GetRect() 
  90             # It was probably a dialog or something that is already 
  91             # gone, so we're done. 
  95         self
.SetTopWindow(frame
) 
  97         #wx.Log_SetActiveTarget(wx.LogStderr()) 
  98         #wx.Log_SetTraceMask(wx.TraceMessages) 
 101             # Make a PyShell window, and position it below our test window 
 103             shell 
= py
.shell
.ShellFrame(None, locals=ns
) 
 104             frect
.OffsetXY(0, frect
.height
) 
 109             # Hook the close event of the test window so that we close 
 110             # the shell at the same time 
 115             frame
.Bind(wx
.EVT_CLOSE
, CloseShell
) 
 120     def OnExitApp(self
, evt
): 
 121         self
.frame
.Close(True) 
 124     def OnCloseFrame(self
, evt
): 
 125         if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"): 
 126             self
.window
.ShutdownDemo() 
 130 #---------------------------------------------------------------------------- 
 135     for x 
in range(len(sys
.argv
)): 
 136         if sys
.argv
[x
] in ['--shell', '-shell', '-s']: 
 142         print "Please specify a demo module name on the command-line" 
 145     name
, ext  
= os
.path
.splitext(argv
[1]) 
 146     module 
= __import__(name
) 
 149     app 
= RunDemoApp(name
, module
, useShell
) 
 154 if __name__ 
== "__main__":