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