Home | Trees | Indices | Help |
---|
|
1 from SimPy.SimulationStep import * 2 from Tkinter import * 3 import SimPy.SimulationStep, GUIDebug 4 5 # global variables 6 _breakpoints = [] 7 _until = 0 8 _callback = None 9 _lastCommandIssued = "" 10 _simStarted = False 11 _registeredClasses = [] 12 _runMode = None 13 14 # run modes 15 STEP = 1 16 NO_STEP = 2 17 18 # register new object for windowing20 21 global _registeredClasses 22 23 # if process subclass is given register it 24 if type(obj) == TypeType and issubclass(obj, Process): 25 _registeredClasses += [(obj,name,hook)] 26 27 # if instance of process is given register it 28 elif issubclass(type(obj), Process): 29 _guiCtrl.addNewProcess(obj,name,hook) 30 31 # if instance of Resource is given register it 32 elif issubclass(type(obj), Resource): 33 _guiCtrl.addNewResource(obj,name,hook) 34 35 # else create a generic window with hook 36 else: 37 _guiCtrl.addNewWindow(obj,name,hook)38 39 # override activate to catch registered class instances41 42 global _registeredClasses 43 44 SimPy.SimulationStep.activate(obj,process,at,delay,prior) 45 46 # if obj is instance of the class register it 47 for c,n,h in _registeredClasses: 48 if isinstance(obj, c): 49 _guiCtrl.addNewProcess(obj,n,h)50 51 # add to breakpoints 57 58 # set the current run mode of simulation 63 64 # initialize the simulation and the GUI66 67 SimPy.SimulationStep.initialize() 68 69 # create gui controller 70 global _guiCtrl 71 _guiCtrl = GUIDebug.GUIController() 72 73 # initialize run mode if not already set 74 global _runMode 75 if not _runMode: 76 _runMode = STEP77 78 # simulation function80 81 global _runMode 82 83 # print usage 84 if( _runMode == STEP ): 85 print "Breakpoint Usage:" 86 print " [c] Continue simulation" 87 print " [s] Step to next event" 88 print " [b #] Add new breakpoint" 89 print 90 print " [q] Quit debugger" 91 print 92 93 # set global variables 94 global _until 95 _until = until 96 97 global _callback 98 _callback = callback 99 100 # initialize to step command 101 global _lastCommandIssued 102 _lastCommandIssued = "s" 103 104 # only prompt user if we are in STEP mode 105 if( _runMode == STEP): promptUser() 106 107 # quit if user entered 'q' 108 if( _lastCommandIssued == 'q'): 109 return 110 111 # begin simulation 112 global _simStarted 113 _simStarted = True 114 startStepping() 115 SimPy.SimulationStep.simulate(callback=callbackFunction,until=_until)116 117 # check for breakpoints119 120 global _breakpoints,_runMode,_guiCtrl 121 122 # NO_STEP mode means we update windows and take no breaks 123 # this is used for compatibility with REAL debuggers 124 if( _runMode == NO_STEP ): 125 _guiCtrl.updateAllWindows() 126 return 127 128 if( 0 == len(_breakpoints) ): 129 return 130 131 # this is a breakpoint 132 if( now() >= _breakpoints[0] ): 133 134 # update gui 135 _guiCtrl.updateAllWindows() 136 137 # remove past times from breakpoints list 138 while( 0 != len(_breakpoints) and now() >= _breakpoints[0] ): 139 _breakpoints.pop(0) 140 141 # call user's callback function 142 global _callback 143 _callback() 144 145 promptUser()146 147 # prompt user for next command149 150 global _simStarted 151 152 # set prompt text 153 prompt = '(SimDB) > ' 154 155 # pause for breakpoint 156 while( 1 ): 157 input = raw_input( prompt ) 158 159 # take a look at the last command issued 160 global _lastCommandIssued 161 162 if 0 == len(input): 163 input = _lastCommandIssued 164 165 _lastCommandIssued = input 166 167 # continue 168 if( "c" == input ): 169 break 170 171 # step 172 elif( "s" == input ): 173 global _breakpoints 174 _breakpoints.insert(0,0) 175 break 176 177 # add breakpoint 178 elif( 0 == input.find("b")): 179 try: 180 for i in eval( input[1:] + "," ): 181 newBreakpoint( int(i) ) 182 except SyntaxError: 183 print "missing breakpoint values" 184 185 # quit 186 elif( "q" == input ): 187 SimPy.SimulationStep.stopSimulation() 188 return 189 190 else: 191 print " unknown command"192
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Apr 02 06:43:31 2009 | http://epydoc.sourceforge.net |