Commit ce824beb authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix plot manager

parent 5a8ea715
......@@ -204,6 +204,8 @@ class asn1Editor(QTreeView):
msc = Signal(unicode, unicode)
# Whenever a new TM is received, the new_tm signal is emitted
new_tm = Signal()
# Use a signal to tell the plots (matplotlib) to update
plot_refresh = Signal()
def __init__(self, parent=None):
super(asn1Editor, self).__init__(parent)
......@@ -589,7 +591,8 @@ class asn1Editor(QTreeView):
self.plotterBackend.updatePlot(plotter, float(value))
self.hideUnusedFields(root, True, row=row)
if self.plotterBackend is not None:
self.plotterBackend.refresh()
self.plot_refresh.emit()
#self.plotterBackend.refresh()
# Inform the thread to update the tree (expand all branches)
self.expandTree.emit()
......
......@@ -423,6 +423,9 @@ def gui():
editor.setAsn1Model(datamodel.tm[editor.objectName()])
g_tmPool[encoder_backend.tmId] = editor
editor.setPlotterBackend(plotter)
# Connect the plot_refresh signal from editors to the plot manager
# (to make sure only one thread accesses it)
editor.plot_refresh.connect(plotter.refresh)
for button in myButtons:
if button.objectName() == 'plotButton':
myMenu = QMenu()
......
......@@ -20,9 +20,10 @@ import speedometer
from tasteplot import TastePlot
from PySide.QtGui import QAction
from PySide.QtCore import QObject, Slot
class plot:
class plot(object):
def __init__(self, handle):
self.handle = handle
# Gnuplot pid
......@@ -39,7 +40,7 @@ class plot:
self.pending_values = []
class PlotManager:
class PlotManager(QObject):
''' Manage a pool of plotters '''
def __init__(self, parent=None, log=None):
self.plotPool = []
......@@ -79,10 +80,6 @@ class PlotManager:
menu[0].addAction(action)
action.triggered.connect(newP._tasteplot.configurePlot)
# Create a new instance of plot
#if self._use_gnuplot:
# self.newPlotInstance(newP)
#else:
return handle
def newMeter(self, title, minR=0, maxR=120):
......@@ -90,8 +87,6 @@ class PlotManager:
self.plotCount += 1
newSM = plot(self.plotCount)
self.plotPool.append(newSM)
#defsizepos = '250x250+0+0'
#self.newPlotInstance(newSM, 1, cmd, defsizepos)
newSM._speedoName = 'SM '+ str(self.plotCount) + ': ' + title
newSM._speedoMinRange = minR
newSM._speedoMaxRange = maxR
......@@ -117,21 +112,16 @@ class PlotManager:
curveId = plotInfo['curveName']
for plot in self.plotPool:
if plot.handle == plotId:
#string = "{id} {val}\nreplot\n".format(id=curveId, val=value)
if not plot._speedo:
#if self._use_gnuplot: (Removed test to gain performance - we don't use gnuplot)
#plot._fifo.write(string)
#else:
# matplotlib is very slow: we must reduce the number of refresh
# by grouping together the update values for each curve of a plot
plot.pending_values.append({'id': curveId, 'value': value})
# matplotlib is very slow: we must reduce the number of refresh
# by grouping together the update values for each curve of a plot
plot.pending_values.append({'id': curveId, 'value': value})
else:
return plot._speedo.updateValue(value)
@Slot()
def refresh(self):
''' Refresh matplotlib display(s) if new values are waiting '''
#if self._use_gnuplot:
# return
for plot in self.plotPool:
if len(plot.pending_values) > 0:
plot._tasteplot.updateValue(plot.pending_values)
......@@ -139,15 +129,11 @@ class PlotManager:
def newPlotInstance(self, plot, defcmd='cat %s | feedgnuplot --stream 0 --lines --dataid --autolegend ', defsizepos="320x240+0+0"):
'''Common function used for both metering and gnuplotting a grid line (Not used anymore) '''
# descr, _, actualOffset = self.LabelAndTypeAndActualOffsetOfSelectedLine()
isGnuPlot = "gnuplot" in defcmd
#if isGnuPlot and g_gnuplotIsMissing:
# self.ShowError("Missing dependency:", "gnuplot is not installed in your machine, plot is disabled...")
# return
# use the actualOffset to identify the PlottedVariable instance
if plot._fifo == None:
# construct new FIFO name
cleanFIFOname = "/tmp/" + str(plot.handle) # re.sub(r'[^a-zA-Z0-9_]', '_', descr)
cleanFIFOname = "/tmp/" + str(plot.handle)
cleanFIFOname += "_gnuplot" if isGnuPlot else "_meter"
try:
os.mkfifo(cleanFIFOname)
......@@ -188,8 +174,6 @@ class PlotManager:
def closeAll(self):
for plot in self.plotPool:
#if plot._pid != -1:
# self.KillTree(plot._pid)
if plot._speedo:
plot._speedo.close()
if plot._tasteplot:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment