]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/run.py
Fixed remaining int vs. long warnings.
[wxWidgets.git] / utils / wxPython / demo / run.py
1 #!/bin/env python
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 """
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
17 on the command line.
18 """
19
20
21 import sys
22 from wxPython.wx import *
23
24 #----------------------------------------------------------------------------
25
26 class Log:
27 def WriteText(self, text):
28 sys.stdout.write(text)
29 write = WriteText
30
31
32 class 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()
40 frame = wxFrame(None, -1, "RunDemo: " + self.name, size=(0,0))
41 frame.CreateStatusBar()
42 frame.Show(true)
43 win = self.demoModule.runTest(frame, frame, Log())
44
45 # a window will be returned if the demo does not create
46 # its own top-level window
47 if win:
48 # so set the frame to a good size for showing stuff
49 frame.SetSize((600, 450))
50
51 else:
52 # otherwise the demo made its own frame, so just put a
53 # button in this one
54 if hasattr(frame, 'otherWin'):
55 wxButton(frame, 1101, " Exit ")
56 frame.SetSize((200, 100))
57 EVT_BUTTON(frame, 1101, self.OnButton)
58 else:
59 # It was probably a dialog or something that is already
60 # gone, so we're done.
61 frame.Destroy()
62 return true
63
64 self.SetTopWindow(frame)
65 self.frame = frame
66 return true
67
68
69 def OnButton(self, evt):
70 self.frame.Close(true)
71
72 #----------------------------------------------------------------------------
73
74
75 def main(argv):
76 if len(argv) != 2:
77 print "Please specify a demo module name on the command-line"
78 raise SystemExit
79
80 name = argv[1]
81 module = __import__(name)
82
83
84 app = RunDemoApp(name, module)
85 app.MainLoop()
86
87
88
89 if __name__ == "__main__":
90 main(sys.argv)
91
92