| Home | Trees | Indices | Help |
|
|---|
|
|
1 import sys, glob, os 2 import pyforms.Utils.tools as tools, time 3 import argparse 4 from pyforms.terminal.BaseWidget import BaseWidget 5 6 from pyStateMachine.States.State import State,EndState 7 from pyStateMachine.StateMachineControllers.StatesController import StatesController11 def go2decorator(func): 12 def func_wrapper(self, inVar): return func(self, inVar) 13 14 func_wrapper.trueParms = trueParms 15 func_wrapper.falseParms = falseParms 16 func_wrapper.go2StateTrue = true 17 func_wrapper.go2StateFalse = false 18 func_wrapper.label = func.__name__ if func.__doc__==None else '\n'.join([x for x in func.__doc__.replace('\t','').split('\n') if len(x)>0]) 19 return func_wrapper20 return go2decorator 21 33 34 35 @property 37 38 @app.setter 40 43 46 47 @property 4952 53 _parser = argparse.ArgumentParser() 54 55143 14457 BaseWidget.__init__(self, title) 58 StatesController.__init__(self, self.STATES) 59 60 for stateName, state in self.states.items(): 61 if hasattr(state, 'init'): state.init()62 6365 66 # Load the applications 67 for fromStateName, state in reversed( self.states.items() ): 68 if hasattr(state, 'app') and state.app: 69 state.app._parser = self._parser 70 state.app._controlsPrefix = fromStateName 71 #Override the original application formset if the state has a new one 72 state.initForm() 73 74 75 self._parser.add_argument( 76 "--exec", default='', 77 help='Function from the application that should be executed. Use | to separate a list of functions.') 78 79 self._parser.add_argument( 80 "--exportDiagramTo", default='', 81 help='File to where the diagram should export to.') 82 83 self._args = self._parser.parse_args() 84 85 if self._args.exportDiagramTo!='': self.exportGraph(self._args.exportDiagramTo) 86 87 88 for fromStateName, state in reversed( self.states.items() ): 89 if hasattr(state, 'app') and state.app: 90 state.app._args = self._args 91 state.parseTerminalParameters() 92 93 for function in self._args.__dict__.get("exec", []).split('|'): 94 if len(function)>0: getattr(self, function)()95 96 9799 """ 100 Iterate states - each call go to another level 101 """ 102 if len(self._waitingStates)>0: 103 statesOutputs = [] 104 105 #First run all the pending states 106 for fromStateName, toStateName, inputParam in self._waitingStates: 107 state = self._states[toStateName] 108 copyOfCurrentState = dict(self._currentState) 109 110 if isinstance(state, EndState): executionDetails = (toStateName, state, inputParam ) 111 else: 112 p = state.enter(inputParam, copyOfCurrentState) 113 state.execute() 114 outParam = state.leave(p, copyOfCurrentState) 115 executionDetails = (toStateName, state, outParam ) 116 117 statesOutputs.append( executionDetails ) 118 119 #Check the events of each exectuted state: 120 for stateName, state, output in statesOutputs: 121 #Remove the exectued state from the waiting queue 122 self._waitingStates.pop(0) 123 #Check each event 124 for e in state.events: 125 #Select the next state to go 126 go2State = e.go2StateTrue if e(state, output) else e.go2StateFalse 127 #In case the state is None, it stops the state execution 128 if go2State!=None: self._waitingStates.append( [stateName, go2State, output] ) 129 else: self._waitingStates.append( [stateName, 'EndState', output] ) 130 131 "Save the currentState of the iteration" 132 self._currentState = self.__returnCurrentStatesValues() 133 else: 134 print("State machine ended")135 136 138 # Initiate the parameters set by the user 139 self._currentState = self.__returnCurrentStatesValues() 140 141 # Iterate the states execution 142 while not self.ended: self.iterateStates()146 """ 147 Iterate all the states and save the values of their controls 148 """ 149 currentState = {} 150 for stateName, state in reversed( self.states.items() ): 151 appState = {} 152 #The state has an application associated to it 153 if hasattr(state, 'app') and state.app: 154 for controlName, control in state.app.formControls.items(): 155 appState[controlName] = control.value 156 currentState[stateName] = appState 157 return currentState158 165
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Sep 11 13:06:35 2015 | http://epydoc.sourceforge.net |