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 #----------------------------------------------------------------------------
27 def WriteText(self
, text
):
34 class RunDemoApp(wx
.App
):
35 def __init__(self
, name
, module
):
37 self
.demoModule
= module
38 wx
.App
.__init
__(self
, 0)
42 wx
.InitAllImageHandlers()
43 wx
.Log_SetActiveTarget(wx
.LogStderr())
45 #self.SetAssertMode(wx.PYAPP_ASSERT_DIALOG)
47 frame
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(0,0),
48 style
=wx
.NO_FULL_REPAINT_ON_RESIZE|wx
.DEFAULT_FRAME_STYLE
)
49 frame
.CreateStatusBar()
50 menuBar
= wx
.MenuBar()
52 menu
.Append(101, "E&xit\tAlt-X", "Exit demo")
53 wx
.EVT_MENU(self
, 101, self
.OnButton
)
54 menuBar
.Append(menu
, "&File")
55 frame
.SetMenuBar(menuBar
)
57 wx
.EVT_CLOSE(frame
, self
.OnCloseFrame
)
59 win
= self
.demoModule
.runTest(frame
, frame
, Log())
61 # a window will be returned if the demo does not create
62 # its own top-level window
64 # so set the frame to a good size for showing stuff
65 frame
.SetSize((640, 480))
70 # otherwise the demo made its own frame, so just put a
72 if hasattr(frame
, 'otherWin'):
73 b
= wx
.Button(frame
, -1, " Exit ")
74 frame
.SetSize((200, 100))
75 wx
.EVT_BUTTON(frame
, b
.GetId(), self
.OnButton
)
77 # It was probably a dialog or something that is already
78 # gone, so we're done.
82 self
.SetTopWindow(frame
)
84 #wx.Log_SetActiveTarget(wx.LogStderr())
85 #wx.Log_SetTraceMask(wx.TraceMessages)
89 def OnButton(self
, evt
):
90 self
.frame
.Close(True)
93 def OnCloseFrame(self
, evt
):
94 if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"):
95 self
.window
.ShutdownDemo()
99 #----------------------------------------------------------------------------
104 print "Please specify a demo module name on the command-line"
108 if name
[-3:] == '.py':
110 module
= __import__(name
)
113 app
= RunDemoApp(name
, module
)
118 if __name__
== "__main__":