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