diff --git a/schainpy/controller.py b/schainpy/controller.py index a8fd3ea..a76b457 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -823,7 +823,7 @@ class Project(): ELEMENTNAME = 'Project' - __plotterQueue = None + plotterQueue = None def __init__(self, plotter_queue=None): @@ -831,7 +831,7 @@ class Project(): self.name = None self.description = None - self.__plotterQueue = plotter_queue + self.plotterQueue = plotter_queue self.procUnitConfObjDict = {} @@ -1046,7 +1046,7 @@ class Project(): def createObjects(self): for procUnitConfObj in self.procUnitConfObjDict.values(): - procUnitConfObj.createObjects(self.__plotterQueue) + procUnitConfObj.createObjects(self.plotterQueue) def __connect(self, objIN, thisObj): @@ -1143,35 +1143,15 @@ class Project(): def setPlotterQueue(self, plotter_queue): - self.__plotterQueue = plotter_queue - + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" + def getPlotterQueue(self): - return self.__plotterQueue - - def useExternalPlotManager(self): - - plotterList = ['Scope', - 'SpectraPlot', 'RTIPlot', - 'CrossSpectraPlot', 'CoherenceMap', - 'PowerProfilePlot', 'Noise', 'BeaconPhase', - 'CorrelationPlot', - 'SpectraHeisScope','RTIfromSpectraHeis'] + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" + + def useExternalPlotter(self): - for thisPUConfObj in self.procUnitConfObjDict.values(): - - inputId = thisPUConfObj.getInputId() - - if int(inputId) == 0: - continue - - for thisOpObj in thisPUConfObj.getOperationObjList(): - - if thisOpObj.type == "self": - continue - - if thisOpObj.name in plotterList: - thisOpObj.type = "plotter" + raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" def run(self): diff --git a/schainpy/controller_api.py b/schainpy/controller_api.py index 9fdc32b..86dfa22 100644 --- a/schainpy/controller_api.py +++ b/schainpy/controller_api.py @@ -1,6 +1,8 @@ import threading +import Queue from schainpy.controller import Project +from schainpy.model.graphics.jroplotter import PlotManager class ControllerThread(threading.Thread, Project): @@ -71,6 +73,48 @@ class ControllerThread(threading.Thread, Project): return not self.is_alive() + def setPlotters(self): + + plotterList = ['Scope', + 'SpectraPlot', 'RTIPlot', + 'CrossSpectraPlot', 'CoherenceMap', + 'PowerProfilePlot', 'Noise', 'BeaconPhase', + 'CorrelationPlot', + 'SpectraHeisScope','RTIfromSpectraHeis'] + + for thisPUConfObj in self.procUnitConfObjDict.values(): + + inputId = thisPUConfObj.getInputId() + + if int(inputId) == 0: + continue + + for thisOpObj in thisPUConfObj.getOperationObjList(): + + if thisOpObj.type == "self": + continue + + if thisOpObj.name in plotterList: + thisOpObj.type = "plotter" + + def setPlotterQueue(self, plotter_queue): + + self.plotterQueue = plotter_queue + + def getPlotterQueue(self): + + return self.plotterQueue + + def useExternalPlotter(self): + + self.plotterQueue = Queue.Queue(10) + self.setPlotters() + + plotManagerObj = PlotManager(self.plotterQueue) + plotManagerObj.setController(self) + + return plotManagerObj + # from PyQt4 import QtCore # from PyQt4.QtCore import SIGNAL # diff --git a/schainpy/gui/viewcontroller/basicwindow.py b/schainpy/gui/viewcontroller/basicwindow.py index 93c342f..4329a8e 100644 --- a/schainpy/gui/viewcontroller/basicwindow.py +++ b/schainpy/gui/viewcontroller/basicwindow.py @@ -4685,16 +4685,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): def use_plotmanager(self, controllerThread): - plotter_queue = Queue(10) - controllerThread.setPlotterQueue(plotter_queue) - controllerThread.useExternalPlotManager() - - self.plotManager = PlotManager(plotter_queue) + self.plotManager = controllerThread.useExternalPlotter() self.plot_timer = QtCore.QTimer() self.plot_timer.timeout.connect(self.on_plotmanager_timer) self.plot_timer.start(10) - + def on_plotmanager_timer(self): if not self.plotManager: @@ -4750,11 +4746,9 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.threadStarted = False self.controllerThread.stop() + self.plot_timer.stop() - while not self.plotManager.isEmpty(): - self.plotManager.run() - - self.plotManager.close() + self.plotManager.join() self.plotManager = None while self.controllerThread.isRunning(): diff --git a/schainpy/model/graphics/jroplotter.py b/schainpy/model/graphics/jroplotter.py index b5a2142..574ebfc 100644 --- a/schainpy/model/graphics/jroplotter.py +++ b/schainpy/model/graphics/jroplotter.py @@ -68,6 +68,7 @@ class Plotter(Operation): # class PlotManager(Thread): class PlotManager(): __stop = False + controllerThreadObj = None def __init__(self, plotter_queue): @@ -96,6 +97,9 @@ class PlotManager(): for i in range(n): + if self.__queue.empty(): + break + serial_data = self.__queue.get() self.__queue.task_done() @@ -136,4 +140,28 @@ class PlotManager(): plotter.close() self.__lock.release() - \ No newline at end of file + + def setController(self, controllerThreadObj): + + self.controllerThreadObj = controllerThreadObj + + def start(self): + + if not self.controllerThreadObj.isRunning(): + raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method" + + self.join() + + def join(self): + + #Execute plotter while controller is running + while self.controllerThreadObj.isRunning(): + self.run() + + self.controllerThreadObj.stop() + + #Wait until plotter queue is empty + while not self.isEmpty(): + self.run() + + self.close() \ No newline at end of file