class BlissScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal("newScan", ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.canAddPoint = True self.dm = DataManager() event.connect(self.dm, "scan_new", self.newScan) event.connect(self.dm, "scan_data", self.newScanPoint) self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == "backgroundColor": if newValue == "white": self.setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) elif property == "graphColor": if newValue == "white": self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.graph.canvas().setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self, property, oldValue, newValue) # def newScan(self, dm, scan_id, filename, motors, npoints, counters, # save_flag=True): def newScan(self, scan_id, filename, motors, npoints, counters, save_flag=True): self.emit(PYSIGNAL("newScan"), ()) self.lblTitle.setText("<nobr><b>%s</b></nobr>" % filename) self.xdata = [] self.graph.clearcurves() # self.graph.xlabel(scanParameters['xlabel']) self.graph.xlabel("Energy") self.ylabel = "Counts" ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels, ydata in zip(ylabels, self.ydatas): self.graph.newcurve(labels, self.xdata, ydata) self.graph.ylabel(self.ylabel) if motors == "Time": self.graph.setx1timescale(True) else: self.graph.setx1timescale(False) self.graph.replot() def newScanPoint(self, scan_id, values): x = values[0] self.xdata.append(x) for label, ydata, yvalue in zip(self.ylabel.split(), self.ydatas, values[1:]): ydata.append(float(yvalue)) self.graph.newcurve(label, self.xdata, ydata) self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt": self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict["x"], signalDict["y"]))
class SoleilScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSlot("newScan", ()) self.defineSlot("newScanPoint", ()) self.scanObject = None self.xdata = [] self.ydata = [] self.isConnected = None self.canAddPoint = True self.addProperty("specVersion", "string", "") self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == "specVersion": if self.scanObject is not None: self.safeDisconnect() self.scanObject = None if self.scanObject is not None: self.safeConnect() elif property == "backgroundColor": if newValue == "white": self.setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) elif property == "graphColor": if newValue == "white": self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.graph.canvas().setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self, property, oldValue, newValue) def newScan(self, scanParameters): logging.info("newScan scanParameters %s" % str(scanParameters)) self.lblTitle.setText("<nobr><b>%s</b></nobr>" % scanParameters["title"]) self.graph.xlabel(scanParameters["xlabel"]) self.graph.ylabel(scanParameters["ylabel"]) self.graph.setx1timescale(False) self.xdata = [] self.ydata = [] self.graph.newcurve("scan", self.xdata, self.ydata) self.graph.replot() def newScanPoint(self, x, y): logging.info("newScanPoint x %s, y %s" % (x, y)) self.xdata.append(x) self.ydata.append(y) self.graph.newcurve("scan", self.xdata, self.ydata, curveinfo="bo-") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt": self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict["x"], signalDict["y"])) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL("newScanPoint"), self.newScan) self.connect(self.scanObject, PYSIGNAL("newPoint"), self.newScanPoint) self.isConnected = True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL("newScan"), self.newScan) self.disconnect(self.scanObject, PYSIGNAL("newScanPoint"), self.newScanPoint) self.isConnected = False
class SpecScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal("newScan", ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.isConnected = None # self.canAddPoint = None self.canAddPoint = True self.addProperty("specVersion", "string", "") self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) # self.cmdZoomIn = QToolButton(buttonBox) # self.cmdZoomOut = QToolButton(buttonBox) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) # QObject.connect(self.cmdZoomIn, SIGNAL('clicked()'), self.cmdZoomInClicked) # QObject.connect(self.cmdZoomOut, SIGNAL('clicked()'), self.cmdZoomOutClicked) # self.cmdZoomIn.setIconSet(QIconSet(Icons.load("zoomin"))) # self.cmdZoomOut.setIconSet(QIconSet(Icons.load("zoomout"))) # self.cmdZoomIn.setToggleButton(True) # self.cmdZoomOut.setToggleButton(True) # self.cmdZoomIn.setUsesTextLabel(False) # self.cmdZoomOut.setUsesTextLabel(False) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == "specVersion": if self.scanObject is not None: self.safeDisconnect() self.scanObject = QSpecScan(newValue) if self.scanObject is not None: self.safeConnect() elif property == "backgroundColor": if newValue == "white": self.setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) elif property == "graphColor": if newValue == "white": self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.graph.canvas().setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self, property, oldValue, newValue) def newScan(self, scanParameters): # self.canAddPoint = True self.emit(PYSIGNAL("newScan"), ()) self.lblTitle.setText("<nobr><b>%s</b></nobr>" % scanParameters["title"]) self.xdata = [] self.graph.clearcurves() self.graph.xlabel(scanParameters["xlabel"]) self.ylabel = scanParameters["ylabel"] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels, ydata in zip(ylabels, self.ydatas): self.graph.newcurve(labels, self.xdata, ydata) self.graph.ylabel(self.ylabel) if self.scanObject.getScanType() == SpecScan.TIMESCAN: self.graph.setx1timescale(True) else: self.graph.setx1timescale(False) try: scanParameters["scaletype"] == "log" if self.mylog == 0: self.graph.toggleLogY() self.mylog = 1 except BaseException: if self.mylog == 1: self.graph.toggleLogY() self.mylog = 0 self.graph.replot() def newScanPoint(self, x, y): self.xdata.append(x) for label, ydata, yvalue in zip(self.ylabel.split(), self.ydatas, str(y).split()): ydata.append(float(yvalue)) self.graph.newcurve(label, self.xdata, ydata) self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt": self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict["x"], signalDict["y"])) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL("newScan"), self.newScan) self.connect(self.scanObject, PYSIGNAL("newPoint"), self.newScanPoint) self.isConnected = True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL("newScan"), self.newScan) self.disconnect(self.scanObject, PYSIGNAL("newScanPoint"), self.newScanPoint) # self.canAddPoint = False self.isConnected = False # def instanceMirrorChanged(self,mirror): # if BlissWidget.isInstanceMirrorAllow(): # self.safeConnect() # else: # self.safeDisconnect() """
class SoleilScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSlot("newScan", ()) self.defineSlot("newScanPoint", ()) self.scanObject = None self.xdata = [] self.ydata = [] self.isConnected = None self.canAddPoint = True self.addProperty("specVersion", "string", "") self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect( self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal ) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == "specVersion": if self.scanObject is not None: self.safeDisconnect() self.scanObject = None if self.scanObject is not None: self.safeConnect() elif property == "backgroundColor": if newValue == "white": self.setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) elif property == "graphColor": if newValue == "white": self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == "default": self.graph.canvas().setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self) ) else: BlissWidget.propertyChanged(self, property, oldValue, newValue) def newScan(self, scanParameters): logging.info("newScan scanParameters %s" % str(scanParameters)) self.lblTitle.setText("<nobr><b>%s</b></nobr>" % scanParameters["title"]) self.graph.xlabel(scanParameters["xlabel"]) self.graph.ylabel(scanParameters["ylabel"]) self.graph.setx1timescale(False) self.xdata = [] self.ydata = [] self.graph.newcurve("scan", self.xdata, self.ydata) self.graph.replot() def newScanPoint(self, x, y): logging.info("newScanPoint x %s, y %s" % (x, y)) self.xdata.append(x) self.ydata.append(y) self.graph.newcurve("scan", self.xdata, self.ydata, curveinfo="bo-") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt": self.lblPosition.setText( "(X: %f, Y: %f)" % (signalDict["x"], signalDict["y"]) ) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL("newScanPoint"), self.newScan) self.connect(self.scanObject, PYSIGNAL("newPoint"), self.newScanPoint) self.isConnected = True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL("newScan"), self.newScan) self.disconnect( self.scanObject, PYSIGNAL("newScanPoint"), self.newScanPoint ) self.isConnected = False
class ScanPlotWidget(QtGui.QWidget): def __init__(self, parent=None, name="scan_plot_widget"): QtGui.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) self.xdata = [] self.ylabel = "" self.isRealTimePlot = None self.isConnected = None self.isScanning = None self.lblTitle = QtGui.QLabel(self) #self.graphPanel = qt.QFrame(self) #buttonBox = qt.QHBox(self) self.lblPosition = QtGui.QLabel(self) self.graph = QtBlissGraph(self) QtCore.QObject.connect(self.graph, QtCore.SIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QtCore.QObject.disconnect( self.graph, QtCore.SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QtCore.QObject.disconnect( self.graph, QtCore.SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) #self.graph.setAutoLegend(False) """self.lblPosition.setAlignment(qt.Qt.AlignRight) self.lblTitle.setAlignment(qt.Qt.AlignHCenter) self.lblTitle.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) self.lblPosition.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) buttonBox.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) qt.QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) qt.QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) self.setPaletteBackgroundColor(qt.Qt.white)""" _main_vlayout = QtGui.QVBoxLayout(self) _main_vlayout.addWidget(self.lblTitle) _main_vlayout.addWidget(self.lblPosition) _main_vlayout.addWidget(self.graph) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(0, 0, 0, 0) def setRealTimePlot(self, isRealTime): self.isRealTimePlot = isRealTime def start_new_scan(self, scanParameters): self.graph.clearcurves() self.isScanning = True self.lblTitle.setText('<nobr><b>%s</b></nobr>' % scanParameters['title']) self.xdata = [] self.graph.xlabel(scanParameters['xlabel']) self.ylabel = scanParameters['ylabel'] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels, ydata in zip(ylabels, self.ydatas): self.graph.newcurve(labels, self.xdata, ydata) self.graph.ylabel(self.ylabel) self.graph.setx1timescale(False) self.graph.replot() self.graph.setTitle("Energy scan started. Waiting values...") def add_new_plot_value(self, x, y): self.xdata.append(x) for label, ydata, yvalue in zip(self.ylabel.split(), self.ydatas, str(y).split()): ydata.append(float(yvalue)) self.graph.newcurve(label, self.xdata, ydata) self.graph.setTitle("Energy scan in progress. Please wait...") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt' and self.isScanning: self.lblPosition.setText("(X: %0.2f, Y: %0.2f)" % (signalDict['x'], signalDict['y'])) def plot_results(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title): self.graph.clearcurves() self.graph.setTitle(title) self.graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.graph.replot() self.isScanning = False def plot_scan_curve(self, scan_data): self.graph.clearcurves() self.graph.setTitle("Energy scan finished") self.lblTitle.setText("") xdata = [scan_data[el][0] for el in range(len(scan_data))] ydata = [scan_data[el][1] for el in range(len(scan_data))] self.graph.newcurve("energy", xdata, ydata) self.graph.replot() def clear(self): self.graph.clearcurves() #self.graph.setTitle("") self.lblTitle.setText("") self.lblPosition.setText("") def scan_finished(self): self.graph.setTitle("Energy scan finished")
class BlissScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal('newScan', ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.canAddPoint = True self.dm = DataManager() event.connect(self.dm, "scan_new", self.newScan) event.connect(self.dm, "scan_data", self.newScanPoint) self.addProperty('backgroundColor', 'combo', ('white', 'default'), 'white') self.addProperty('graphColor', 'combo', ('white', 'default'), 'white') self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QObject.disconnect(self.graph, SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QObject.disconnect(self.graph, SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == 'backgroundColor': if newValue == 'white': self.setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) elif property == 'graphColor': if newValue == 'white': self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.graph.canvas().setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self,property,oldValue,newValue) #def newScan(self, dm, scan_id, filename, motors, npoints, counters, save_flag=True): def newScan(self, scan_id, filename, motors, npoints, counters, save_flag=True): self.emit(PYSIGNAL('newScan'), ()) self.lblTitle.setText('<nobr><b>%s</b></nobr>' % filename) self.xdata = [] self.graph.clearcurves() #self.graph.xlabel(scanParameters['xlabel']) self.graph.xlabel("Energy") self.ylabel = "Counts" ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels,ydata in zip(ylabels,self.ydatas): self.graph.newcurve(labels,self.xdata,ydata) self.graph.ylabel(self.ylabel) if motors == 'Time': self.graph.setx1timescale(True) else: self.graph.setx1timescale(False) self.graph.replot() def newScanPoint(self, scan_id, values): x = values[0] self.xdata.append(x) for label,ydata,yvalue in zip(self.ylabel.split(),self.ydatas,values[1:]): ydata.append(float(yvalue)) self.graph.newcurve(label,self.xdata,ydata) self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt': self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict['x'], signalDict['y']))
class SpecScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal('newScan', ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.isConnected = None #self.canAddPoint = None self.canAddPoint = True self.addProperty('specVersion', 'string', '') self.addProperty('backgroundColor', 'combo', ('white', 'default'), 'white') self.addProperty('graphColor', 'combo', ('white', 'default'), 'white') self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) #self.cmdZoomIn = QToolButton(buttonBox) #self.cmdZoomOut = QToolButton(buttonBox) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QObject.disconnect(self.graph, SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QObject.disconnect(self.graph, SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) #QObject.connect(self.cmdZoomIn, SIGNAL('clicked()'), self.cmdZoomInClicked) #QObject.connect(self.cmdZoomOut, SIGNAL('clicked()'), self.cmdZoomOutClicked) #self.cmdZoomIn.setIconSet(QIconSet(Icons.load("zoomin"))) #self.cmdZoomOut.setIconSet(QIconSet(Icons.load("zoomout"))) #self.cmdZoomIn.setToggleButton(True) #self.cmdZoomOut.setToggleButton(True) #self.cmdZoomIn.setUsesTextLabel(False) #self.cmdZoomOut.setUsesTextLabel(False) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == 'specVersion': if self.scanObject is not None: self.safeDisconnect() self.scanObject = QSpecScan(newValue) if self.scanObject is not None: self.safeConnect() elif property == 'backgroundColor': if newValue == 'white': self.setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) elif property == 'graphColor': if newValue == 'white': self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.graph.canvas().setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self,property,oldValue,newValue) def newScan(self, scanParameters): #self.canAddPoint = True self.emit(PYSIGNAL('newScan'), ()) self.lblTitle.setText('<nobr><b>%s</b></nobr>' % scanParameters['title']) self.xdata = [] self.graph.clearcurves() self.graph.xlabel(scanParameters['xlabel']) self.ylabel = scanParameters['ylabel'] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels,ydata in zip(ylabels,self.ydatas): self.graph.newcurve(labels,self.xdata,ydata) self.graph.ylabel(self.ylabel) if self.scanObject.getScanType() == SpecScan.TIMESCAN: self.graph.setx1timescale(True) else: self.graph.setx1timescale(False) try: scanParameters['scaletype'] == 'log' if self.mylog == 0 : self.graph.toggleLogY() self.mylog = 1 except: if self.mylog == 1: self.graph.toggleLogY() self.mylog = 0 self.graph.replot() def newScanPoint(self, x, y): self.xdata.append(x) for label,ydata,yvalue in zip(self.ylabel.split(),self.ydatas,str(y).split()) : ydata.append(float(yvalue)) self.graph.newcurve(label,self.xdata,ydata) self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt': self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict['x'], signalDict['y'])) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL('newScan'), self.newScan) self.connect(self.scanObject, PYSIGNAL('newPoint'), self.newScanPoint) self.isConnected=True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL('newScan'), self.newScan) self.disconnect(self.scanObject, PYSIGNAL('newScanPoint'), self.newScanPoint) #self.canAddPoint = False self.isConnected = False #def instanceMirrorChanged(self,mirror): # if BlissWidget.isInstanceMirrorAllow(): # self.safeConnect() # else: # self.safeDisconnect() """
class ScanPlotWidget(qt.QWidget): def __init__(self, parent=None, name="scan_plot_widget"): qt.QWidget.__init__(self, parent, name) self.xdata = [] self.ylabel = "" self.isRealTimePlot = None self.isConnected = None self.isScanning = None self.lblTitle = qt.QLabel(self) self.graphPanel = qt.QFrame(self) buttonBox = qt.QHBox(self) self.lblPosition = qt.QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) qt.QObject.connect( self.graph, qt.PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal ) qt.QObject.disconnect( self.graph, qt.SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) qt.QObject.disconnect( self.graph, qt.SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) # self.graph.setAutoLegend(False) self.lblPosition.setAlignment(qt.Qt.AlignRight) self.lblTitle.setAlignment(qt.Qt.AlignHCenter) self.lblTitle.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) self.lblPosition.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) buttonBox.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) qt.QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) qt.QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) self.setPaletteBackgroundColor(qt.Qt.white) def setRealTimePlot(self, isRealTime): self.isRealTimePlot = isRealTime def newScanStarted(self, scanParameters): self.graph.clearcurves() self.isScanning = True self.lblTitle.setText("<nobr><b>%s</b></nobr>" % scanParameters["title"]) self.xdata = [] self.graph.xlabel(scanParameters["xlabel"]) self.ylabel = scanParameters["ylabel"] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels, ydata in zip(ylabels, self.ydatas): self.graph.newcurve(labels, self.xdata, ydata) self.graph.ylabel(self.ylabel) self.graph.setx1timescale(False) self.graph.replot() self.graph.setTitle("Energy scan started. Waiting values...") def newScanPoint(self, x, y): self.xdata.append(x) for label, ydata, yvalue in zip( self.ylabel.split(), self.ydatas, str(y).split() ): ydata.append(float(yvalue)) self.graph.newcurve(label, self.xdata, ydata) self.graph.setTitle("Energy scan in progress. Please wait...") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt" and self.isScanning: self.lblPosition.setText( "(X: %0.2f, Y: %0.2f)" % (signalDict["x"], signalDict["y"]) ) def plotResults( self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title, ): self.graph.clearcurves() self.graph.setTitle(title) self.graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.graph.replot() self.isScanning = False def plotScanCurve(self, scan_data): self.graph.clearcurves() self.graph.setTitle("Energy scan finished") self.lblTitle.setText("") xdata = [scan_data[el][0] for el in range(len(scan_data))] ydata = [scan_data[el][1] for el in range(len(scan_data))] self.graph.newcurve("energy", xdata, ydata) self.graph.replot() def clear(self): self.graph.clearcurves() # self.graph.setTitle("") self.lblTitle.setText("") self.lblPosition.setText("") def scanFinished(self): self.graph.setTitle("Energy scan finished")
class ColormapDialog(qt.QDialog): def __init__(self, parent=None, name="Colormap Dialog", slider=False): if QTVERSION < '4.0.0': qt.QDialog.__init__(self, parent, name) self.setCaption(name) else: qt.QDialog.__init__(self, parent) self.setWindowTitle(name) self.title = name self.colormapList = [ "Greyscale", "Reverse Grey", "Temperature", "Red", "Green", "Blue", "Many" ] # default values self.dataMin = -10 self.dataMax = 10 self.minValue = 0 self.maxValue = 1 self.colormapIndex = 2 self.colormapType = 0 self.autoscale = False self.autoscale90 = False # main layout if QTVERSION < '4.0.0': vlayout = qt.QVBoxLayout(self, 0, -1, "Main ColormapDialog Layout") else: vlayout = qt.QVBoxLayout(self) vlayout.setMargin(10) vlayout.setSpacing(0) # layout 1 : -combo to choose colormap # -autoscale button # -autoscale 90% button hbox1 = qt.QWidget(self) hlayout1 = qt.QHBoxLayout(hbox1) vlayout.addWidget(hbox1) hlayout1.setMargin(0) hlayout1.setSpacing(10) # combo self.combo = qt.QComboBox(hbox1) for colormap in self.colormapList: if QTVERSION < '4.0.0': self.combo.insertItem(colormap) else: self.combo.addItem(colormap) self.connect(self.combo, qt.SIGNAL("activated(int)"), self.colormapChange) hlayout1.addWidget(self.combo) # autoscale self.autoScaleButton = qt.QPushButton("Autoscale", hbox1) if QTVERSION < '4.0.0': self.autoScaleButton.setToggleButton(True) else: self.autoScaleButton.setCheckable(True) self.autoScaleButton.setAutoDefault(False) self.connect(self.autoScaleButton, qt.SIGNAL("toggled(bool)"), self.autoscaleChange) hlayout1.addWidget(self.autoScaleButton) # autoscale 90% self.autoScale90Button = qt.QPushButton("Autoscale 90%", hbox1) if QTVERSION < '4.0.0': self.autoScale90Button.setToggleButton(True) else: self.autoScale90Button.setCheckable(True) self.autoScale90Button.setAutoDefault(False) self.connect(self.autoScale90Button, qt.SIGNAL("toggled(bool)"), self.autoscale90Change) hlayout1.addWidget(self.autoScale90Button) # hlayout if QTVERSION > '4.0.0': hbox0 = qt.QWidget(self) self.__hbox0 = hbox0 hlayout0 = qt.QHBoxLayout(hbox0) hlayout0.setMargin(0) hlayout0.setSpacing(0) vlayout.addWidget(hbox0) #hlayout0.addStretch(10) self.buttonGroup = qt.QButtonGroup() g1 = qt.QCheckBox(hbox0) g1.setText("Linear") g2 = qt.QCheckBox(hbox0) g2.setText("Logarithmic") g3 = qt.QCheckBox(hbox0) g3.setText("Gamma") self.buttonGroup.addButton(g1, 0) self.buttonGroup.addButton(g2, 1) self.buttonGroup.addButton(g3, 2) self.buttonGroup.setExclusive(True) if self.colormapType == 1: self.buttonGroup.button(1).setChecked(True) elif self.colormapType == 2: self.buttonGroup.button(2).setChecked(True) else: self.buttonGroup.button(0).setChecked(True) hlayout0.addWidget(g1) hlayout0.addWidget(g2) hlayout0.addWidget(g3) vlayout.addWidget(hbox0) self.connect(self.buttonGroup, qt.SIGNAL("buttonClicked(int)"), self.buttonGroupChange) vlayout.addSpacing(20) hboxlimits = qt.QWidget(self) hboxlimitslayout = qt.QHBoxLayout(hboxlimits) hboxlimitslayout.setMargin(0) hboxlimitslayout.setSpacing(0) if slider: self.slider = DoubleSlider.DoubleSlider(hboxlimits, scale=False) hboxlimitslayout.addWidget(self.slider) else: self.slider = None vlayout.addWidget(hboxlimits) vboxlimits = qt.QWidget(hboxlimits) vboxlimitslayout = qt.QVBoxLayout(vboxlimits) vboxlimitslayout.setMargin(0) vboxlimitslayout.setSpacing(0) hboxlimitslayout.addWidget(vboxlimits) # hlayout 2 : - min label # - min texte hbox2 = qt.QWidget(vboxlimits) self.__hbox2 = hbox2 hlayout2 = qt.QHBoxLayout(hbox2) hlayout2.setMargin(0) hlayout2.setSpacing(0) #vlayout.addWidget(hbox2) vboxlimitslayout.addWidget(hbox2) hlayout2.addStretch(10) self.minLabel = qt.QLabel(hbox2) self.minLabel.setText("Minimum") hlayout2.addWidget(self.minLabel) hlayout2.addSpacing(5) hlayout2.addStretch(1) self.minText = MyQLineEdit(hbox2) self.minText.setFixedWidth(150) self.minText.setAlignment(qt.Qt.AlignRight) self.connect(self.minText, qt.SIGNAL("returnPressed()"), self.minTextChanged) hlayout2.addWidget(self.minText) # hlayout 3 : - min label # - min text hbox3 = qt.QWidget(vboxlimits) self.__hbox3 = hbox3 hlayout3 = qt.QHBoxLayout(hbox3) hlayout3.setMargin(0) hlayout3.setSpacing(0) #vlayout.addWidget(hbox3) vboxlimitslayout.addWidget(hbox3) hlayout3.addStretch(10) self.maxLabel = qt.QLabel(hbox3) self.maxLabel.setText("Maximum") hlayout3.addWidget(self.maxLabel) hlayout3.addSpacing(5) hlayout3.addStretch(1) self.maxText = MyQLineEdit(hbox3) self.maxText.setFixedWidth(150) self.maxText.setAlignment(qt.Qt.AlignRight) self.connect(self.maxText, qt.SIGNAL("returnPressed()"), self.maxTextChanged) hlayout3.addWidget(self.maxText) # Graph widget for color curve... self.c = QtBlissGraph(self) self.c.xlabel("Data Values") self.c.enableZoom(False) self.c.setCanvasBackground(qt.Qt.white) self.c.canvas().setMouseTracking(1) self.c.enableAxis(Qwt5.QwtPlot.xBottom) self.marge = (abs(self.dataMax) + abs(self.dataMin)) / 6.0 self.minmd = self.dataMin - self.marge self.maxpd = self.dataMax + self.marge self.c.setx1axislimits(self.minmd, self.maxpd) self.c.sety1axislimits(-11.5, 11.5) self.c.picker.setSelectionFlags(Qwt5.QwtPicker.NoSelection) x = [self.minmd, self.dataMin, self.dataMax, self.maxpd] y = [-10, -10, 10, 10] self.c.newCurve("ConstrainedCurve", x, y) self.markers = [] self.__x = x self.__y = y for i in range(4): index = self.c.insertx1marker(x[i], y[i], noline=True) marker = self.c.markersdict[index]['marker'] if i in [1, 2]: self.c.setmarkerfollowmouse(index, 1) marker.setLinePen(qt.QPen(qt.Qt.green, 2, qt.Qt.DashDotLine)) marker.setSymbol( Qwt5.QwtSymbol(Qwt5.QwtSymbol.Diamond, qt.QBrush(qt.Qt.blue), qt.QPen(qt.Qt.red), qt.QSize(15, 15))) self.markers.append(index) #self.c.enablemarkermode() self.c.setMinimumSize(qt.QSize(250, 200)) vlayout.addWidget(self.c) if QTVERSION < '4.0.0': self.connect(self.c, qt.PYSIGNAL("QtBlissGraphSignal"), self.chval) self.connect(self.c, qt.PYSIGNAL("QtBlissGraphSignal"), self.chmap) if slider: self.connect(self.slider, qt.PYSIGNAL("doubleSliderValueChanged"), self._sliderChanged) else: self.connect(self.c, qt.SIGNAL("QtBlissGraphSignal"), self.chval) self.connect(self.c, qt.SIGNAL("QtBlissGraphSignal"), self.chmap) if slider: self.connect(self.slider, qt.SIGNAL("doubleSliderValueChanged"), self._sliderChanged) # colormap window can not be resized self.setFixedSize(vlayout.minimumSize()) def _sliderChanged(self, ddict): if not self.__sliderConnected: return delta = (self.dataMax - self.dataMin) * 0.01 xmin = self.dataMin + delta * ddict['min'] xmax = self.dataMin + delta * ddict['max'] self.setDisplayedMinValue(xmin) self.setDisplayedMaxValue(xmax) self.__x[1] = xmin self.__x[2] = xmax self.c.newCurve("ConstrainedCurve", self.__x, self.__y) for i in range(4): self.c.setMarkerXPos(self.c.markersdict[self.markers[i]]['marker'], self.__x[i]) self.c.setMarkerYPos(self.c.markersdict[self.markers[i]]['marker'], self.__y[i]) self.c.replot() if DEBUG: print("Slider asking to update colormap") #self._update() self.sendColormap() def _update(self): if DEBUG: print("colormap _update called") self.marge = (abs(self.dataMax) + abs(self.dataMin)) / 6.0 self.minmd = self.dataMin - self.marge self.maxpd = self.dataMax + self.marge self.c.setx1axislimits(self.minmd, self.maxpd) self.c.sety1axislimits(-11.5, 11.5) self.__x = [self.minmd, self.dataMin, self.dataMax, self.maxpd] self.__y = [-10, -10, 10, 10] self.c.newCurve("ConstrainedCurve", self.__x, self.__y) for i in range(4): self.c.setMarkerXPos(self.c.markersdict[self.markers[i]]['marker'], self.__x[i]) self.c.setMarkerYPos(self.c.markersdict[self.markers[i]]['marker'], self.__y[i]) self.c.replot() self.sendColormap() def buttonGroupChange(self, val): if DEBUG: print("buttonGroup asking to update colormap") self.setColormapType(val, update=True) self._update() def setColormapType(self, val, update=False): self.colormapType = val if QTVERSION > '4.0.0': if self.colormapType == 1: self.buttonGroup.button(1).setChecked(True) elif self.colormapType == 2: self.buttonGroup.button(2).setChecked(True) else: self.colormapType = 0 self.buttonGroup.button(0).setChecked(True) if update: self._update() def chval(self, ddict): if ddict['event'] == 'markerMoving': if ddict['marker'] in self.markers: markerIndex = self.markers.index(ddict['marker']) else: print("Unknown marker") return else: return diam = markerIndex + 1 x = ddict['x'] if diam == 2: self.setDisplayedMinValue(x) if diam == 3: self.setDisplayedMaxValue(x) def chmap(self, ddict): if ddict['event'] == 'markerMoved': if ddict['marker'] in self.markers: markerIndex = self.markers.index(ddict['marker']) else: print("Unknown marker") return else: return diam = markerIndex + 1 x = ddict['x'] if diam == 2: self.setMinValue(x) if diam == 3: self.setMaxValue(x) """ Colormap """ def setColormap(self, colormap): self.colormapIndex = colormap if QTVERSION < '4.0.0': self.combo.setCurrentItem(colormap) else: self.combo.setCurrentIndex(colormap) def colormapChange(self, colormap): self.colormapIndex = colormap self.sendColormap() # AUTOSCALE """ Autoscale """ def autoscaleChange(self, val): self.autoscale = val self.setAutoscale(val) self.sendColormap() def setAutoscale(self, val): if DEBUG: print("setAutoscale called", val) if val: if QTVERSION < '4.0.0': self.autoScaleButton.setOn(True) self.autoScale90Button.setOn(False) else: self.autoScaleButton.setChecked(True) self.autoScale90Button.setChecked(False) #self.autoScale90Button.setDown(False) self.setMinValue(self.dataMin) self.setMaxValue(self.dataMax) if self.slider is not None: self.__sliderConnected = False self.slider.setMinMax(0, 100) self.slider.setEnabled(False) self.__sliderConnected = True self.maxText.setEnabled(0) self.minText.setEnabled(0) self.c.setEnabled(0) self.c.disablemarkermode() else: if QTVERSION < '4.0.0': self.autoScaleButton.setOn(False) self.autoScale90Button.setOn(False) else: self.autoScaleButton.setChecked(False) self.autoScale90Button.setChecked(False) self.minText.setEnabled(1) self.maxText.setEnabled(1) if self.slider: self.slider.setEnabled(True) self.c.setEnabled(1) self.c.enablemarkermode() """ set rangeValues to dataMin ; dataMax-10% """ def autoscale90Change(self, val): self.autoscale90 = val self.setAutoscale90(val) self.sendColormap() def setAutoscale90(self, val): if val: if QTVERSION < '4.0.0': self.autoScaleButton.setOn(False) else: self.autoScaleButton.setChecked(False) self.setMinValue(self.dataMin) self.setMaxValue(self.dataMax - abs(self.dataMax / 10)) if self.slider is not None: self.__sliderConnected = False self.slider.setMinMax(0, 90) self.slider.setEnabled(0) self.__sliderConnected = True self.minText.setEnabled(0) self.maxText.setEnabled(0) self.c.setEnabled(0) self.c.disablemarkermode() else: if QTVERSION < '4.0.0': self.autoScale90Button.setOn(False) else: self.autoScale90Button.setChecked(False) self.minText.setEnabled(1) self.maxText.setEnabled(1) if self.slider: self.slider.setEnabled(True) self.c.setEnabled(1) self.c.enablemarkermode() self.c.setFocus() # MINIMUM """ change min value and update colormap """ def setMinValue(self, val): v = float(str(val)) self.minValue = v self.minText.setText("%g" % v) self.__x[1] = v self.c.setMarkerXPos(self.c.markersdict[self.markers[1]]['marker'], v) self.c.newCurve("ConstrainedCurve", self.__x, self.__y) self.sendColormap() """ min value changed by text """ def minTextChanged(self): text = str(self.minText.text()) if not len(text): return val = float(text) self.setMinValue(val) if self.minText.hasFocus(): self.c.setFocus() """ change only the displayed min value """ def setDisplayedMinValue(self, val): val = float(val) self.minValue = val self.minText.setText("%g" % val) self.__x[1] = val self.c.setMarkerXPos(self.c.markersdict[self.markers[1]]['marker'], val) self.c.newCurve("ConstrainedCurve", self.__x, self.__y) # MAXIMUM """ change max value and update colormap """ def setMaxValue(self, val): v = float(str(val)) self.maxValue = v self.maxText.setText("%g" % v) self.__x[2] = v self.c.setMarkerXPos(self.c.markersdict[self.markers[2]]['marker'], v) self.c.newCurve("ConstrainedCurve", self.__x, self.__y) self.sendColormap() """ max value changed by text """ def maxTextChanged(self): text = str(self.maxText.text()) if not len(text): return val = float(text) self.setMaxValue(val) if self.maxText.hasFocus(): self.c.setFocus() """ change only the displayed max value """ def setDisplayedMaxValue(self, val): val = float(val) self.maxValue = val self.maxText.setText("%g" % val) self.__x[2] = val self.c.newCurve("ConstrainedCurve", self.__x, self.__y) # DATA values """ set min/max value of data source """ def setDataMinMax(self, minVal, maxVal, update=True): if minVal is not None: vmin = float(str(minVal)) self.dataMin = vmin if maxVal is not None: vmax = float(str(maxVal)) self.dataMax = vmax if update: # are current values in the good range ? self._update() """ send 'ColormapChanged' signal """ def sendColormap(self): if DEBUG: print("sending colormap") #prevent unexpected behaviour because of bad limits if self.minValue > self.maxValue: vmax = self.minValue vmin = self.maxValue else: vmax = self.maxValue vmin = self.minValue try: if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("ColormapChanged"), (self.colormapIndex, self.autoscale, vmin, vmax, self.dataMin, self.dataMax, self.colormapType)) else: self.emit(qt.SIGNAL("ColormapChanged"), self.colormapIndex, self.autoscale, vmin, vmax, self.dataMin, self.dataMax, self.colormapType) except: sys.excepthook(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
class ScanPlotWidget(QtGui.QWidget): def __init__(self, parent = None, name = "scan_plot_widget"): QtGui.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) self.xdata = [] self.ylabel = "" self.isRealTimePlot = None self.isConnected = None self.isScanning = None self.lblTitle = QtGui.QLabel(self) #self.graphPanel = qt.QFrame(self) #buttonBox = qt.QHBox(self) self.lblPosition = QtGui.QLabel(self) self.graph = QtBlissGraph(self) QtCore.QObject.connect(self.graph, QtCore.SIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QtCore.QObject.disconnect(self.graph, QtCore.SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QtCore.QObject.disconnect(self.graph, QtCore.SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) #self.graph.setAutoLegend(False) """self.lblPosition.setAlignment(qt.Qt.AlignRight) self.lblTitle.setAlignment(qt.Qt.AlignHCenter) self.lblTitle.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) self.lblPosition.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) buttonBox.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) qt.QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) qt.QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) self.setPaletteBackgroundColor(qt.Qt.white)""" _main_vlayout = QtGui.QVBoxLayout(self) _main_vlayout.addWidget(self.lblTitle) _main_vlayout.addWidget(self.lblPosition) _main_vlayout.addWidget(self.graph) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(0, 0, 0, 0) def setRealTimePlot(self, isRealTime): self.isRealTimePlot = isRealTime def start_new_scan(self, scanParameters): self.graph.clearcurves() self.isScanning = True self.lblTitle.setText('<nobr><b>%s</b></nobr>' % scanParameters['title']) self.xdata = [] self.graph.xlabel(scanParameters['xlabel']) self.ylabel = scanParameters['ylabel'] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels,ydata in zip(ylabels,self.ydatas): self.graph.newcurve(labels,self.xdata,ydata) self.graph.ylabel(self.ylabel) self.graph.setx1timescale(False) self.graph.replot() self.graph.setTitle("Energy scan started. Waiting values...") def add_new_plot_value(self, x, y): self.xdata.append(x) for label,ydata,yvalue in zip(self.ylabel.split(),self.ydatas,str(y).split()) : ydata.append(float(yvalue)) self.graph.newcurve(label,self.xdata,ydata) self.graph.setTitle("Energy scan in progress. Please wait...") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt' and self.isScanning: self.lblPosition.setText("(X: %0.2f, Y: %0.2f)" % (signalDict['x'], signalDict['y'])) def plot_results(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title): self.graph.clearcurves() self.graph.setTitle(title) self.graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.graph.replot() self.isScanning = False def plot_scan_curve(self, scan_data): self.graph.clearcurves() self.graph.setTitle("Energy scan finished") self.lblTitle.setText("") xdata = [scan_data[el][0] for el in range(len(scan_data))] ydata = [scan_data[el][1] for el in range(len(scan_data))] self.graph.newcurve("energy", xdata, ydata) self.graph.replot() def clear(self): self.graph.clearcurves() #self.graph.setTitle("") self.lblTitle.setText("") self.lblPosition.setText("") def scan_finished(self): self.graph.setTitle("Energy scan finished")
class ScanPlotWidget(QtImport.QWidget): def __init__(self, parent=None, name="scan_plot_widget"): QtImport.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) self.xdata = [] self.ylabel = "" self.isRealTimePlot = None self.is_connected = None self.isScanning = None self.lblTitle = QtImport.QLabel(self) self.lblPosition = QtImport.QLabel(self) self.graph = QtBlissGraph(self) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self.lblTitle) _main_vlayout.addWidget(self.lblPosition) _main_vlayout.addWidget(self.graph) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(0, 0, 0, 0) def setRealTimePlot(self, isRealTime): self.isRealTimePlot = isRealTime def start_new_scan(self, scanParameters): self.graph.clearcurves() self.isScanning = True self.lblTitle.setText("<nobr><b>%s</b></nobr>" % scanParameters["title"]) self.xdata = [] self.graph.xlabel(scanParameters["xlabel"]) self.ylabel = scanParameters["ylabel"] ylabels = self.ylabel.split() self.ydatas = [[] for x in range(len(ylabels))] for labels, ydata in zip(ylabels, self.ydatas): self.graph.newcurve(labels, self.xdata, ydata) self.graph.ylabel(self.ylabel) self.graph.setx1timescale(False) self.graph.replot() self.graph.setTitle("Energy scan started. Waiting values...") def add_new_plot_value(self, x, y): self.xdata.append(x) for label, ydata, yvalue in zip( self.ylabel.split(), self.ydatas, str(y).split() ): ydata.append(float(yvalue)) self.graph.newcurve(label, self.xdata, ydata) self.graph.setTitle("Energy scan in progress. Please wait...") self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict["event"] == "MouseAt" and self.isScanning: self.lblPosition.setText( "(X: %0.2f, Y: %0.2f)" % (signalDict["x"], signalDict["y"]) ) def plot_results( self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title, ): self.graph.clearcurves() self.graph.setTitle(title) self.graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.graph.replot() self.isScanning = False def plot_scan_curve(self, scan_data): self.graph.clearcurves() self.graph.setTitle("Energy scan finished") self.lblTitle.setText("") xdata = [scan_data[el][0] for el in range(len(scan_data))] ydata = [scan_data[el][1] for el in range(len(scan_data))] self.graph.newcurve("energy", xdata, ydata) self.graph.replot() def clear(self): self.graph.clearcurves() # self.graph.setTitle("") self.lblTitle.setText("") self.lblPosition.setText("") def scan_finished(self): self.graph.setTitle("Energy scan finished")
class SoleilScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSlot('newScan', ()) self.defineSlot('newScanPoint', ()) self.scanObject = None self.xdata = [] self.ydata = [] self.isConnected = None self.canAddPoint = True self.addProperty('specVersion', 'string', '') self.addProperty('backgroundColor', 'combo', ('white', 'default'), 'white') self.addProperty('graphColor', 'combo', ('white', 'default'), 'white') self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QObject.disconnect(self.graph, SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QObject.disconnect(self.graph, SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == 'specVersion': if self.scanObject is not None: self.safeDisconnect() self.scanObject = None if self.scanObject is not None: self.safeConnect() elif property == 'backgroundColor': if newValue == 'white': self.setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) elif property == 'graphColor': if newValue == 'white': self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.graph.canvas().setPaletteBackgroundColor( QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self, property, oldValue, newValue) def newScan(self, scanParameters): logging.info('newScan scanParameters %s' % str(scanParameters)) self.lblTitle.setText('<nobr><b>%s</b></nobr>' % scanParameters['title']) self.graph.xlabel(scanParameters['xlabel']) self.graph.ylabel(scanParameters['ylabel']) self.graph.setx1timescale(False) self.xdata = [] self.ydata = [] self.graph.newcurve('scan', self.xdata, self.ydata) self.graph.replot() def newScanPoint(self, x, y): logging.info('newScanPoint x %s, y %s' % (x, y)) self.xdata.append(x) self.ydata.append(y) self.graph.newcurve('scan', self.xdata, self.ydata, curveinfo='bo-') self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt': self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict['x'], signalDict['y'])) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL('newScanPoint'), self.newScan) self.connect(self.scanObject, PYSIGNAL('newPoint'), self.newScanPoint) self.isConnected = True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL('newScan'), self.newScan) self.disconnect(self.scanObject, PYSIGNAL('newScanPoint'), self.newScanPoint) self.isConnected = False
class SoleilScanPlotBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSlot('newScan', ()) self.defineSlot('newScanPoint',()) self.scanObject = None self.xdata = [] self.ydata = [] self.isConnected = None self.canAddPoint = True self.addProperty('specVersion', 'string', '') self.addProperty('backgroundColor', 'combo', ('white', 'default'), 'white') self.addProperty('graphColor', 'combo', ('white', 'default'), 'white') self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.handleBlissGraphSignal) QObject.disconnect(self.graph, SIGNAL('plotMousePressed(const QMouseEvent&)'), self.graph.onMousePressed) QObject.disconnect(self.graph, SIGNAL('plotMouseReleased(const QMouseEvent&)'), self.graph.onMouseReleased) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel) def propertyChanged(self, property, oldValue, newValue): if property == 'specVersion': if self.scanObject is not None: self.safeDisconnect() self.scanObject = None if self.scanObject is not None: self.safeConnect() elif property == 'backgroundColor': if newValue == 'white': self.setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) elif property == 'graphColor': if newValue == 'white': self.graph.canvas().setPaletteBackgroundColor(Qt.white) elif newValue == 'default': self.graph.canvas().setPaletteBackgroundColor(QWidget.paletteBackgroundColor(self)) else: BlissWidget.propertyChanged(self,property,oldValue,newValue) def newScan(self, scanParameters): logging.info('newScan scanParameters %s' % str(scanParameters) ) self.lblTitle.setText('<nobr><b>%s</b></nobr>' % scanParameters['title']) self.graph.xlabel(scanParameters['xlabel']) self.graph.ylabel(scanParameters['ylabel']) self.graph.setx1timescale(False) self.xdata = [] self.ydata = [] self.graph.newcurve('scan', self.xdata, self.ydata) self.graph.replot() def newScanPoint(self, x, y): logging.info('newScanPoint x %s, y %s' % (x,y)) self.xdata.append(x) self.ydata.append(y) self.graph.newcurve('scan', self.xdata, self.ydata, curveinfo='bo-') self.graph.replot() def handleBlissGraphSignal(self, signalDict): if signalDict['event'] == 'MouseAt': self.lblPosition.setText("(X: %f, Y: %f)" % (signalDict['x'], signalDict['y'])) def safeConnect(self): if not self.isConnected: self.connect(self.scanObject, PYSIGNAL('newScanPoint'), self.newScan) self.connect(self.scanObject, PYSIGNAL('newPoint'), self.newScanPoint) self.isConnected=True def safeDisconnect(self): if self.isConnected: self.disconnect(self.scanObject, PYSIGNAL('newScan'), self.newScan) self.disconnect(self.scanObject, PYSIGNAL('newScanPoint'), self.newScanPoint) self.isConnected = False