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