@@ -17,3 +17,7 VERSIONS: | |||
|
17 | 17 | 2.1.3.1: |
|
18 | 18 | -GUI: every icon were resized |
|
19 | 19 | -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file |
|
20 | ||
|
21 | 2.1.3.2: | |
|
22 | -GUI: user interaction enhanced | |
|
23 | -controller_api.py: Safe access to ControllerThead No newline at end of file |
@@ -4,4 +4,4 Created on Feb 7, 2012 | |||
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 |
__version__ = "2.1.3. |
|
|
7 | __version__ = "2.1.3.2" No newline at end of file |
@@ -6,13 +6,14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |||
|
6 | 6 | from xml.dom import minidom |
|
7 | 7 | |
|
8 | 8 | from model import * |
|
9 | ||
|
10 | try: | |
|
11 | from gevent import sleep | |
|
12 | except: | |
|
13 | from time import sleep | |
|
9 | from time import sleep | |
|
14 | 10 | |
|
11 | import sys | |
|
15 | 12 | import ast |
|
13 | import traceback | |
|
14 | ||
|
15 | SCHAIN_MAIL = "miguel.urco@jro.igp.gob.pe" | |
|
16 | EMAIL_SERVER = "jro.igp.gob.pe" | |
|
16 | 17 | |
|
17 | 18 | def prettify(elem): |
|
18 | 19 | """Return a pretty-printed XML string for the Element. |
@@ -603,7 +604,7 class ProcUnitConf(): | |||
|
603 | 604 | |
|
604 | 605 | def run(self): |
|
605 | 606 | |
|
606 |
|
|
|
607 | is_ok = False | |
|
607 | 608 | |
|
608 | 609 | for opConfObj in self.opConfObjList: |
|
609 | 610 | |
@@ -619,9 +620,9 class ProcUnitConf(): | |||
|
619 | 620 | opName = opConfObj.name, |
|
620 | 621 | opId = opConfObj.id, |
|
621 | 622 | **kwargs) |
|
622 |
|
|
|
623 | is_ok = is_ok or sts | |
|
623 | 624 | |
|
624 |
return |
|
|
625 | return is_ok | |
|
625 | 626 | |
|
626 | 627 | def close(self): |
|
627 | 628 | |
@@ -763,7 +764,7 class Project(): | |||
|
763 | 764 | |
|
764 | 765 | ELEMENTNAME = 'Project' |
|
765 | 766 | |
|
766 |
def __init__(self |
|
|
767 | def __init__(self): | |
|
767 | 768 | |
|
768 | 769 | self.id = None |
|
769 | 770 | self.name = None |
@@ -771,14 +772,6 class Project(): | |||
|
771 | 772 | |
|
772 | 773 | self.procUnitConfObjDict = {} |
|
773 | 774 | |
|
774 | #global data_q | |
|
775 | #data_q = dataq | |
|
776 | ||
|
777 | if control==None: | |
|
778 | control = {'stop':False,'pause':False} | |
|
779 | ||
|
780 | self.control = control | |
|
781 | ||
|
782 | 775 | def __getNewId(self): |
|
783 | 776 | |
|
784 | 777 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
@@ -979,12 +972,43 class Project(): | |||
|
979 | 972 | |
|
980 | 973 | self.__connect(puObjIN, thisPUObj) |
|
981 | 974 | |
|
975 | def isPaused(self): | |
|
976 | return 0 | |
|
977 | ||
|
978 | def isStopped(self): | |
|
979 | return 0 | |
|
980 | ||
|
981 | def runController(self): | |
|
982 | """ | |
|
983 | returns 0 when this process has been stopped, 1 otherwise | |
|
984 | """ | |
|
985 | ||
|
986 | if self.isPaused(): | |
|
987 | print "Process suspended" | |
|
988 | ||
|
989 | while True: | |
|
990 | sleep(0.1) | |
|
991 | ||
|
992 | if not self.isPaused(): | |
|
993 | break | |
|
994 | ||
|
995 | if self.isStopped(): | |
|
996 | break | |
|
997 | ||
|
998 | print "Process reinitialized" | |
|
999 | ||
|
1000 | if self.isStopped(): | |
|
1001 | print "Process stopped" | |
|
1002 | return 0 | |
|
1003 | ||
|
1004 | return 1 | |
|
1005 | ||
|
982 | 1006 | def run(self): |
|
983 | 1007 | |
|
984 | 1008 | |
|
985 |
print "*"* |
|
|
1009 | print "*"*60 | |
|
986 | 1010 | print " Starting SIGNAL CHAIN PROCESSING " |
|
987 |
print "*"* |
|
|
1011 | print "*"*60 | |
|
988 | 1012 | |
|
989 | 1013 | |
|
990 | 1014 | keyList = self.procUnitConfObjDict.keys() |
@@ -992,35 +1016,40 class Project(): | |||
|
992 | 1016 | |
|
993 | 1017 | while(True): |
|
994 | 1018 | |
|
995 |
|
|
|
1019 | is_ok = False | |
|
996 | 1020 | |
|
997 | 1021 | for procKey in keyList: |
|
998 | 1022 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
999 | 1023 | |
|
1000 | 1024 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1001 | sts = procUnitConfObj.run() | |
|
1002 | finalSts = finalSts or sts | |
|
1025 | ||
|
1026 | message = "" | |
|
1027 | try: | |
|
1028 | sts = procUnitConfObj.run() | |
|
1029 | is_ok = is_ok or sts | |
|
1030 | except: | |
|
1031 | sleep(1) | |
|
1032 | err = traceback.format_exception(sys.exc_info()[0], | |
|
1033 | sys.exc_info()[1], | |
|
1034 | sys.exc_info()[2]) | |
|
1035 | ||
|
1036 | for thisLine in err: | |
|
1037 | message += thisLine | |
|
1038 | ||
|
1039 | print message | |
|
1040 | # self.sendReport(message) | |
|
1041 | sleep(0.1) | |
|
1042 | is_ok = False | |
|
1043 | ||
|
1044 | break | |
|
1003 | 1045 | |
|
1004 | 1046 | #If every process unit finished so end process |
|
1005 |
if not( |
|
|
1047 | if not(is_ok): | |
|
1048 | print message | |
|
1006 | 1049 | print "Every process unit have finished" |
|
1007 | 1050 | break |
|
1008 | 1051 | |
|
1009 |
if self. |
|
|
1010 | print "Process suspended" | |
|
1011 | ||
|
1012 | while True: | |
|
1013 | sleep(0.1) | |
|
1014 | ||
|
1015 | if not self.control['pause']: | |
|
1016 | break | |
|
1017 | ||
|
1018 | if self.control['stop']: | |
|
1019 | break | |
|
1020 | print "Process reinitialized" | |
|
1021 | ||
|
1022 | if self.control['stop']: | |
|
1023 | # print "Process stopped" | |
|
1052 | if not self.runController(): | |
|
1024 | 1053 | break |
|
1025 | 1054 | |
|
1026 | 1055 | #Closing every process |
@@ -1038,6 +1067,23 class Project(): | |||
|
1038 | 1067 | self.createObjects() |
|
1039 | 1068 | self.connectObjects() |
|
1040 | 1069 | self.run() |
|
1070 | ||
|
1071 | def sendReport(self, message, subject="Error occurred in Signal Chain", email=SCHAIN_MAIL): | |
|
1072 | ||
|
1073 | import smtplib | |
|
1074 | ||
|
1075 | print subject | |
|
1076 | print "Sending report to %s ..." %email | |
|
1077 | ||
|
1078 | message = 'From: (Python Signal Chain API) ' + email + '\n' + \ | |
|
1079 | 'To: ' + email + '\n' + \ | |
|
1080 | 'Subject: ' + str(subject) + '\n' + \ | |
|
1081 | 'Content-type: text/html\n\n' + message | |
|
1082 | ||
|
1083 | server = smtplib.SMTP(EMAIL_SERVER) | |
|
1084 | server.sendmail(email.split(',')[0], | |
|
1085 | email.split(','), message) | |
|
1086 | server.quit() | |
|
1041 | 1087 | |
|
1042 | 1088 | if __name__ == '__main__': |
|
1043 | 1089 |
@@ -15,80 +15,49 class ControllerThread(threading.Thread, Project): | |||
|
15 | 15 | self.setDaemon(True) |
|
16 | 16 | |
|
17 | 17 | self.filename = filename |
|
18 | ||
|
19 | self.lock = threading.Lock() | |
|
18 | 20 | self.control = {'stop':False, 'pause':False} |
|
19 | 21 | |
|
20 | 22 | def __del__(self): |
|
21 | 23 | |
|
22 | 24 | self.control['stop'] = True |
|
23 | # self.pause(1) | |
|
24 | # self.wait() | |
|
25 | 25 | |
|
26 | 26 | def stop(self): |
|
27 | ||
|
28 | self.lock.acquire() | |
|
29 | ||
|
27 | 30 | self.control['stop'] = True |
|
28 | 31 | |
|
32 | self.lock.release() | |
|
33 | ||
|
29 | 34 | def pause(self): |
|
35 | ||
|
36 | self.lock.acquire() | |
|
37 | ||
|
30 | 38 | self.control['pause'] = not(self.control['pause']) |
|
39 | paused = self.control['pause'] | |
|
40 | ||
|
41 | self.lock.release() | |
|
31 | 42 | |
|
32 |
return |
|
|
43 | return paused | |
|
33 | 44 | |
|
34 |
def |
|
|
45 | def isPaused(self): | |
|
35 | 46 | |
|
36 | ||
|
37 | print "*"*40 | |
|
38 | print " Starting SIGNAL CHAIN PROCESSING " | |
|
39 | print "*"*40 | |
|
40 | ||
|
47 | self.lock.acquire() | |
|
48 | paused = self.control['pause'] | |
|
49 | self.lock.release() | |
|
41 | 50 | |
|
42 | keyList = self.procUnitConfObjDict.keys() | |
|
43 | keyList.sort() | |
|
44 | ||
|
45 | while(True): | |
|
46 | ||
|
47 | finalSts = False | |
|
48 | #executed proc units | |
|
49 | procUnitExecutedList = [] | |
|
50 | ||
|
51 | for procKey in keyList: | |
|
52 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
|
53 | ||
|
54 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
|
55 | ||
|
56 | inputId = procUnitConfObj.getInputId() | |
|
57 | ||
|
58 | sts = procUnitConfObj.run() | |
|
59 | finalSts = finalSts or sts | |
|
60 | ||
|
61 | procUnitExecutedList.append(procUnitConfObj.id) | |
|
62 | ||
|
63 | #If every process unit finished so end process | |
|
64 | if not(finalSts): | |
|
65 | print "Every process unit have finished" | |
|
66 | break | |
|
67 | ||
|
68 | if self.control['pause']: | |
|
69 | print "Process suspended" | |
|
70 | ||
|
71 | while True: | |
|
72 | sleep(0.1) | |
|
73 | ||
|
74 | if not self.control['pause']: | |
|
75 | break | |
|
76 | ||
|
77 | if self.control['stop']: | |
|
78 | break | |
|
79 | print "Process reinitialized" | |
|
80 | ||
|
81 | if self.control['stop']: | |
|
82 | # print "Process stopped" | |
|
83 | break | |
|
84 | ||
|
85 | #Closing every process | |
|
86 | for procKey in keyList: | |
|
87 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
|
88 | procUnitConfObj.close() | |
|
89 | ||
|
90 | print "Process finished" | |
|
51 | return paused | |
|
52 | ||
|
53 | def isStopped(self): | |
|
91 | 54 | |
|
55 | self.lock.acquire() | |
|
56 | stopped = self.control['stop'] | |
|
57 | self.lock.release() | |
|
58 | ||
|
59 | return stopped | |
|
60 | ||
|
92 | 61 | def run(self): |
|
93 | 62 | self.control['stop'] = False |
|
94 | 63 | self.control['pause'] = False |
@@ -114,6 +83,8 class ControllerQThread(QtCore.QThread, Project): | |||
|
114 | 83 | Project.__init__(self) |
|
115 | 84 | |
|
116 | 85 | self.filename = filename |
|
86 | ||
|
87 | self.lock = threading.Lock() | |
|
117 | 88 | self.control = {'stop':False, 'pause':False} |
|
118 | 89 | |
|
119 | 90 | def __del__(self): |
@@ -122,12 +93,42 class ControllerQThread(QtCore.QThread, Project): | |||
|
122 | 93 | self.wait() |
|
123 | 94 | |
|
124 | 95 | def stop(self): |
|
96 | ||
|
97 | self.lock.acquire() | |
|
98 | ||
|
125 | 99 | self.control['stop'] = True |
|
126 | 100 | |
|
101 | self.lock.release() | |
|
102 | ||
|
127 | 103 | def pause(self): |
|
104 | ||
|
105 | self.lock.acquire() | |
|
106 | ||
|
128 | 107 | self.control['pause'] = not(self.control['pause']) |
|
129 | ||
|
108 | paused = self.control['pause'] | |
|
109 | ||
|
110 | self.lock.release() | |
|
111 | ||
|
112 | return paused | |
|
113 | ||
|
114 | def isPaused(self): | |
|
115 | ||
|
116 | self.lock.acquire() | |
|
117 | paused = self.control['pause'] | |
|
118 | self.lock.release() | |
|
119 | ||
|
120 | return paused | |
|
121 | ||
|
122 | def isStopped(self): | |
|
123 | ||
|
124 | self.lock.acquire() | |
|
125 | stopped = self.control['stop'] | |
|
126 | self.lock.release() | |
|
127 | ||
|
128 | return stopped | |
|
129 | ||
|
130 | 130 | def run(self): |
|
131 | ||
|
131 | 132 | self.control['stop'] = False |
|
132 | 133 | self.control['pause'] = False |
|
133 | 134 | |
@@ -136,4 +137,5 class ControllerQThread(QtCore.QThread, Project): | |||
|
136 | 137 | self.connectObjects() |
|
137 | 138 | self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) |
|
138 | 139 | Project.run(self) |
|
139 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) No newline at end of file | |
|
140 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) | |
|
141 | No newline at end of file |
@@ -5892,6 +5892,10 class ShowMeConsole(QtCore.QObject): | |||
|
5892 | 5892 | |
|
5893 | 5893 | def write(self, text): |
|
5894 | 5894 | |
|
5895 | if len(text) == 0: | |
|
5896 | self.textWritten.emit("\n") | |
|
5897 | return | |
|
5898 | ||
|
5895 | 5899 | if text[-1] == "\n": |
|
5896 | 5900 | text = text[:-1] |
|
5897 | 5901 |
@@ -287,10 +287,9 class Ui_EnvWindow(object): | |||
|
287 | 287 | def aboutEvent(self): |
|
288 | 288 | title = "Signal Chain Processing Software v%s" %__version__ |
|
289 | 289 | message = """ |
|
290 |
|
|
|
291 |
|
|
|
292 | """ | |
|
293 | ||
|
290 | Developed by Jicamarca Radio Observatory | |
|
291 | Any comment to miguel.urco@jro.igp.gob.pe | |
|
292 | """ | |
|
294 | 293 | QtGui.QMessageBox.about(self, title, message) |
|
295 | 294 | |
|
296 | 295 |
@@ -84,11 +84,14 class Header(object): | |||
|
84 | 84 | |
|
85 | 85 | def printInfo(self): |
|
86 | 86 | |
|
87 | print "#"*100 | |
|
88 |
|
|
|
89 | print "#"*100 | |
|
87 | message = "#"*50 + "\n" | |
|
88 | message += self.__class__.__name__.upper() + "\n" | |
|
89 | message += "#"*50 + "\n" | |
|
90 | ||
|
90 | 91 | for key in self.__dict__.keys(): |
|
91 |
|
|
|
92 | message += "%s = %s" %(key, self.__dict__[key]) + "\n" | |
|
93 | ||
|
94 | print message | |
|
92 | 95 | |
|
93 | 96 | class BasicHeader(Header): |
|
94 | 97 |
@@ -7,7 +7,7 if 'linux' in sys.platform: | |||
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 |
matplotlib.use(' |
|
|
10 | matplotlib.use('WXAgg') | |
|
11 | 11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
@@ -33,27 +33,27 def createFigure(id, wintitle, width, height, facecolor="w", show=True): | |||
|
33 | 33 | def closeFigure(show=False, fig=None): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | matplotlib.pyplot.pause(0.1) | |
|
36 | # matplotlib.pyplot.pause(0.1) | |
|
37 | 37 | |
|
38 | 38 | if show: |
|
39 | 39 | matplotlib.pyplot.show() |
|
40 | 40 | |
|
41 | 41 | if fig != None: |
|
42 | matplotlib.pyplot.close(fig) | |
|
43 | matplotlib.pyplot.pause(0.1) | |
|
44 | matplotlib.pyplot.ion() | |
|
42 | matplotlib.pyplot.close(fig.number) | |
|
43 | # matplotlib.pyplot.pause(0.1) | |
|
44 | # matplotlib.pyplot.ion() | |
|
45 | 45 | return |
|
46 | 46 | |
|
47 | 47 | matplotlib.pyplot.close("all") |
|
48 | matplotlib.pyplot.pause(0.1) | |
|
49 | matplotlib.pyplot.ion() | |
|
48 | # matplotlib.pyplot.pause(0.1) | |
|
49 | # matplotlib.pyplot.ion() | |
|
50 | 50 | return |
|
51 | 51 | |
|
52 | 52 | def saveFigure(fig, filename): |
|
53 | 53 | |
|
54 | matplotlib.pyplot.ioff() | |
|
54 | # matplotlib.pyplot.ioff() | |
|
55 | 55 | fig.savefig(filename) |
|
56 | matplotlib.pyplot.ion() | |
|
56 | # matplotlib.pyplot.ion() | |
|
57 | 57 | |
|
58 | 58 | def setWinTitle(fig, title): |
|
59 | 59 |
General Comments 0
You need to be logged in to leave comments.
Login now