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
):
28 sys
.stdout
.write(text
)
32 class RunDemoApp(wxApp
):
33 def __init__(self
, name
, module
):
35 self
.demoModule
= module
36 wxApp
.__init
__(self
, 0)
39 wxInitAllImageHandlers()
40 frame
= wxFrame(None, -1, "RunDemo: " + self
.name
, size
=(0,0),
41 style
=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE
)
42 frame
.CreateStatusBar()
45 menu
.Append(101, "E&xit\tAlt-X", "Exit demo")
46 EVT_MENU(self
, 101, self
.OnButton
)
47 menuBar
.Append(menu
, "&File")
48 frame
.SetMenuBar(menuBar
)
50 win
= self
.demoModule
.runTest(frame
, frame
, Log())
52 # a window will be returned if the demo does not create
53 # its own top-level window
55 # so set the frame to a good size for showing stuff
56 frame
.SetSize((640, 480))
60 # otherwise the demo made its own frame, so just put a
62 if hasattr(frame
, 'otherWin'):
63 b
= wxButton(frame
, -1, " Exit ")
64 frame
.SetSize((200, 100))
65 EVT_BUTTON(frame
, b
.GetId(), self
.OnButton
)
67 # It was probably a dialog or something that is already
68 # gone, so we're done.
72 self
.SetTopWindow(frame
)
77 def OnButton(self
, evt
):
78 self
.frame
.Close(true
)
80 #----------------------------------------------------------------------------
85 print "Please specify a demo module name on the command-line"
89 if name
[-3:] == '.py':
91 module
= __import__(name
)
94 app
= RunDemoApp(name
, module
)
99 if __name__
== "__main__":