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