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 LakeshoreBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.addProperty("mnemonic", "string", "") self.addProperty("unit", "combo", ("C", "K"), "C") self.addProperty("baseTime", "combo", ("current time", "0"), "0") self.lstChannelValueDisplay = [] self.lstChannelWidgets = [] self.data = {} self.lakeshore = None graphBox = QVBox(self) graphButtonsBox = QHBox(graphBox) graphButtonsBox.setSpacing(5) self.graph = QtBlissGraph(graphBox) self.graph.setx1timescale(True) self.graph.xlabel("time") self.graph.ylabel("temperature (%s)" % self["unit"]) self.graph.setPaletteBackgroundColor(Qt.white) self.graph.canvas().setMouseTracking(True) self.cmdResetZoom = QPushButton("Reset zoom", graphButtonsBox) self.lblXY = QLabel("X = ? ; Y = ?", graphButtonsBox) HorizontalSpacer(graphButtonsBox) self.cmdSaveData = QToolButton(graphButtonsBox) self.cmdSaveData.setUsesTextLabel(True) self.cmdSaveData.setTextLabel("Save data to file") self.cmdSaveData.setIconSet(QIconSet(Icons.load("save"))) self.cmdSaveData.setTextPosition(QToolButton.BesideIcon) self.topFrame = QVGroupBox("Lakeshore - ", self) updateFreqBox = QHBox(self.topFrame) updateFreqBox.setSpacing(5) QLabel("Update frequency : every", updateFreqBox) self.spnUpdateFrequency = QSpinBox(64, 30000, 500, updateFreqBox) QLabel("millisecond", updateFreqBox) self.lblUpdateFrequency = QLabel("<nobr><b>current = ?</b></nobr>", updateFreqBox) self.cmdUpdateFrequency = QPushButton("Change", updateFreqBox) HorizontalSpacer(updateFreqBox) self.lblStatus = QLabel("<h1>status</h1>", self.topFrame) self.lblStatus.setAlignment(Qt.AlignCenter) innerBox = QVBox(self.topFrame) self.channelsBox = QGrid(8, innerBox) self.channelsBox.setSpacing(5) self.channelsBox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) commandsBox = QVBox(innerBox) VerticalSpacer(self.topFrame) resetBox = QHBox(self.topFrame) HorizontalSpacer(resetBox) #self.cmdReset = QToolButton(resetBox) #self.cmdReset.setUsesTextLabel(True) #self.cmdReset.setTextLabel("Reset instrument") #self.cmdReset.setIconSet(QIconSet(Icons.load("reload"))) #self.cmdReset.setTextPosition(QToolButton.BesideIcon) #QObject.connect(self.cmdReset, SIGNAL("clicked()"), self.lsReset) QObject.connect(self.cmdResetZoom, SIGNAL('clicked()'), self.graph.ResetZoom) QObject.connect(self.cmdSaveData, SIGNAL('clicked()'), self.saveGraph) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.graphSignal) QObject.connect(self.cmdUpdateFrequency, SIGNAL("clicked()"), self.lsUpdateFrequency) QVBoxLayout(self, 5, 5) self.layout().addWidget(graphBox) self.layout().addWidget(self.topFrame) def graphSignal(self, dict): if dict['event'] == 'MouseAt': self.lblXY.setText("X = %.3f ; Y = %.3f" % (dict['x'], dict['y'])) def setStatus(self, status): self.lblStatus.setText("<nobr><h1>status: %s</h1></nobr>" % status) def updateFrequency(self, freq): self.lblUpdateFrequency.setText("<nobr><b>current = %d</b></nobr>" % freq) self.spnUpdateFrequency.setValue(freq) def propertyChanged(self, property, oldValue, newValue): if property == 'mnemonic': self.lakeshore = self.getHardwareObject(newValue) if self.lakeshore is not None: self.lakeshore.setUnit(self["unit"]) self.topFrame.setTitle("Lakeshore - %s" % self.lakeshore.getIdent()) self.updateFrequency(self.lakeshore.interval) for w in self.lstChannelWidgets: w.close(True) self.lstChannelValueDisplay = [] self.lstChannelWidgets = [] self.channelCheckboxCb = weakref.WeakKeyDictionary() for i in range(self.lakeshore.getChannelsNumber()): newCheckbox = QCheckBox("Channel %d" % (i + 1), self.channelsBox) self.lstChannelWidgets.append(newCheckbox) self.data[i] = None def checkbox_cb(state, channel=i): if state == QButton.On: self.data[channel] = {"x": [], "y": [], "t0": None} else: self.data[channel] = None self.channelCheckboxCb[newCheckbox] = checkbox_cb QObject.connect(newCheckbox, SIGNAL("stateChanged(int)"), checkbox_cb) newValueDisplayBrick = ValueDisplayBrick.ValueDisplayBrick( self.channelsBox, "channel%d" % i) self.lstChannelValueDisplay.append(newValueDisplayBrick) self.lstChannelWidgets.append( self.lstChannelValueDisplay[-1]) newValueDisplayBrick["unit"] = self["unit"] newValueDisplayBrick["valueLabel"] = "" newValueDisplayBrick["showSynoptic"] = False newValueDisplayBrick["showTitle"] = False newValueDisplayBrick["formatString"] = "+####.##" newValueDisplayBrick.show() self.connect(self.lakeshore, "statusChanged", self.setStatus) self.connect(self.lakeshore, "channelsUpdate", self.lsChannelsUpdated) self.connect(self.lakeshore, "intervalChanged", self.updateFrequency) elif property == "unit": if self.lakeshore is not None: self.lakeshore.setUnit(newValue) elif property == "baseTime": for channel, curve_data in self.data.items(): if curve_data is None: continue self.graph.delcurve("channel %d" % (channel + 1)) curve_data["x"] = [] curve_data["y"] = [] curve_data["t0"] = None def saveGraph(self): filename = str( QFileDialog.getSaveFileName(os.environ["HOME"], "Data file (*.dat *.txt)", self, "Save file", "Choose a filename to save under")) if len(filename) == 0: return try: f = open(filename, "w") except: logging.getLogger().exception( "An error occured while trying to open file %s", filename) QMessageBox.warning( self, "Error", "Could not open file %s for writing !" % filename, QMessageBox.Ok) else: contents = [ "#F Lakeshore temperatures", "#D %s" % time.ctime(time.time()) ] for channel, curve_data in self.data.items(): if curve_data is None: continue contents.append("\n#S %d %s" % (channel + 1, "channel %d" % (channel + 1))) contents.append("#N 2") contents.append("#L %s %s" % ("time (s)", "temperature")) for x, y in zip(curve_data["x"], curve_data["y"]): contents.append("%s %s" % (str(x), str(y))) contents.append("\n") try: try: f.write("\n".join(contents)) except: QMessageBox.warning( self, "Error", "Could not save file to\n%s" % filename, QMessageBox.Ok) else: QMessageBox.information( self, "Success", "Data have been saved successfully to\n%s" % filename, QMessageBox.Ok) finally: f.close() def lsChannelsUpdated(self, values): i = 0 t = None if self["baseTime"] == "0": t = time.time() try: t0 = min([ _f for _f in [ d["t0"] for d in [_f for _f in iter(self.data.values()) if _f] ] if _f ]) except ValueError: t0 = t for v in values: curve_name = "channel %d" % (i + 1) self.lstChannelValueDisplay[i].setValue(v) self.lstChannelValueDisplay[i]["unit"] = self["unit"] if self.data[i] is not None: if self.data[i]["t0"] is None: self.data[i]["t0"] = t if self["baseTime"] == "0": self.data[i]["x"].append(t - t0) else: # convert computer local time to seconds t = time.localtime() self.data[i]["x"].append( sum([t[n + 3] * (60**(2 - n)) for n in range(3)])) self.data[i]["y"].append(v) self.graph.newcurve(curve_name, self.data[i]["x"], self.data[i]["y"]) else: self.graph.delcurve(curve_name) i += 1 self.graph.replot() def lsReset(self): if self.lakeshore is not None: self.lakeshore.reset() def lsUpdateFrequency(self): new_freq = self.spnUpdateFrequency.value() if self.lakeshore is not None: self.lakeshore.setInterval(new_freq)
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 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 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 PymcaPlotWidget(qt_import.QWidget): def __init__(self, parent, realtime_plot=False): qt_import.QWidget.__init__(self, parent) self.axis_x_array = [] self.axis_y_array = [] self.realtime_plot = realtime_plot self.pymca_graph = Plot(self) self.pymca_graph.showGrid() self.info_label = qt_import.QLabel("", self) self.info_label.setAlignment(qt_import.Qt.AlignRight) _main_vlayout = qt_import.QVBoxLayout(self) _main_vlayout.addWidget(self.pymca_graph) _main_vlayout.addWidget(self.info_label) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(2, 2, 2, 2) self.setSizePolicy(qt_import.QSizePolicy.Expanding, qt_import.QSizePolicy.Expanding) if PYMCA_EXISTS: qt_import.QObject.connect( self.pymca_graph, qt_import.SIGNAL("QtBlissGraphSignal"), self.handle_graph_signal, ) colors.set_widget_color(self, colors.WHITE) def clear(self): self.pymca_graph.clearcurves() self.pymca_graph.setTitle("") self.info_label.setText("") def plot_energy_scan_curve(self, scan_result, scan_title): """Results are converted to two list describing x and y axes """ x_data = [item[0] for item in scan_result] y_data = [item[1] for item in scan_result] self.pymca_graph.newcurve("Energy", x_data, y_data) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_title) self.pymca_graph.setx1axislimits(min(x_data), max(x_data)) def start_new_scan(self, scan_info): self.axis_x_array = [] self.axis_y_array = [] self.pymca_graph.clearcurves() self.pymca_graph.xlabel(scan_info["xlabel"]) self.ylabel = scan_info["ylabel"] self.pymca_graph.ylabel(self.ylabel) self.pymca_graph.setx1timescale(False) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_info["title"]) def plot_energy_scan_results( self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title, ): self.pymca_graph.clearcurves() self.pymca_graph.setTitle(title) self.pymca_graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.pymca_graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.pymca_graph.replot() self.pymca_graph.setx1axislimits(min(chooch_graph_x), max(chooch_graph_x)) def plot_finished(self): if self.axis_x_array: self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) self.pymca_graph.replot() def add_new_plot_value(self, x, y): if self.realtime_plot: self.axis_x_array.append(x / 1000.0) self.axis_y_array.append(y / 1000.0) self.pymca_graph.newcurve("Energy", self.axis_x_array, self.axis_y_array) self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) # self.pymca_graph.replot() def handle_graph_signal(self, signal_info): if signal_info["event"] == "MouseAt": self.info_label.setText("(X: %0.2f, Y: %0.2f)" % (signal_info["x"], signal_info["y"]))
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 PymcaPlotWidget(QWidget): """ Descript. : """ def __init__(self, parent, realtime_plot = False): """ Descript. : """ QWidget.__init__(self, parent) self.axis_x_array = [] self.axis_y_array = [] self.realtime_plot = realtime_plot self.pymca_graph = Graph(self) self.pymca_graph.showGrid() self.info_label = QLabel("", self) self.info_label.setAlignment(Qt.AlignRight) _main_vlayout = QVBoxLayout(self) _main_vlayout.addWidget(self.pymca_graph) _main_vlayout.addWidget(self.info_label) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(2, 2, 2, 2) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) if qt_variant == 'PyQt5': pass else: QObject.connect(self.pymca_graph, SIGNAL("QtBlissGraphSignal"), self.handle_graph_signal) Qt4_widget_colors.set_widget_color(self, Qt4_widget_colors.WHITE) def clear(self): """ Descript. : """ self.pymca_graph.clearcurves() self.pymca_graph.setTitle("") self.info_label.setText("") def plot_energy_scan_curve(self, scan_result, scan_title): """Results are converted to two list describing x and y axes """ x_data = [item[0] for item in scan_result] y_data = [item[1] for item in scan_result] self.pymca_graph.newcurve("Energy", x_data, y_data) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_title) self.pymca_graph.setx1axislimits(min(x_data), max(x_data)) def start_new_scan(self, scan_info): """ Descript. : """ self.axis_x_array = [] self.axis_y_array = [] self.pymca_graph.clearcurves() self.pymca_graph.xlabel(scan_info['xlabel']) self.ylabel = scan_info['ylabel'] self.pymca_graph.ylabel(self.ylabel) self.pymca_graph.setx1timescale(False) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_info['title']) def plot_energy_scan_results(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title): """ """ self.pymca_graph.clearcurves() self.pymca_graph.setTitle(title) self.pymca_graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.pymca_graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.pymca_graph.replot() self.pymca_graph.setx1axislimits(min(chooch_graph_x), max(chooch_graph_x)) def plot_finished(self): """ Descript. : """ if self.axis_x_array: self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) self.pymca_graph.replot() def add_new_plot_value(self, x, y): """ Descript. : """ if self.realtime_plot: self.axis_x_array.append(x / 1000.0) self.axis_y_array.append(y / 1000.0) self.pymca_graph.newcurve("Energy", self.axis_x_array, self.axis_y_array) self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) #self.pymca_graph.replot() def handle_graph_signal(self, signal_info): """ """ if signal_info['event'] == 'MouseAt': self.info_label.setText("(X: %0.4f, Y: %0.4f)" % \ (signal_info['x'], signal_info['y']))
class PymcaPlotWidget(QWidget): """ Descript. : """ def __init__(self, parent, realtime_plot = False): """ Descript. : """ QWidget.__init__(self, parent) self.axis_x_array = [] self.axis_y_array = [] self.realtime_plot = realtime_plot self.pymca_graph = Graph(self) self.pymca_graph.showGrid() self.info_label = QLabel("", self) self.info_label.setAlignment(Qt.AlignRight) _main_vlayout = QVBoxLayout(self) _main_vlayout.addWidget(self.pymca_graph) _main_vlayout.addWidget(self.info_label) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(2, 2, 2, 2) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) if qt_variant == 'PyQt5': pass else: QObject.connect(self.pymca_graph, SIGNAL("QtBlissGraphSignal"), self.handle_graph_signal) Qt4_widget_colors.set_widget_color(self, Qt4_widget_colors.WHITE) def clear(self): """ Descript. : """ self.pymca_graph.clearcurves() self.pymca_graph.setTitle("") self.info_label.setText("") def plot_energy_scan_curve(self, scan_result, scan_title): """Results are converted to two list describing x and y axes """ x_data = [item[0] for item in scan_result] y_data = [item[1] for item in scan_result] self.pymca_graph.newcurve("Energy", x_data, y_data) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_title) self.pymca_graph.setx1axislimits(min(x_data), max(x_data)) def start_new_scan(self, scan_info): """ Descript. : """ self.axis_x_array = [] self.axis_y_array = [] self.pymca_graph.clearcurves() self.pymca_graph.xlabel(scan_info['xlabel']) self.ylabel = scan_info['ylabel'] self.pymca_graph.ylabel(self.ylabel) self.pymca_graph.setx1timescale(False) self.pymca_graph.replot() self.pymca_graph.setTitle(scan_info['title']) def plot_energy_scan_results(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title): """ """ self.pymca_graph.clearcurves() self.pymca_graph.setTitle(title) self.pymca_graph.newcurve("spline", chooch_graph_x, chooch_graph_y1) self.pymca_graph.newcurve("fp", chooch_graph_x, chooch_graph_y2) self.pymca_graph.replot() self.pymca_graph.setx1axislimits(min(chooch_graph_x), max(chooch_graph_x)) def plot_finished(self): """ Descript. : """ if self.axis_x_array: self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) self.pymca_graph.replot() def add_new_plot_value(self, x, y): """ Descript. : """ if self.realtime_plot: self.axis_x_array.append(x / 1000.0) self.axis_y_array.append(y / 1000.0) self.pymca_graph.newcurve("Energy", self.axis_x_array, self.axis_y_array) self.pymca_graph.setx1axislimits(min(self.axis_x_array), max(self.axis_x_array)) #self.pymca_graph.replot() def handle_graph_signal(self, signal_info): """ """ if signal_info['event'] == 'MouseAt': self.info_label.setText("(X: %0.2f, Y: %0.2f)" % \ (signal_info['x'], signal_info['y']))
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 LakeshoreBrick(BlissWidget): def __init__(self, *args): BlissWidget.__init__(self, *args) self.addProperty("mnemonic", "string", "") self.addProperty("unit", "combo", ("C", "K"), "C") self.addProperty("baseTime", "combo", ("current time", "0"), "0") self.lstChannelValueDisplay = [] self.lstChannelWidgets = [] self.data = {} self.lakeshore = None graphBox = QVBox(self) graphButtonsBox = QHBox(graphBox) graphButtonsBox.setSpacing(5) self.graph = QtBlissGraph(graphBox) self.graph.setx1timescale(True) self.graph.xlabel("time") self.graph.ylabel("temperature (%s)" % self["unit"]) self.graph.setPaletteBackgroundColor(Qt.white) self.graph.canvas().setMouseTracking(True) self.cmdResetZoom = QPushButton("Reset zoom", graphButtonsBox) self.lblXY = QLabel("X = ? ; Y = ?", graphButtonsBox) HorizontalSpacer(graphButtonsBox) self.cmdSaveData = QToolButton(graphButtonsBox) self.cmdSaveData.setUsesTextLabel(True) self.cmdSaveData.setTextLabel("Save data to file") self.cmdSaveData.setIconSet(QIconSet(Icons.load("save"))) self.cmdSaveData.setTextPosition(QToolButton.BesideIcon) self.topFrame = QVGroupBox("Lakeshore - ", self) updateFreqBox = QHBox(self.topFrame) updateFreqBox.setSpacing(5) QLabel("Update frequency : every", updateFreqBox) self.spnUpdateFrequency = QSpinBox(64, 30000, 500, updateFreqBox) QLabel("millisecond", updateFreqBox) self.lblUpdateFrequency = QLabel("<nobr><b>current = ?</b></nobr>", updateFreqBox) self.cmdUpdateFrequency = QPushButton("Change", updateFreqBox) HorizontalSpacer(updateFreqBox) self.lblStatus = QLabel("<h1>status</h1>", self.topFrame) self.lblStatus.setAlignment(Qt.AlignCenter) innerBox = QVBox(self.topFrame) self.channelsBox = QGrid(8, innerBox) self.channelsBox.setSpacing(5) self.channelsBox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) commandsBox = QVBox(innerBox) VerticalSpacer(self.topFrame) resetBox = QHBox(self.topFrame) HorizontalSpacer(resetBox) #self.cmdReset = QToolButton(resetBox) #self.cmdReset.setUsesTextLabel(True) #self.cmdReset.setTextLabel("Reset instrument") #self.cmdReset.setIconSet(QIconSet(Icons.load("reload"))) #self.cmdReset.setTextPosition(QToolButton.BesideIcon) #QObject.connect(self.cmdReset, SIGNAL("clicked()"), self.lsReset) QObject.connect(self.cmdResetZoom, SIGNAL('clicked()'), self.graph.ResetZoom) QObject.connect(self.cmdSaveData, SIGNAL('clicked()'), self.saveGraph) QObject.connect(self.graph, PYSIGNAL('QtBlissGraphSignal'), self.graphSignal) QObject.connect(self.cmdUpdateFrequency, SIGNAL("clicked()"), self.lsUpdateFrequency) QVBoxLayout(self, 5, 5) self.layout().addWidget(graphBox) self.layout().addWidget(self.topFrame) def graphSignal(self, dict): if dict['event'] == 'MouseAt': self.lblXY.setText("X = %.3f ; Y = %.3f" % (dict['x'], dict['y'])) def setStatus(self, status): self.lblStatus.setText("<nobr><h1>status: %s</h1></nobr>" % status) def updateFrequency(self, freq): self.lblUpdateFrequency.setText("<nobr><b>current = %d</b></nobr>" % freq) self.spnUpdateFrequency.setValue(freq) def propertyChanged(self, property, oldValue, newValue): if property == 'mnemonic': self.lakeshore = self.getHardwareObject(newValue) if self.lakeshore is not None: self.lakeshore.setUnit(self["unit"]) self.topFrame.setTitle("Lakeshore - %s" % self.lakeshore.getIdent()) self.updateFrequency(self.lakeshore.interval) for w in self.lstChannelWidgets: w.close(True) self.lstChannelValueDisplay = [] self.lstChannelWidgets = [] self.channelCheckboxCb = weakref.WeakKeyDictionary() for i in range(self.lakeshore.getChannelsNumber()): newCheckbox = QCheckBox("Channel %d" % (i+1), self.channelsBox) self.lstChannelWidgets.append(newCheckbox) self.data[i]=None def checkbox_cb(state, channel=i): if state == QButton.On: self.data[channel]={ "x":[], "y":[], "t0": None } else: self.data[channel]=None self.channelCheckboxCb[newCheckbox] = checkbox_cb QObject.connect(newCheckbox, SIGNAL("stateChanged(int)"), checkbox_cb) newValueDisplayBrick = ValueDisplayBrick.ValueDisplayBrick(self.channelsBox, "channel%d" % i) self.lstChannelValueDisplay.append(newValueDisplayBrick) self.lstChannelWidgets.append(self.lstChannelValueDisplay[-1]) newValueDisplayBrick["unit"] = self["unit"] newValueDisplayBrick["valueLabel"]="" newValueDisplayBrick["showSynoptic"] = False newValueDisplayBrick["showTitle"] = False newValueDisplayBrick["formatString"]="+####.##" newValueDisplayBrick.show() self.connect(self.lakeshore, "statusChanged", self.setStatus) self.connect(self.lakeshore, "channelsUpdate", self.lsChannelsUpdated) self.connect(self.lakeshore, "intervalChanged", self.updateFrequency) elif property == "unit": if self.lakeshore is not None: self.lakeshore.setUnit(newValue) elif property == "baseTime": for channel, curve_data in self.data.items(): if curve_data is None: continue self.graph.delcurve("channel %d" % (channel+1)) curve_data["x"]=[] curve_data["y"]=[] curve_data["t0"]=None def saveGraph(self): filename = str(QFileDialog.getSaveFileName(os.environ["HOME"], "Data file (*.dat *.txt)", self, "Save file", "Choose a filename to save under")) if len(filename) == 0: return try: f = open(filename, "w") except: logging.getLogger().exception("An error occured while trying to open file %s", filename) QMessageBox.warning(self, "Error", "Could not open file %s for writing !" % filename, QMessageBox.Ok) else: contents = ["#F Lakeshore temperatures", "#D %s" % time.ctime(time.time())] for channel, curve_data in self.data.items(): if curve_data is None: continue contents.append("\n#S %d %s" % (channel+1, "channel %d" % (channel+1))) contents.append("#N 2") contents.append("#L %s %s" % ("time (s)", "temperature")) for x, y in zip(curve_data["x"], curve_data["y"]): contents.append("%s %s" % (str(x), str(y))) contents.append("\n") try: try: f.write("\n".join(contents)) except: QMessageBox.warning(self, "Error", "Could not save file to\n%s" % filename, QMessageBox.Ok) else: QMessageBox.information(self, "Success", "Data have been saved successfully to\n%s" % filename, QMessageBox.Ok) finally: f.close() def lsChannelsUpdated(self, values): i = 0 t = None if self["baseTime"] == "0": t = time.time() try: t0 = min([_f for _f in [d["t0"] for d in [_f for _f in iter(self.data.values()) if _f]] if _f]) except ValueError: t0 = t for v in values: curve_name = "channel %d" % (i+1) self.lstChannelValueDisplay[i].setValue(v) self.lstChannelValueDisplay[i]["unit"] = self["unit"] if self.data[i] is not None: if self.data[i]["t0"] is None: self.data[i]["t0"] = t if self["baseTime"] == "0": self.data[i]["x"].append(t-t0) else: # convert computer local time to seconds t = time.localtime() self.data[i]["x"].append(sum([t[n+3]*(60**(2-n)) for n in range(3)])) self.data[i]["y"].append(v) self.graph.newcurve(curve_name, self.data[i]["x"], self.data[i]["y"]) else: self.graph.delcurve(curve_name) i += 1 self.graph.replot() def lsReset(self): if self.lakeshore is not None: self.lakeshore.reset() def lsUpdateFrequency(self): new_freq = self.spnUpdateFrequency.value() if self.lakeshore is not None: self.lakeshore.setInterval(new_freq)
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