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
, useShell
):
45 self
.demoModule
= module
46 self
.useShell
= useShell
47 wx
.App
.__init
__(self
, 0)
51 wx
.InitAllImageHandlers()
52 wx
.Log_SetActiveTarget(wx
.LogStderr())
54 self
.SetAssertMode(assertMode
)
56 frame
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(200,100),
57 style
=wx
.NO_FULL_REPAINT_ON_RESIZE|wx
.DEFAULT_FRAME_STYLE
)
58 frame
.CreateStatusBar()
60 menuBar
= wx
.MenuBar()
62 item
= menu
.Append(-1, "E&xit\tAlt-X", "Exit demo")
63 self
.Bind(wx
.EVT_MENU
, self
.OnButton
, item
)
64 menuBar
.Append(menu
, "&File")
69 ns
['module'] = self
.demoModule
72 frame
.SetMenuBar(menuBar
)
74 frame
.Bind(wx
.EVT_CLOSE
, self
.OnCloseFrame
)
76 win
= self
.demoModule
.runTest(frame
, frame
, Log())
78 # a window will be returned if the demo does not create
79 # its own top-level window
81 # so set the frame to a good size for showing stuff
82 frame
.SetSize((640, 480))
86 frect
= frame
.GetRect()
89 # otherwise the demo made its own frame, so just put a
91 if hasattr(frame
, 'otherWin'):
92 ns
['win'] = frame
.otherWin
93 frect
= frame
.otherWin
.GetRect()
94 p
= wx
.Panel(frame
, -1)
95 b
= wx
.Button(p
, -1, " Exit ", (10,10))
97 #frame.SetClientSize(p.GetSize())
98 frame
.SetSize((200, 100))
99 frame
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
101 # It was probably a dialog or something that is already
102 # gone, so we're done.
106 self
.SetTopWindow(frame
)
108 #wx.Log_SetActiveTarget(wx.LogStderr())
109 #wx.Log_SetTraceMask(wx.TraceMessages)
112 # Make a PyShell window, and position it below our test window
114 shell
= py
.shell
.ShellFrame(None, locals=ns
)
115 frect
.OffsetXY(0, frect
.height
)
120 # Hook the close event of the test window so that we close
121 # the shell at the same time
126 frame
.Bind(wx
.EVT_CLOSE
, CloseShell
)
131 def OnButton(self
, evt
):
132 self
.frame
.Close(True)
135 def OnCloseFrame(self
, evt
):
136 if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"):
137 self
.window
.ShutdownDemo()
141 #----------------------------------------------------------------------------
146 for x
in range(len(sys
.argv
)):
147 if sys
.argv
[x
] in ['--shell', '-shell', '-s']:
153 print "Please specify a demo module name on the command-line"
156 name
, ext
= os
.path
.splitext(argv
[1])
157 module
= __import__(name
)
160 app
= RunDemoApp(name
, module
, useShell
)
165 if __name__
== "__main__":