| Home | Trees | Indices | Help |
|
|---|
|
|
1 import sys, glob, os 2 from PyQt4 import uic 3 from PyQt4 import QtGui, QtCore 4 import pyforms.Utils.tools as tools, time 5 from pyforms.gui.BaseWidget import BaseWidget 6 7 from pyStateMachine.States.State import State, EndState 8 from pyStateMachine.StateMachineControllers.StatesController import StatesController12 def go2decorator(func): 13 def func_wrapper(self, inVar): return func(self, inVar) 14 15 func_wrapper.trueParms = trueParms 16 func_wrapper.falseParms = falseParms 17 func_wrapper.go2StateTrue = true 18 func_wrapper.go2StateFalse = false 19 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]) 20 return func_wrapper21 return go2decorator 22 34 35 @property 37 38 @app.setter 40 41 44 45 @property 4751149 16153 BaseWidget.__init__(self, title) 54 StatesController.__init__(self, self.STATES) 55 for stateName, state in self.states.items(): 56 if hasattr(state, 'init'): state.init()57 58 59 6062 tabs = QtGui.QTabWidget(self) 63 self.layout().addWidget(tabs) 64 self.layout().setMargin(0) 65 self.layout().setSpacing(0) 66 67 # Generates and load the State machine graph 68 self.exportGraph() 69 self._image = QtGui.QLabel() 70 self._image.setPixmap(QtGui.QPixmap('stateMachine.png')) 71 scrollArea = QtGui.QScrollArea(); 72 scrollArea.setWidget(self._image); 73 tabs.addTab(scrollArea, 'State Machine Diagram') 74 75 # Load the applications 76 for fromStateName, state in reversed( self.states.items() ): 77 if hasattr(state, 'app') and state.app: 78 #Override the original application formset if the state has a new one 79 state.initForm(); 80 # Add the application form to a new Tab 81 tabs.addTab(state.form, fromStateName)82 83 84 85 8688 """ 89 Iterate states - each call go to another level 90 """ 91 if len(self._waitingStates)>0: 92 statesOutputs = [] 93 print self._waitingStates 94 95 #First run all the pending states 96 for fromStateName, toStateName, inputParam in self._waitingStates: 97 state = self._states[toStateName] 98 copyOfCurrentState = dict(self._currentState) 99 100 if isinstance(state, EndState): executionDetails = (toStateName, state, inputParam ) 101 else: 102 p = state.enter(inputParam, copyOfCurrentState) 103 state.execute() 104 outParam = state.leave(p, copyOfCurrentState) 105 executionDetails = (toStateName, state, outParam ) 106 107 statesOutputs.append( executionDetails ) 108 109 #Check the events of each exectuted state: 110 for stateName, state, output in statesOutputs: 111 #Remove the exectued state from the waiting queue 112 self._waitingStates.pop(0) 113 #Check each event 114 for e in state.events: 115 #Select the next state to go 116 go2State = e.go2StateTrue if e(state, output) else e.go2StateFalse 117 #In case the state is None, it stops the state execution 118 if go2State!=None: self._waitingStates.append( [stateName, go2State, output] ) 119 else: self._waitingStates.append( [stateName, 'EndState', output] ) 120 121 "Save the currentState of the iteration" 122 self._currentState = self.__returnCurrentStatesValues() 123 else: 124 print("State machine ended")125 126 127129 # Initiate the parameters set by the user 130 self._currentState = self.__returnCurrentStatesValues() 131 132 # Iterate the states execution 133 while not self.ended: self.iterateStates()134 135137 """ 138 Iterate all the states and save the values of their controls 139 """ 140 currentState = {} 141 for stateName, state in reversed( self.states.items() ): 142 appState = {} 143 #The state has an application associated to it 144 if hasattr(state, 'app') and state.app: 145 for controlName, control in state.app.formControls.items(): 146 appState[controlName] = control.value 147 currentState[stateName] = appState 148 return currentState
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Sep 11 13:06:34 2015 | http://epydoc.sourceforge.net |