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