]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/run.py
added destructor (correction for Mac OS X)
[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
20
21import sys
22from wxPython.wx import *
23
24#----------------------------------------------------------------------------
25
26class Log:
27 def WriteText(self, text):
28 sys.stdout.write(text)
29 write = WriteText
30
31
32class RunDemoApp(wxApp):
33 def __init__(self, name, module):
34 self.name = name
35 self.demoModule = module
36 wxApp.__init__(self, 0)
37
38 def OnInit(self):
39 wxInitAllImageHandlers()
f6bcfd97
BP
40 frame = wxFrame(None, -1, "RunDemo: " + self.name, size=(0,0),
41 style=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE)
4c9993c3
RD
42 frame.CreateStatusBar()
43 frame.Show(true)
44 win = self.demoModule.runTest(frame, frame, Log())
45
46 # a window will be returned if the demo does not create
47 # its own top-level window
48 if win:
49 # so set the frame to a good size for showing stuff
f6bcfd97
BP
50 frame.SetSize((640, 480))
51 win.SetFocus()
4c9993c3
RD
52
53 else:
54 # otherwise the demo made its own frame, so just put a
55 # button in this one
56 if hasattr(frame, 'otherWin'):
57 wxButton(frame, 1101, " Exit ")
58 frame.SetSize((200, 100))
59 EVT_BUTTON(frame, 1101, self.OnButton)
60 else:
61 # It was probably a dialog or something that is already
62 # gone, so we're done.
63 frame.Destroy()
64 return true
65
66 self.SetTopWindow(frame)
67 self.frame = frame
68 return true
69
70
71 def OnButton(self, evt):
72 self.frame.Close(true)
73
74#----------------------------------------------------------------------------
75
76
7ff49f0c
RD
77def main(argv):
78 if len(argv) != 2:
4c9993c3
RD
79 print "Please specify a demo module name on the command-line"
80 raise SystemExit
81
7ff49f0c 82 name = argv[1]
f6bcfd97
BP
83 if name[-3:] == '.py':
84 name = name[:-3]
4c9993c3
RD
85 module = __import__(name)
86
87
88 app = RunDemoApp(name, module)
89 app.MainLoop()
90
91
92
93if __name__ == "__main__":
7ff49f0c 94 main(sys.argv)
4c9993c3
RD
95
96