]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/run.py
Moved some methods/classes inside COMPATIBILITY_2_4.
[wxWidgets.git] / wxPython / demo / run.py
1 #!/usr/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 import wx # This module uses the new wx namespace
21
22 import sys, os
23
24 #----------------------------------------------------------------------------
25
26 class Log:
27 def WriteText(self, text):
28 if text[-1:] == '\n':
29 text = text[:-1]
30 wx.LogMessage(text)
31 write = WriteText
32
33
34 class RunDemoApp(wx.App):
35 def __init__(self, name, module):
36 self.name = name
37 self.demoModule = module
38 wx.App.__init__(self, 0)
39
40
41 def OnInit(self):
42 wx.InitAllImageHandlers()
43 wx.Log_SetActiveTarget(wx.LogStderr())
44
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)
49 frame.CreateStatusBar()
50 menuBar = wx.MenuBar()
51 menu = wx.Menu()
52 menu.Append(101, "E&xit\tAlt-X", "Exit demo")
53 wx.EVT_MENU(self, 101, self.OnButton)
54 menuBar.Append(menu, "&File")
55 frame.SetMenuBar(menuBar)
56 frame.Show(True)
57 wx.EVT_CLOSE(frame, self.OnCloseFrame)
58
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
65 frame.SetSize((640, 480))
66 win.SetFocus()
67 self.window = win
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'):
73 b = wx.Button(frame, -1, " Exit ")
74 frame.SetSize((200, 100))
75 wx.EVT_BUTTON(frame, b.GetId(), self.OnButton)
76 else:
77 # It was probably a dialog or something that is already
78 # gone, so we're done.
79 frame.Destroy()
80 return True
81
82 self.SetTopWindow(frame)
83 self.frame = frame
84 #wx.Log_SetActiveTarget(wx.LogStderr())
85 #wx.Log_SetTraceMask(wx.TraceMessages)
86 return True
87
88
89 def OnButton(self, evt):
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
98
99 #----------------------------------------------------------------------------
100
101
102 def main(argv):
103 if len(argv) < 2:
104 print "Please specify a demo module name on the command-line"
105 raise SystemExit
106
107 name = argv[1]
108 if name[-3:] == '.py':
109 name = name[:-3]
110 module = __import__(name)
111
112
113 app = RunDemoApp(name, module)
114 app.MainLoop()
115
116
117
118 if __name__ == "__main__":
119 main(sys.argv)
120
121