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 
  20 import wx                  
# This module uses the new wx namespace 
  24 print "wx.VERSION_STRING = ", wx
.VERSION_STRING
 
  25 print "pid:", os
.getpid() 
  26 ##raw_input("Press a key...") 
  28 assertMode 
= wx
.PYAPP_ASSERT_DIALOG
 
  29 ##assertMode = wx.PYAPP_ASSERT_EXCEPTION 
  32 #---------------------------------------------------------------------------- 
  35     def WriteText(self
, text
): 
  42 class RunDemoApp(wx
.App
): 
  43     def __init__(self
, name
, module
): 
  45         self
.demoModule 
= module
 
  46         wx
.App
.__init
__(self
, 0) 
  50         wx
.InitAllImageHandlers() 
  51         wx
.Log_SetActiveTarget(wx
.LogStderr()) 
  53         self
.SetAssertMode(assertMode
) 
  55         frame 
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(200,100), 
  56                         style
=wx
.NO_FULL_REPAINT_ON_RESIZE|wx
.DEFAULT_FRAME_STYLE
) 
  57         frame
.CreateStatusBar() 
  58         menuBar 
= wx
.MenuBar() 
  60         menu
.Append(101, "E&xit\tAlt-X", "Exit demo") 
  61         wx
.EVT_MENU(self
, 101, self
.OnButton
) 
  62         menuBar
.Append(menu
, "&File") 
  63         frame
.SetMenuBar(menuBar
) 
  65         wx
.EVT_CLOSE(frame
, self
.OnCloseFrame
) 
  67         win 
= self
.demoModule
.runTest(frame
, frame
, Log()) 
  69         # a window will be returned if the demo does not create 
  70         # its own top-level window 
  72             # so set the frame to a good size for showing stuff 
  73             frame
.SetSize((640, 480)) 
  78             # otherwise the demo made its own frame, so just put a 
  80             if hasattr(frame
, 'otherWin'): 
  81                 p 
= wx
.Panel(frame
, -1) 
  82                 b 
= wx
.Button(p
, -1, " Exit ", (10,10)) 
  84                 frame
.SetClientSize(p
.GetSize()) 
  85                 #frame.SetSize((200, 100)) 
  86                 wx
.EVT_BUTTON(frame
, b
.GetId(), self
.OnButton
) 
  88                 # It was probably a dialog or something that is already 
  89                 # gone, so we're done. 
  93         self
.SetTopWindow(frame
) 
  95         #wx.Log_SetActiveTarget(wx.LogStderr()) 
  96         #wx.Log_SetTraceMask(wx.TraceMessages) 
 100     def OnButton(self
, evt
): 
 101         self
.frame
.Close(True) 
 104     def OnCloseFrame(self
, evt
): 
 105         if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"): 
 106             self
.window
.ShutdownDemo() 
 110 #---------------------------------------------------------------------------- 
 115         print "Please specify a demo module name on the command-line" 
 119     if name
[-3:] == '.py': 
 121     module 
= __import__(name
) 
 124     app 
= RunDemoApp(name
, module
) 
 129 if __name__ 
== "__main__":