]>
Commit | Line | Data |
---|---|---|
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 | """ | |
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 | ||
b5a5d647 | 21 | import sys, os |
4c9993c3 RD |
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 | |
eb0f373c | 36 | wxApp.__init__(self, 0) ##wxPlatform == "__WXMAC__") |
0af45411 | 37 | |
4c9993c3 RD |
38 | |
39 | def OnInit(self): | |
40 | wxInitAllImageHandlers() | |
f6bcfd97 BP |
41 | frame = wxFrame(None, -1, "RunDemo: " + self.name, size=(0,0), |
42 | style=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE) | |
4c9993c3 | 43 | frame.CreateStatusBar() |
8082483b RD |
44 | menuBar = wxMenuBar() |
45 | menu = wxMenu() | |
46 | menu.Append(101, "E&xit\tAlt-X", "Exit demo") | |
47 | EVT_MENU(self, 101, self.OnButton) | |
48 | menuBar.Append(menu, "&File") | |
49 | frame.SetMenuBar(menuBar) | |
4c9993c3 RD |
50 | frame.Show(true) |
51 | win = self.demoModule.runTest(frame, frame, Log()) | |
52 | ||
53 | # a window will be returned if the demo does not create | |
54 | # its own top-level window | |
55 | if win: | |
56 | # so set the frame to a good size for showing stuff | |
f6bcfd97 BP |
57 | frame.SetSize((640, 480)) |
58 | win.SetFocus() | |
4c9993c3 RD |
59 | |
60 | else: | |
61 | # otherwise the demo made its own frame, so just put a | |
62 | # button in this one | |
63 | if hasattr(frame, 'otherWin'): | |
b5a5d647 | 64 | b = wxButton(frame, -1, " Exit ") |
4c9993c3 | 65 | frame.SetSize((200, 100)) |
b5a5d647 | 66 | EVT_BUTTON(frame, b.GetId(), self.OnButton) |
4c9993c3 RD |
67 | else: |
68 | # It was probably a dialog or something that is already | |
69 | # gone, so we're done. | |
70 | frame.Destroy() | |
71 | return true | |
72 | ||
73 | self.SetTopWindow(frame) | |
74 | self.frame = frame | |
f9b24f07 RD |
75 | #wxLog_SetActiveTarget(wxLogStderr()) |
76 | #wxLog_SetTraceMask(wxTraceMessages) | |
4c9993c3 RD |
77 | return true |
78 | ||
79 | ||
80 | def OnButton(self, evt): | |
81 | self.frame.Close(true) | |
82 | ||
83 | #---------------------------------------------------------------------------- | |
84 | ||
85 | ||
7ff49f0c | 86 | def main(argv): |
3979290c | 87 | if len(argv) < 2: |
4c9993c3 RD |
88 | print "Please specify a demo module name on the command-line" |
89 | raise SystemExit | |
90 | ||
7ff49f0c | 91 | name = argv[1] |
f6bcfd97 BP |
92 | if name[-3:] == '.py': |
93 | name = name[:-3] | |
4c9993c3 RD |
94 | module = __import__(name) |
95 | ||
96 | ||
97 | app = RunDemoApp(name, module) | |
98 | app.MainLoop() | |
99 | ||
100 | ||
101 | ||
102 | if __name__ == "__main__": | |
7ff49f0c | 103 | main(sys.argv) |
4c9993c3 RD |
104 | |
105 |