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