7
|
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 # 20080209 - Yoshihiko FUCHITA (fuchita@cr.ie.u-ryukyu.ac.jp)
|
|
15 #
|
|
16 # o Fixed RunDemoApp
|
|
17 #
|
|
18
|
|
19
|
|
20
|
|
21 """
|
|
22 This program will load and run one of the individual demos in this
|
|
23 directory within its own frame window. Just specify the module name
|
|
24 on the command line.
|
|
25 """
|
|
26
|
|
27 import wx # This module uses the new wx namespace
|
|
28 import sys, os
|
|
29
|
|
30 import re
|
|
31 import ParseGraffle
|
|
32 import Graffle2Arrangement
|
|
33
|
|
34 # stuff for debugging
|
|
35 print "wx.VERSION_STRING = ", wx.VERSION_STRING
|
|
36 print "pid:", os.getpid()
|
|
37 ##raw_input("Press Enter...")
|
|
38
|
|
39 assertMode = wx.PYAPP_ASSERT_DIALOG
|
|
40 ##assertMode = wx.PYAPP_ASSERT_EXCEPTION
|
|
41
|
|
42
|
|
43 #----------------------------------------------------------------------------
|
|
44
|
|
45 class Log:
|
|
46 def WriteText(self, text):
|
|
47 if text[-1:] == '\n':
|
|
48 text = text[:-1]
|
|
49 wx.LogMessage(text)
|
|
50 write = WriteText
|
|
51
|
|
52
|
|
53 class RunDemoApp(wx.App):
|
|
54 def __init__(self, name, module, useShell, node_list, log_list):
|
|
55 self.name = name
|
|
56 self.demoModule = module
|
|
57 self.useShell = useShell
|
|
58 self.nodelist = node_list
|
|
59 self.loglist = log_list
|
|
60 wx.App.__init__(self, redirect=False)
|
|
61
|
|
62
|
|
63 def OnInit(self):
|
|
64 wx.Log_SetActiveTarget(wx.LogStderr())
|
|
65
|
|
66 self.SetAssertMode(assertMode)
|
|
67
|
|
68 frame = wx.Frame(None, -1, "RunDemo: " + self.name, pos=(50,50), size=(200,100),
|
|
69 style=wx.DEFAULT_FRAME_STYLE)
|
|
70 frame.CreateStatusBar()
|
|
71
|
|
72 menuBar = wx.MenuBar()
|
|
73 menu = wx.Menu()
|
|
74 item = menu.Append(-1, "E&xit\tAlt-X", "Exit demo")
|
|
75 self.Bind(wx.EVT_MENU, self.OnButton, item)
|
|
76 menuBar.Append(menu, "&File")
|
|
77
|
|
78 ns = {}
|
|
79 ns['wx'] = wx
|
|
80 ns['app'] = self
|
|
81 ns['module'] = self.demoModule
|
|
82 ns['frame'] = frame
|
|
83
|
|
84 frame.SetMenuBar(menuBar)
|
|
85 frame.Show(True)
|
|
86 frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
|
|
87
|
|
88 win = self.demoModule.runTest(frame, frame, Log(), self.nodelist, self.loglist)
|
|
89
|
|
90
|
|
91 #p = wx.Panel(frame, -1)
|
|
92 #b = wx.Button(frame, -1, " Exit ", (10,10))
|
|
93 #wx.CallAfter(frame.SetClientSize, (200, 100))
|
|
94 #frame.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
95
|
|
96 # a window will be returned if the demo does not create
|
|
97 # its own top-level window
|
|
98 if win:
|
|
99 # so set the frame to a good size for showing stuff
|
|
100 frame.SetSize((800, 600))
|
|
101 win.SetFocus()
|
|
102 self.window = win
|
|
103 ns['win'] = win
|
|
104 frect = frame.GetRect()
|
|
105
|
|
106 else:
|
|
107 # otherwise the demo made its own frame, so just put a
|
|
108 # button in this one
|
|
109 if hasattr(frame, 'otherWin'):
|
|
110 ns['win'] = frame.otherWin
|
|
111 frect = frame.otherWin.GetRect()
|
|
112 p = wx.Panel(frame, -1)
|
|
113 b = wx.Button(p, -1, " Exit ", (10,10))
|
|
114 wx.CallAfter(frame.SetClientSize, (200, 100))
|
|
115 frame.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
|
116 else:
|
|
117 # It was probably a dialog or something that is already
|
|
118 # gone, so we're done.
|
|
119 frame.Destroy()
|
|
120 return True
|
|
121
|
|
122 self.SetTopWindow(frame)
|
|
123 self.frame = frame
|
|
124 #wx.Log_SetActiveTarget(wx.LogStderr())
|
|
125 #wx.Log_SetTraceMask(wx.TraceMessages)
|
|
126
|
|
127 if self.useShell:
|
|
128 # Make a PyShell window, and position it below our test window
|
|
129 from wx import py
|
|
130 shell = py.shell.ShellFrame(None, locals=ns)
|
|
131 frect.OffsetXY(0, frect.height)
|
|
132 frect.height = 400
|
|
133 shell.SetRect(frect)
|
|
134 shell.Show()
|
|
135
|
|
136 # Hook the close event of the test window so that we close
|
|
137 # the shell at the same time
|
|
138 def CloseShell(evt):
|
|
139 if shell:
|
|
140 shell.Close()
|
|
141 evt.Skip()
|
|
142 frame.Bind(wx.EVT_CLOSE, CloseShell)
|
|
143
|
|
144 return True
|
|
145
|
|
146
|
|
147 def OnButton(self, evt):
|
|
148 self.frame.Close(True)
|
|
149
|
|
150
|
|
151 def OnCloseFrame(self, evt):
|
|
152 if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
|
|
153 self.window.ShutdownDemo()
|
|
154 evt.Skip()
|
|
155
|
|
156
|
|
157 #----------------------------------------------------------------------------
|
|
158
|
|
159 class logInfo:
|
|
160 def __init__(self, MasterTSID = None, dst = None, InNum = None, OutNum = None):
|
|
161 self.masterTSID = MasterTSID
|
|
162 self.dstTSID = dst
|
|
163 self.In = InNum
|
|
164 self.Out = OutNum
|
|
165 #for dst in dstlist:
|
|
166 # self.dstList[dst].append(dstInfo(dst.dstID, dst.In, dst.Out))
|
|
167
|
|
168 class dstInfo:
|
|
169 def __init__(self, dst = "", InNum = None, OutNum = None):
|
|
170 self.dstTSID = dst
|
|
171 self.In = InNum
|
|
172 self.Out = OutNum
|
|
173
|
|
174
|
|
175 def main(argv):
|
|
176 useShell = False
|
|
177 # for x in range(len(sys.argv)):
|
|
178 # if sys.argv[x] in ['--shell', '-shell', '-s']:
|
|
179 # useShell = True
|
|
180 # del sys.argv[x]
|
|
181 # break
|
|
182
|
|
183 #if len(argv) < 2:
|
|
184 # print "Please specify a demo module name on the command-line"
|
|
185 # raise SystemExit
|
|
186
|
|
187 #name, ext = os.path.splitext(argv[1])
|
|
188 name = "Visualizer"
|
|
189 module = __import__(name)
|
|
190 #module = ""
|
|
191
|
|
192 if len(sys.argv) < 4:
|
|
193 usage(sys.argv[0])
|
|
194
|
|
195 grafflefile = sys.argv[1]
|
|
196
|
|
197 nodetxt = open(sys.argv[2],'r').read()
|
|
198 nodelist = re.findall("[-.\w]+:[0-9]+",nodetxt)
|
|
199
|
|
200 res = ParseGraffle.parseFile(grafflefile)
|
|
201
|
|
202 node_list = Graffle2Arrangement.parsedlist2NodeArrangements(res, nodelist)
|
|
203 #print node_arrengement_list
|
|
204
|
|
205 logtxt = open(sys.argv[3],'r').read()
|
|
206 log_list = re.findall("[-.\w]+:[0-9]+\-\-+[-.\w]+:[0-9]+\s[a-z]=[0-9]+\sid=[0-9]+\sseq=[0-9]+\sdata=.*\n",logtxt)
|
|
207
|
|
208
|
|
209 #print log_list
|
|
210
|
|
211 # logInfo_list1 = []
|
|
212 # for list in log_list:
|
|
213 # (masterID, dstID) = list.split("--")
|
|
214 # (dstID, command) = dstID.split(" ")
|
|
215 # if re.match("^i=",command):
|
|
216 # logInfo_list1.append(logInfo(masterID, dstID, command, None))
|
|
217 # elif re.match("^o=",command):
|
|
218 # logInfo_list1.append(logInfo(masterID, dstID, None, command))
|
|
219
|
|
220 #for n in logInfo_list:
|
|
221 # print "MaterTSID:",n.masterTSID
|
|
222 # print "DstID:",n.dstTSID
|
|
223 # print "In:",n.In
|
|
224 # print "Out:",n.Out
|
|
225 # p = logInfo_list1.pop(10)
|
|
226 # print "MaterTSID:",p.masterTSID
|
|
227 # print "DstID:",p.dstTSID
|
|
228 # print "In:",p.In
|
|
229 # print "Out:",p.Out
|
|
230
|
|
231 app = RunDemoApp(name, module, useShell, node_list, log_list)
|
|
232 app.MainLoop()
|
|
233
|
|
234
|
|
235
|
|
236 if __name__ == "__main__":
|
|
237 main(sys.argv)
|
|
238
|
|
239
|