]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/run.py
Undid last commit and restored bool argument to wxFrame::DoGiveHelp() as
[wxWidgets.git] / wxPython / demo / run.py
CommitLineData
f6bcfd97 1#!/usr/bin/env python
4c9993c3
RD
2#----------------------------------------------------------------------------
3# Name: run.py
4# Purpose: Simple framework for running individual demos
5#
6# Author: Robin Dunn
7#
8# Created: 6-March-2000
9# RCS-ID: $Id$
10# Copyright: (c) 2000 by Total Control Software
11# Licence: wxWindows license
12#----------------------------------------------------------------------------
13
14"""
15This program will load and run one of the individual demos in this
16directory within its own frame window. Just specify the module name
17on the command line.
18"""
19
8030e0e9 20import wx
cbfc9df6 21import wx.lib.mixins.inspection
c38400d0
RD
22import sys, os
23
24# stuff for debugging
a47418db 25print "wx.version:", wx.version()
c38400d0 26print "pid:", os.getpid()
74a57fcd 27##raw_input("Press Enter...")
4c9993c3 28
d14a1e28
RD
29assertMode = wx.PYAPP_ASSERT_DIALOG
30##assertMode = wx.PYAPP_ASSERT_EXCEPTION
31
4c9993c3
RD
32
33#----------------------------------------------------------------------------
34
35class Log:
36 def WriteText(self, text):
1e4a197e
RD
37 if text[-1:] == '\n':
38 text = text[:-1]
1fded56b 39 wx.LogMessage(text)
4c9993c3
RD
40 write = WriteText
41
42
cbfc9df6 43class RunDemoApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
8eca4fef 44 def __init__(self, name, module, useShell):
4c9993c3
RD
45 self.name = name
46 self.demoModule = module
8eca4fef 47 self.useShell = useShell
4287ca9e 48 wx.App.__init__(self, redirect=False)
0af45411 49
4c9993c3
RD
50
51 def OnInit(self):
1fded56b 52 wx.Log_SetActiveTarget(wx.LogStderr())
1e4a197e 53
d14a1e28 54 self.SetAssertMode(assertMode)
8030e0e9 55 self.Init() # InspectionMixin
1fded56b 56
fd3f2efe 57 frame = wx.Frame(None, -1, "RunDemo: " + self.name, pos=(50,50), size=(200,100),
8030e0e9 58 style=wx.DEFAULT_FRAME_STYLE, name="run a sample")
4c9993c3 59 frame.CreateStatusBar()
7f8f0b88 60
1fded56b
RD
61 menuBar = wx.MenuBar()
62 menu = wx.Menu()
30fc5e8f 63 item = menu.Append(-1, "E&xit\tCtrl-Q", "Exit demo")
31a01a24 64 self.Bind(wx.EVT_MENU, self.OnExitApp, item)
8082483b 65 menuBar.Append(menu, "&File")
7f8f0b88 66
8eca4fef 67 ns = {}
31e36465 68 ns['wx'] = wx
8eca4fef
RD
69 ns['app'] = self
70 ns['module'] = self.demoModule
71 ns['frame'] = frame
72
8082483b 73 frame.SetMenuBar(menuBar)
1e4a197e 74 frame.Show(True)
7f8f0b88 75 frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
1e4a197e 76
4c9993c3
RD
77 win = self.demoModule.runTest(frame, frame, Log())
78
79 # a window will be returned if the demo does not create
80 # its own top-level window
81 if win:
82 # so set the frame to a good size for showing stuff
f6bcfd97
BP
83 frame.SetSize((640, 480))
84 win.SetFocus()
1e4a197e 85 self.window = win
8eca4fef
RD
86 ns['win'] = win
87 frect = frame.GetRect()
4c9993c3
RD
88
89 else:
8fc680f4
RD
90 # It was probably a dialog or something that is already
91 # gone, so we're done.
92 frame.Destroy()
93 return True
4c9993c3
RD
94
95 self.SetTopWindow(frame)
96 self.frame = frame
1fded56b
RD
97 #wx.Log_SetActiveTarget(wx.LogStderr())
98 #wx.Log_SetTraceMask(wx.TraceMessages)
8eca4fef
RD
99
100 if self.useShell:
101 # Make a PyShell window, and position it below our test window
102 from wx import py
103 shell = py.shell.ShellFrame(None, locals=ns)
104 frect.OffsetXY(0, frect.height)
105 frect.height = 400
106 shell.SetRect(frect)
107 shell.Show()
108
109 # Hook the close event of the test window so that we close
110 # the shell at the same time
111 def CloseShell(evt):
71ed12a0
RD
112 if shell:
113 shell.Close()
8eca4fef
RD
114 evt.Skip()
115 frame.Bind(wx.EVT_CLOSE, CloseShell)
116
1e4a197e 117 return True
4c9993c3
RD
118
119
31a01a24 120 def OnExitApp(self, evt):
1e4a197e
RD
121 self.frame.Close(True)
122
123
124 def OnCloseFrame(self, evt):
125 if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
126 self.window.ShutdownDemo()
127 evt.Skip()
128
4c9993c3
RD
129
130#----------------------------------------------------------------------------
131
132
7ff49f0c 133def main(argv):
8eca4fef
RD
134 useShell = False
135 for x in range(len(sys.argv)):
136 if sys.argv[x] in ['--shell', '-shell', '-s']:
137 useShell = True
138 del sys.argv[x]
139 break
140
3979290c 141 if len(argv) < 2:
4c9993c3
RD
142 print "Please specify a demo module name on the command-line"
143 raise SystemExit
144
887dfc14 145 name, ext = os.path.splitext(argv[1])
4c9993c3
RD
146 module = __import__(name)
147
148
8eca4fef 149 app = RunDemoApp(name, module, useShell)
4c9993c3
RD
150 app.MainLoop()
151
152
153
154if __name__ == "__main__":
7ff49f0c 155 main(sys.argv)
4c9993c3
RD
156
157