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