@@ -1,137 +1,139 | |||||
1 | import threading |
|
1 | import threading | |
2 |
|
2 | |||
3 | from PyQt4 import QtCore |
|
3 | from PyQt4 import QtCore | |
4 | from PyQt4.QtCore import SIGNAL |
|
4 | from PyQt4.QtCore import SIGNAL | |
5 |
|
5 | |||
6 | from schainpy.controller import Project |
|
6 | from schainpy.controller import Project | |
7 |
|
7 | |||
8 | class ControllerThread(threading.Thread, Project): |
|
8 | class ControllerThread(threading.Thread, Project): | |
9 |
|
9 | |||
10 | def __init__(self, filename): |
|
10 | def __init__(self, filename): | |
11 |
|
11 | |||
12 | threading.Thread.__init__(self) |
|
12 | threading.Thread.__init__(self) | |
13 | Project.__init__(self) |
|
13 | Project.__init__(self) | |
14 |
|
14 | |||
15 | self.setDaemon(True) |
|
15 | self.setDaemon(True) | |
16 |
|
16 | |||
17 | self.filename = filename |
|
17 | self.filename = filename | |
18 | self.control = {'stop':False, 'pause':False} |
|
18 | self.control = {'stop':False, 'pause':False} | |
19 |
|
19 | |||
20 | def __del__(self): |
|
20 | def __del__(self): | |
21 |
|
21 | |||
22 | self.control['stop'] = True |
|
22 | self.control['stop'] = True | |
23 | # self.pause(1) |
|
23 | # self.pause(1) | |
24 | # self.wait() |
|
24 | # self.wait() | |
25 |
|
25 | |||
26 | def stop(self): |
|
26 | def stop(self): | |
27 | self.control['stop'] = True |
|
27 | self.control['stop'] = True | |
28 |
|
28 | |||
29 | def pause(self): |
|
29 | def pause(self): | |
30 | self.control['pause'] = not(self.control['pause']) |
|
30 | self.control['pause'] = not(self.control['pause']) | |
31 |
|
31 | |||
|
32 | return self.control['pause'] | |||
|
33 | ||||
32 | def __run(self): |
|
34 | def __run(self): | |
33 |
|
35 | |||
34 |
|
36 | |||
35 | print "*"*40 |
|
37 | print "*"*40 | |
36 | print " Starting SIGNAL CHAIN PROCESSING " |
|
38 | print " Starting SIGNAL CHAIN PROCESSING " | |
37 | print "*"*40 |
|
39 | print "*"*40 | |
38 |
|
40 | |||
39 |
|
41 | |||
40 | keyList = self.procUnitConfObjDict.keys() |
|
42 | keyList = self.procUnitConfObjDict.keys() | |
41 | keyList.sort() |
|
43 | keyList.sort() | |
42 |
|
44 | |||
43 | while(True): |
|
45 | while(True): | |
44 |
|
46 | |||
45 | finalSts = False |
|
47 | finalSts = False | |
46 | #executed proc units |
|
48 | #executed proc units | |
47 | procUnitExecutedList = [] |
|
49 | procUnitExecutedList = [] | |
48 |
|
50 | |||
49 | for procKey in keyList: |
|
51 | for procKey in keyList: | |
50 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
52 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
51 |
|
53 | |||
52 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
54 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
53 |
|
55 | |||
54 | inputId = procUnitConfObj.getInputId() |
|
56 | inputId = procUnitConfObj.getInputId() | |
55 |
|
57 | |||
56 | sts = procUnitConfObj.run() |
|
58 | sts = procUnitConfObj.run() | |
57 | finalSts = finalSts or sts |
|
59 | finalSts = finalSts or sts | |
58 |
|
60 | |||
59 | procUnitExecutedList.append(procUnitConfObj.id) |
|
61 | procUnitExecutedList.append(procUnitConfObj.id) | |
60 |
|
62 | |||
61 | #If every process unit finished so end process |
|
63 | #If every process unit finished so end process | |
62 | if not(finalSts): |
|
64 | if not(finalSts): | |
63 | print "Every process unit have finished" |
|
65 | print "Every process unit have finished" | |
64 | break |
|
66 | break | |
65 |
|
67 | |||
66 | if self.control['pause']: |
|
68 | if self.control['pause']: | |
67 | print "Process suspended" |
|
69 | print "Process suspended" | |
68 |
|
70 | |||
69 | while True: |
|
71 | while True: | |
70 | sleep(0.1) |
|
72 | sleep(0.1) | |
71 |
|
73 | |||
72 | if not self.control['pause']: |
|
74 | if not self.control['pause']: | |
73 | break |
|
75 | break | |
74 |
|
76 | |||
75 | if self.control['stop']: |
|
77 | if self.control['stop']: | |
76 | break |
|
78 | break | |
77 | print "Process reinitialized" |
|
79 | print "Process reinitialized" | |
78 |
|
80 | |||
79 | if self.control['stop']: |
|
81 | if self.control['stop']: | |
80 | # print "Process stopped" |
|
82 | # print "Process stopped" | |
81 | break |
|
83 | break | |
82 |
|
84 | |||
83 | #Closing every process |
|
85 | #Closing every process | |
84 | for procKey in keyList: |
|
86 | for procKey in keyList: | |
85 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
87 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
86 | procUnitConfObj.close() |
|
88 | procUnitConfObj.close() | |
87 |
|
89 | |||
88 | print "Process finished" |
|
90 | print "Process finished" | |
89 |
|
91 | |||
90 | def run(self): |
|
92 | def run(self): | |
91 | self.control['stop'] = False |
|
93 | self.control['stop'] = False | |
92 | self.control['pause'] = False |
|
94 | self.control['pause'] = False | |
93 |
|
95 | |||
94 | self.readXml(self.filename) |
|
96 | self.readXml(self.filename) | |
95 | self.createObjects() |
|
97 | self.createObjects() | |
96 | self.connectObjects() |
|
98 | self.connectObjects() | |
97 | Project.run(self) |
|
99 | Project.run(self) | |
98 |
|
100 | |||
99 | def isRunning(self): |
|
101 | def isRunning(self): | |
100 |
|
102 | |||
101 | return self.is_alive() |
|
103 | return self.is_alive() | |
102 |
|
104 | |||
103 | def isFinished(self): |
|
105 | def isFinished(self): | |
104 |
|
106 | |||
105 | return not self.is_alive() |
|
107 | return not self.is_alive() | |
106 |
|
108 | |||
107 | class ControllerQThread(QtCore.QThread, Project): |
|
109 | class ControllerQThread(QtCore.QThread, Project): | |
108 |
|
110 | |||
109 | def __init__(self, filename): |
|
111 | def __init__(self, filename): | |
110 |
|
112 | |||
111 | QtCore.QThread.__init__(self) |
|
113 | QtCore.QThread.__init__(self) | |
112 | Project.__init__(self) |
|
114 | Project.__init__(self) | |
113 |
|
115 | |||
114 | self.filename = filename |
|
116 | self.filename = filename | |
115 | self.control = {'stop':False, 'pause':False} |
|
117 | self.control = {'stop':False, 'pause':False} | |
116 |
|
118 | |||
117 | def __del__(self): |
|
119 | def __del__(self): | |
118 |
|
120 | |||
119 | self.control['stop'] = True |
|
121 | self.control['stop'] = True | |
120 | self.wait() |
|
122 | self.wait() | |
121 |
|
123 | |||
122 | def stop(self): |
|
124 | def stop(self): | |
123 | self.control['stop'] = True |
|
125 | self.control['stop'] = True | |
124 |
|
126 | |||
125 | def pause(self): |
|
127 | def pause(self): | |
126 | self.control['pause'] = not(self.control['pause']) |
|
128 | self.control['pause'] = not(self.control['pause']) | |
127 |
|
129 | |||
128 | def run(self): |
|
130 | def run(self): | |
129 | self.control['stop'] = False |
|
131 | self.control['stop'] = False | |
130 | self.control['pause'] = False |
|
132 | self.control['pause'] = False | |
131 |
|
133 | |||
132 | self.readXml(self.filename) |
|
134 | self.readXml(self.filename) | |
133 | self.createObjects() |
|
135 | self.createObjects() | |
134 | self.connectObjects() |
|
136 | self.connectObjects() | |
135 | self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) |
|
137 | self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) | |
136 | Project.run(self) |
|
138 | Project.run(self) | |
137 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) No newline at end of file |
|
139 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
General Comments 0
You need to be logged in to leave comments.
Login now