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
22 from wxPython
.wx
import *
24 #----------------------------------------------------------------------------
27 def WriteText(self
, text
):
34 class RunDemoApp(wxApp
):
35 def __init__(self
, name
, module
):
37 self
.demoModule
= module
38 wxApp
.__init
__(self
, 0) ##wxPlatform == "__WXMAC__")
42 wxInitAllImageHandlers()
43 wxLog_SetActiveTarget(wxLogStderr())
45 frame
= wxFrame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(0,0),
46 style
=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE
)
47 frame
.CreateStatusBar()
50 menu
.Append(101, "E&xit\tAlt-X", "Exit demo")
51 EVT_MENU(self
, 101, self
.OnButton
)
52 menuBar
.Append(menu
, "&File")
53 frame
.SetMenuBar(menuBar
)
55 EVT_CLOSE(frame
, self
.OnCloseFrame
)
57 win
= self
.demoModule
.runTest(frame
, frame
, Log())
59 # a window will be returned if the demo does not create
60 # its own top-level window
62 # so set the frame to a good size for showing stuff
63 frame
.SetSize((640, 480))
68 # otherwise the demo made its own frame, so just put a
70 if hasattr(frame
, 'otherWin'):
71 b
= wxButton(frame
, -1, " Exit ")
72 frame
.SetSize((200, 100))
73 EVT_BUTTON(frame
, b
.GetId(), self
.OnButton
)
75 # It was probably a dialog or something that is already
76 # gone, so we're done.
80 self
.SetTopWindow(frame
)
82 #wxLog_SetActiveTarget(wxLogStderr())
83 #wxLog_SetTraceMask(wxTraceMessages)
87 def OnButton(self
, evt
):
88 self
.frame
.Close(True)
91 def OnCloseFrame(self
, evt
):
92 if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"):
93 self
.window
.ShutdownDemo()
97 #----------------------------------------------------------------------------
102 print "Please specify a demo module name on the command-line"
106 if name
[-3:] == '.py':
108 module
= __import__(name
)
111 app
= RunDemoApp(name
, module
)
116 if __name__
== "__main__":