]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/run.py
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:", wx
.version()
25 print "pid:", os
.getpid()
26 ##raw_input("Press Enter...")
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
, redirect
=False)
51 wx
.Log_SetActiveTarget(wx
.LogStderr())
53 self
.SetAssertMode(assertMode
)
55 frame
= wx
.Frame(None, -1, "RunDemo: " + self
.name
, pos
=(50,50), size
=(200,100),
56 style
=wx
.DEFAULT_FRAME_STYLE
)
57 frame
.CreateStatusBar()
59 menuBar
= wx
.MenuBar()
61 item
= menu
.Append(-1, "E&xit\tCtrl-Q", "Exit demo")
62 self
.Bind(wx
.EVT_MENU
, self
.OnExitApp
, item
)
63 menuBar
.Append(menu
, "&File")
68 ns
['module'] = self
.demoModule
71 frame
.SetMenuBar(menuBar
)
73 frame
.Bind(wx
.EVT_CLOSE
, self
.OnCloseFrame
)
75 win
= self
.demoModule
.runTest(frame
, frame
, Log())
77 # a window will be returned if the demo does not create
78 # its own top-level window
80 # so set the frame to a good size for showing stuff
81 frame
.SetSize((640, 480))
85 frect
= frame
.GetRect()
88 # It was probably a dialog or something that is already
89 # gone, so we're done.
93 self
.SetTopWindow(frame
)
95 #wx.Log_SetActiveTarget(wx.LogStderr())
96 #wx.Log_SetTraceMask(wx.TraceMessages)
99 # Make a PyShell window, and position it below our test window
101 shell
= py
.shell
.ShellFrame(None, locals=ns
)
102 frect
.OffsetXY(0, frect
.height
)
107 # Hook the close event of the test window so that we close
108 # the shell at the same time
113 frame
.Bind(wx
.EVT_CLOSE
, CloseShell
)
118 def OnExitApp(self
, evt
):
119 self
.frame
.Close(True)
122 def OnCloseFrame(self
, evt
):
123 if hasattr(self
, "window") and hasattr(self
.window
, "ShutdownDemo"):
124 self
.window
.ShutdownDemo()
128 #----------------------------------------------------------------------------
133 for x
in range(len(sys
.argv
)):
134 if sys
.argv
[x
] in ['--shell', '-shell', '-s']:
140 print "Please specify a demo module name on the command-line"
143 name
, ext
= os
.path
.splitext(argv
[1])
144 module
= __import__(name
)
147 app
= RunDemoApp(name
, module
, useShell
)
152 if __name__
== "__main__":