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
21 print "wx.VERSION_STRING = ", wx
.VERSION_STRING
23 assertMode
= wx
.PYAPP_ASSERT_DIALOG
24 ##assertMode = wx.PYAPP_ASSERT_EXCEPTION
28 #----------------------------------------------------------------------------
31 def WriteText(self
, text
):
38 class RunDemoApp(wx
.App
):
39 def __init__(self
, name
, module
):
41 self
.demoModule
= module
42 wx
.App
.__init
__(self
, 0)
46 wx
.InitAllImageHandlers()
47 wx
.Log_SetActiveTarget(wx
.LogStderr())
49 self
.SetAssertMode(assertMode
)
51 frame
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(0,0),
52 style
=wx
.NO_FULL_REPAINT_ON_RESIZE|wx
.DEFAULT_FRAME_STYLE
)
53 frame
.CreateStatusBar()
54 menuBar
= wx
.MenuBar()
56 menu
.Append(101, "E&xit\tAlt-X", "Exit demo")
57 wx
.EVT_MENU(self
, 101, self
.OnButton
)
58 menuBar
.Append(menu
, "&File")
59 frame
.SetMenuBar(menuBar
)
61 wx
.EVT_CLOSE(frame
, self
.OnCloseFrame
)
63 win
= self
.demoModule
.runTest(frame
, frame
, Log())
65 # a window will be returned if the demo does not create
66 # its own top-level window
68 # so set the frame to a good size for showing stuff
69 frame
.SetSize((640, 480))
74 # otherwise the demo made its own frame, so just put a
76 if hasattr(frame
, 'otherWin'):
77 p
= wx
.Panel(frame
, -1)
78 b
= wx
.Button(p
, -1, " Exit ", (10,10))
80 frame
.SetClientSize(p
.GetSize())
81 #frame.SetSize((200, 100))
82 wx
.EVT_BUTTON(frame
, b
.GetId(), self
.OnButton
)
84 # It was probably a dialog or something that is already
85 # gone, so we're done.
89 self
.SetTopWindow(frame
)
91 #wx.Log_SetActiveTarget(wx.LogStderr())
92 #wx.Log_SetTraceMask(wx.TraceMessages)
96 def OnButton(self
, evt
):
97 self
.frame
.Close(True)
100 def OnCloseFrame(self
, evt
):
101 if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"):
102 self
.window
.ShutdownDemo()
106 #----------------------------------------------------------------------------
111 print "Please specify a demo module name on the command-line"
115 if name
[-3:] == '.py':
117 module
= __import__(name
)
120 app
= RunDemoApp(name
, module
)
125 if __name__
== "__main__":