diff --git a/schainpy/VERSION b/schainpy/VERSION index f015b5a..7ab056c 100644 --- a/schainpy/VERSION +++ b/schainpy/VERSION @@ -17,3 +17,7 @@ VERSIONS: 2.1.3.1: -GUI: every icon were resized -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file + +2.1.3.2: +-GUI: user interaction enhanced +-controller_api.py: Safe access to ControllerThead \ No newline at end of file diff --git a/schainpy/__init__.py b/schainpy/__init__.py index 2ff5957..60c5659 100644 --- a/schainpy/__init__.py +++ b/schainpy/__init__.py @@ -4,4 +4,4 @@ Created on Feb 7, 2012 @author $Author$ @version $Id$ ''' -__version__ = "2.1.3.1" \ No newline at end of file +__version__ = "2.1.3.2" \ No newline at end of file diff --git a/schainpy/controller.py b/schainpy/controller.py index a57e837..a1dd03d 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -6,13 +6,14 @@ from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring from xml.dom import minidom from model import * - -try: - from gevent import sleep -except: - from time import sleep +from time import sleep +import sys import ast +import traceback + +SCHAIN_MAIL = "miguel.urco@jro.igp.gob.pe" +EMAIL_SERVER = "jro.igp.gob.pe" def prettify(elem): """Return a pretty-printed XML string for the Element. @@ -603,7 +604,7 @@ class ProcUnitConf(): def run(self): - finalSts = False + is_ok = False for opConfObj in self.opConfObjList: @@ -619,9 +620,9 @@ class ProcUnitConf(): opName = opConfObj.name, opId = opConfObj.id, **kwargs) - finalSts = finalSts or sts + is_ok = is_ok or sts - return finalSts + return is_ok def close(self): @@ -763,7 +764,7 @@ class Project(): ELEMENTNAME = 'Project' - def __init__(self, control=None, dataq=None): + def __init__(self): self.id = None self.name = None @@ -771,14 +772,6 @@ class Project(): self.procUnitConfObjDict = {} - #global data_q - #data_q = dataq - - if control==None: - control = {'stop':False,'pause':False} - - self.control = control - def __getNewId(self): id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 @@ -979,12 +972,43 @@ class Project(): self.__connect(puObjIN, thisPUObj) + def isPaused(self): + return 0 + + def isStopped(self): + return 0 + + def runController(self): + """ + returns 0 when this process has been stopped, 1 otherwise + """ + + if self.isPaused(): + print "Process suspended" + + while True: + sleep(0.1) + + if not self.isPaused(): + break + + if self.isStopped(): + break + + print "Process reinitialized" + + if self.isStopped(): + print "Process stopped" + return 0 + + return 1 + def run(self): print - print "*"*50 + print "*"*60 print " Starting SIGNAL CHAIN PROCESSING " - print "*"*50 + print "*"*60 print keyList = self.procUnitConfObjDict.keys() @@ -992,35 +1016,40 @@ class Project(): while(True): - finalSts = False + is_ok = False for procKey in keyList: # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) procUnitConfObj = self.procUnitConfObjDict[procKey] - sts = procUnitConfObj.run() - finalSts = finalSts or sts + + message = "" + try: + sts = procUnitConfObj.run() + is_ok = is_ok or sts + except: + sleep(1) + err = traceback.format_exception(sys.exc_info()[0], + sys.exc_info()[1], + sys.exc_info()[2]) + + for thisLine in err: + message += thisLine + + print message +# self.sendReport(message) + sleep(0.1) + is_ok = False + + break #If every process unit finished so end process - if not(finalSts): + if not(is_ok): + print message print "Every process unit have finished" break - if self.control['pause']: - print "Process suspended" - - while True: - sleep(0.1) - - if not self.control['pause']: - break - - if self.control['stop']: - break - print "Process reinitialized" - - if self.control['stop']: -# print "Process stopped" + if not self.runController(): break #Closing every process @@ -1038,6 +1067,23 @@ class Project(): self.createObjects() self.connectObjects() self.run() + + def sendReport(self, message, subject="Error occurred in Signal Chain", email=SCHAIN_MAIL): + + import smtplib + + print subject + print "Sending report to %s ..." %email + + message = 'From: (Python Signal Chain API) ' + email + '\n' + \ + 'To: ' + email + '\n' + \ + 'Subject: ' + str(subject) + '\n' + \ + 'Content-type: text/html\n\n' + message + + server = smtplib.SMTP(EMAIL_SERVER) + server.sendmail(email.split(',')[0], + email.split(','), message) + server.quit() if __name__ == '__main__': diff --git a/schainpy/controller_api.py b/schainpy/controller_api.py index 4ff3520..39c871b 100644 --- a/schainpy/controller_api.py +++ b/schainpy/controller_api.py @@ -15,80 +15,49 @@ class ControllerThread(threading.Thread, Project): self.setDaemon(True) self.filename = filename + + self.lock = threading.Lock() self.control = {'stop':False, 'pause':False} def __del__(self): self.control['stop'] = True -# self.pause(1) -# self.wait() def stop(self): + + self.lock.acquire() + self.control['stop'] = True + self.lock.release() + def pause(self): + + self.lock.acquire() + self.control['pause'] = not(self.control['pause']) + paused = self.control['pause'] + + self.lock.release() - return self.control['pause'] + return paused - def __run(self): + def isPaused(self): - print - print "*"*40 - print " Starting SIGNAL CHAIN PROCESSING " - print "*"*40 - print + self.lock.acquire() + paused = self.control['pause'] + self.lock.release() - keyList = self.procUnitConfObjDict.keys() - keyList.sort() - - while(True): - - finalSts = False - #executed proc units - procUnitExecutedList = [] - - for procKey in keyList: -# print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) - - procUnitConfObj = self.procUnitConfObjDict[procKey] - - inputId = procUnitConfObj.getInputId() - - sts = procUnitConfObj.run() - finalSts = finalSts or sts - - procUnitExecutedList.append(procUnitConfObj.id) - - #If every process unit finished so end process - if not(finalSts): - print "Every process unit have finished" - break - - if self.control['pause']: - print "Process suspended" - - while True: - sleep(0.1) - - if not self.control['pause']: - break - - if self.control['stop']: - break - print "Process reinitialized" - - if self.control['stop']: -# print "Process stopped" - break - - #Closing every process - for procKey in keyList: - procUnitConfObj = self.procUnitConfObjDict[procKey] - procUnitConfObj.close() - - print "Process finished" + return paused + + def isStopped(self): + self.lock.acquire() + stopped = self.control['stop'] + self.lock.release() + + return stopped + def run(self): self.control['stop'] = False self.control['pause'] = False @@ -114,6 +83,8 @@ class ControllerQThread(QtCore.QThread, Project): Project.__init__(self) self.filename = filename + + self.lock = threading.Lock() self.control = {'stop':False, 'pause':False} def __del__(self): @@ -122,12 +93,42 @@ class ControllerQThread(QtCore.QThread, Project): self.wait() def stop(self): + + self.lock.acquire() + self.control['stop'] = True + self.lock.release() + def pause(self): + + self.lock.acquire() + self.control['pause'] = not(self.control['pause']) - + paused = self.control['pause'] + + self.lock.release() + + return paused + + def isPaused(self): + + self.lock.acquire() + paused = self.control['pause'] + self.lock.release() + + return paused + + def isStopped(self): + + self.lock.acquire() + stopped = self.control['stop'] + self.lock.release() + + return stopped + def run(self): + self.control['stop'] = False self.control['pause'] = False @@ -136,4 +137,5 @@ class ControllerQThread(QtCore.QThread, Project): self.connectObjects() self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) Project.run(self) - self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) \ No newline at end of file + self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) + \ No newline at end of file diff --git a/schainpy/gui/viewcontroller/basicwindow.py b/schainpy/gui/viewcontroller/basicwindow.py index bbd12e3..b6508c1 100644 --- a/schainpy/gui/viewcontroller/basicwindow.py +++ b/schainpy/gui/viewcontroller/basicwindow.py @@ -5892,6 +5892,10 @@ class ShowMeConsole(QtCore.QObject): def write(self, text): + if len(text) == 0: + self.textWritten.emit("\n") + return + if text[-1] == "\n": text = text[:-1] diff --git a/schainpy/gui/viewer/ui_mainwindow.py b/schainpy/gui/viewer/ui_mainwindow.py index 70182f6..470e1fc 100644 --- a/schainpy/gui/viewer/ui_mainwindow.py +++ b/schainpy/gui/viewer/ui_mainwindow.py @@ -287,10 +287,9 @@ class Ui_EnvWindow(object): def aboutEvent(self): title = "Signal Chain Processing Software v%s" %__version__ message = """ - Developed by Jicamarca Radio Observatory - Any comment to miguel.urco@jro.igp.gob.pe - """ - +Developed by Jicamarca Radio Observatory +Any comment to miguel.urco@jro.igp.gob.pe +""" QtGui.QMessageBox.about(self, title, message) diff --git a/schainpy/model/data/jroheaderIO.py b/schainpy/model/data/jroheaderIO.py index 4ccce96..65f841a 100644 --- a/schainpy/model/data/jroheaderIO.py +++ b/schainpy/model/data/jroheaderIO.py @@ -84,11 +84,14 @@ class Header(object): def printInfo(self): - print "#"*100 - print self.__class__.__name__.upper() - print "#"*100 + message = "#"*50 + "\n" + message += self.__class__.__name__.upper() + "\n" + message += "#"*50 + "\n" + for key in self.__dict__.keys(): - print "%s = %s" %(key, self.__dict__[key]) + message += "%s = %s" %(key, self.__dict__[key]) + "\n" + + print message class BasicHeader(Header): diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index afded75..97462a3 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -7,7 +7,7 @@ if 'linux' in sys.platform: matplotlib.use("TKAgg") if 'darwin' in sys.platform: - matplotlib.use('GTKAgg') + matplotlib.use('WXAgg') #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' import matplotlib.pyplot @@ -33,27 +33,27 @@ def createFigure(id, wintitle, width, height, facecolor="w", show=True): def closeFigure(show=False, fig=None): matplotlib.pyplot.ioff() - matplotlib.pyplot.pause(0.1) +# matplotlib.pyplot.pause(0.1) if show: matplotlib.pyplot.show() if fig != None: - matplotlib.pyplot.close(fig) - matplotlib.pyplot.pause(0.1) - matplotlib.pyplot.ion() + matplotlib.pyplot.close(fig.number) +# matplotlib.pyplot.pause(0.1) +# matplotlib.pyplot.ion() return matplotlib.pyplot.close("all") - matplotlib.pyplot.pause(0.1) - matplotlib.pyplot.ion() +# matplotlib.pyplot.pause(0.1) +# matplotlib.pyplot.ion() return def saveFigure(fig, filename): - matplotlib.pyplot.ioff() +# matplotlib.pyplot.ioff() fig.savefig(filename) - matplotlib.pyplot.ion() +# matplotlib.pyplot.ion() def setWinTitle(fig, title): diff --git a/setup.py b/setup.py index 7065dcc..0c52bce 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ setup(name="schainpy", install_requires=["numpy >= 1.6.0", "scipy >= 0.9.0", "h5py >= 2.0.1", + "wxpython >= 2.8", "matplotlib >= 1.0.0" ], ) \ No newline at end of file