Esempio n. 1
0
class EnergyScanBrick(BlissWidget):
    STATES = {
        'error': QWidget.red,\
        'ok': QWidget.green,\
        'progress': QWidget.yellow
    }

    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.energyScan = None
        #self.scanObject = None
        self.element = None

        self.sessionId = None
        self.blSampleId = None
        self.scanParameters = {}
        self.archive_directory = None

        self.addProperty('mnemonic', 'string', '')
        self.addProperty('icons', 'string', '')
        self.addProperty('formatString', 'formatString', '##.####')
        self.addProperty('decimalPlaces', 'string', '4')

        self.defineSlot('setDirectory', ())
        self.defineSlot('setPrefix', ())
        self.defineSlot('setElement', ())
        self.defineSlot('setSample', ())
        self.defineSlot('setSession', ())

        self.defineSignal('energyScanning', ())
        self.defineSignal('energyScanConnected', ())
        self.defineSignal('energyScanCanMove', ())
        self.defineSignal('edgeScanEnergies', ())

        self.parametersBox = QHGroupBox("Parameters", self)
        self.parametersBox.hide()
        self.parametersBox.setInsideMargin(4)
        self.parametersBox.setInsideSpacing(2)
        self.parametersBox.setCheckable(True)
        self.parametersBox.setChecked(False)

        QLabel("Prefix:", self.parametersBox)
        self.prefixInput = QLineEdit(self.parametersBox)
        self.prefixInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        QObject.connect(self.prefixInput,
                        SIGNAL('textChanged(const QString &)'),
                        self.prefixChanged)
        QLabel("Directory:", self.parametersBox)
        self.directoryInput = QLineEdit(self.parametersBox)
        self.directoryInput.setSizePolicy(QSizePolicy.Expanding,
                                          QSizePolicy.Fixed)
        QObject.connect(self.directoryInput,
                        SIGNAL('textChanged(const QString &)'),
                        self.directoryChanged)

        self.browseButton = QToolButton(self.parametersBox)
        self.browseButton.setTextLabel("Browse")
        self.browseButton.setUsesTextLabel(True)
        self.browseButton.setTextPosition(QToolButton.BesideIcon)
        QObject.connect(self.browseButton, SIGNAL("clicked()"),
                        self.browseButtonClicked)

        self.scanBox = QHGroupBox("Energy scan", self)
        self.scanBox.setInsideMargin(4)
        self.scanBox.setInsideSpacing(2)
        self.scanBox.hide()
        self.startScanButton = MenuButton(self.scanBox, "Start scan")
        self.startScanButton.hide()
        self.connect(self.startScanButton, PYSIGNAL('executeCommand'),
                     self.startEnergyScan)
        self.connect(self.startScanButton, PYSIGNAL('cancelCommand'),
                     self.cancelEnergyScan)

        self.statusBox = QHGroupBox("(no element)", self.scanBox)
        self.statusBox.hide()
        #self.statusBox.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.MinimumExpanding)
        self.statusBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.statusBox.setAlignment(QGroupBox.AlignCenter)
        self.scanStatus = QLabel(self.statusBox)
        self.scanStatus.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.MinimumExpanding)
        self.scanStatus.setAlignment(QLabel.AlignCenter)

        box4 = QVBox(self.scanBox)
        peakLabel = QLabel("Peak:", box4)
        peakLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev1Label = QLabel("(keV)", box4)
        kev1Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        #kev2Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.peakInput = shortLineEdit(self.scanBox)
        self.peakInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.peakInput.setValidator(QDoubleValidator(self))

        box5 = QVBox(self.scanBox)
        inflectionLabel = QLabel("Inflection:", box5)
        inflectionLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev2Label = QLabel("(keV)", box5)
        kev2Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        #kev1Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.inflectionInput = shortLineEdit(self.scanBox)
        self.inflectionInput.setSizePolicy(QSizePolicy.Minimum,
                                           QSizePolicy.Fixed)
        self.inflectionInput.setValidator(QDoubleValidator(self))

        box6 = QVBox(self.scanBox)
        remoteLabel = QLabel("Remote:", box6)
        remoteLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev3Label = QLabel("(keV)", box6)
        kev3Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        #kev3Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.remoteInput = shortLineEdit(self.scanBox)
        self.remoteInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.remoteInput.setValidator(QDoubleValidator(self))

        box7 = QVBox(self.scanBox)
        remoteLabel = QLabel("2nd Remote:", box7)
        remoteLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev4Label = QLabel("(keV)", box7)
        kev4Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        #kev4Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.remote2Input = shortLineEdit(self.scanBox)
        self.remote2Input.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.remote2Input.setValidator(QDoubleValidator(self))

        self.acceptBox = QVBox(self.scanBox)
        self.acceptBox.setSpacing(2)
        self.acceptButton = MenuButton2(self.acceptBox, "Accept")
        self.resetButton = MenuButton2(self.acceptBox, "Reset")
        self.acceptBox.hide()
        QObject.connect(self.resetButton, SIGNAL('clicked()'),
                        self.resetEnergies)
        QObject.connect(self.acceptButton, SIGNAL('clicked()'),
                        self.acceptEnergies)

        self.parametersBox.setSizePolicy(QSizePolicy.MinimumExpanding,
                                         QSizePolicy.Fixed)
        self.scanBox.setSizePolicy(QSizePolicy.MinimumExpanding,
                                   QSizePolicy.Fixed)
        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)

        self.instanceSynchronize("parametersBox", "prefixInput",
                                 "directoryInput", "peakInput",
                                 "inflectionInput", "remoteInput",
                                 "remote2Input")

        self.choochGraphs = QtBlissGraph(self)
        self.choochGraphs.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Fixed)

        QVBoxLayout(self)
        self.layout().addWidget(self.parametersBox)
        self.layout().addWidget(self.scanBox)
        self.layout().addWidget(self.choochGraphs)

        self.setEnabled(False)

    def setIcons(self, icons):
        icons_list = icons.split()
        try:
            self.startScanButton.setIcons(icons_list[0], icons_list[1])
        except IndexError:
            pass
        try:
            self.acceptButton.setPixmap(Icons.load(icons_list[2]))
        except IndexError:
            pass
        try:
            self.resetButton.setPixmap(Icons.load(icons_list[3]))
        except IndexError:
            pass
        try:
            self.browseButton.setPixmap(Icons.load(icons_list[4]))
        except IndexError:
            pass

    def prefixChanged(self, txt):
        txt = str(txt).replace(" ", "_")
        self.prefixInput.setText(txt)

    def directoryChanged(self, txt):
        txt = str(txt).replace(" ", "_")
        self.directoryInput.setText(txt)

    def browseButtonClicked(self):
        get_dir = QFileDialog(self)
        s = self.font().pointSize()
        f = get_dir.font()
        f.setPointSize(s)
        get_dir.setFont(f)
        get_dir.updateGeometry()
        d=get_dir.getExistingDirectory(self.directoryInput.text(),self,"",\
            "Select a directory",True,False)
        if d is not None and len(d) > 0:
            self.setDirectory(d)

    def setSample(self, samples_list):
        #print "EnergyScanBrick.setSample",samples_list
        if len(samples_list) == 0:
            self.blSampleId = None
        else:
            if len(samples_list) > 1:
                logging.getLogger().warning(
                    "EnergyScanBrick: multiple samples selected (attaching scan only to first sample)!"
                )
            for sample in samples_list:
                try:
                    blsample_id = int(sample[0])
                except:
                    pass
                else:
                    self.blSampleId = blsample_id
                    break

    def setSession(self,
                   session_id,
                   prop_code=None,
                   prop_number=None,
                   prop_id=None,
                   expiration_time=0):
        #print "EnergyScanBrick.setSession",session_id
        self.sessionId = session_id
        if prop_code is None or prop_number is None:
            pass
        else:
            self.archive_directory = str(prop_code) + str(prop_number)

    def setDirectory(self, scan_dir):
        self.directoryInput.setText(scan_dir)

    def setPrefix(self, scan_prefix):
        self.prefixInput.setText(scan_prefix)

    def setElement(self, symbol, edge):
        #print "ENERGYSCANBRICK.setElement",symbol,edge
        if symbol is None:
            self.clearEnergies()
            self.setEnabled(False)
            self.element = None
        else:
            if self.energyScan is not None and self.energyScan.canScanEnergy():
                self.setEnabled(True)
            self.element = (symbol, edge)

    def resetEnergies(self):
        confirm_dialog=QMessageBox("Confirm reset",\
            "This will also clear your energies in the Collect tab. Press OK to reset the energies.",\
            QMessageBox.Warning,QMessageBox.Ok,QMessageBox.Cancel,\
            QMessageBox.NoButton,self)

        s = self.font().pointSize()
        f = confirm_dialog.font()
        f.setPointSize(s)
        confirm_dialog.setFont(f)
        confirm_dialog.updateGeometry()

        if confirm_dialog.exec_loop() == QMessageBox.Ok:
            self.inflectionInput.setText("")
            self.peakInput.setText("")
            self.remoteInput.setText("")
            self.remote2Input.setText("")
            self.emit(PYSIGNAL('edgeScanEnergies'), ({}, ))

    def acceptEnergies(self):
        if self.peakInput.hasAcceptableInput():
            pk = float(self.peakInput.text())
        else:
            pk = None
        if self.inflectionInput.hasAcceptableInput():
            ip = float(self.inflectionInput.text())
        else:
            ip = None
        if self.remoteInput.hasAcceptableInput():
            rm = float(self.remoteInput.text())
        else:
            rm = None
        if self.remote2Input.hasAcceptableInput():
            rm2 = float(self.remote2Input.text())
        else:
            rm2 = None
        energies = {"pk": pk, "ip": ip, "rm": rm, "rm2": rm2}
        self.emit(PYSIGNAL('edgeScanEnergies'), (energies, ))

    def propertyChanged(self, propertyName, oldValue, newValue):
        if propertyName == 'mnemonic':
            if self.energyScan is not None:
                self.disconnect(self.energyScan, 'energyScanStarted',
                                self.scanStarted)
                self.disconnect(self.energyScan, 'energyScanFinished',
                                self.scanFinished)
                self.disconnect(self.energyScan, 'energyScanFailed',
                                self.scanFailed)
                self.disconnect(self.energyScan, 'scanStatusChanged',
                                self.scanStatusChanged)
                self.disconnect(self.energyScan, 'energyScanReady',
                                self.scanReady)
                self.disconnect(self.energyScan, 'connected', self.connected)
                self.disconnect(self.energyScan, 'disconnected',
                                self.disconnected)

            self.clearEnergies()
            self.energyScan = self.getHardwareObject(newValue)
            if self.energyScan is not None:
                self.connect(self.energyScan, 'energyScanStarted',
                             self.scanStarted)
                self.connect(self.energyScan, 'energyScanFinished',
                             self.scanFinished)
                self.connect(self.energyScan, 'energyScanFailed',
                             self.scanFailed)
                self.connect(self.energyScan, 'scanStatusChanged',
                             self.scanStatusChanged)
                self.connect(self.energyScan, 'energyScanReady',
                             self.scanReady)
                self.connect(self.energyScan, 'connected', self.connected)
                self.connect(self.energyScan, 'disconnected',
                             self.disconnected)
                self.connect(self.energyScan, 'chooch_finished',
                             self.chooch_finished)

                if self.energyScan.isConnected():
                    self.connected()
                else:
                    self.disconnected()
            else:
                self.disconnected()

        elif propertyName == 'icons':
            self.setIcons(newValue)
        else:
            BlissWidget.propertyChanged(self, propertyName, oldValue, newValue)

    def run(self):
        logging.getLogger().info(
            "Anonmalous Scattering Factors determination based on Chooch 5.0.6 by Gwyndaf Evans\nCopyright (C) 1994--2007\[email protected]\nG. Evans & R. F. Pettifer (2001)\nJ. Appl. Cryst. 34, 82-86."
        )

        if self.energyScan is not None:
            if self.energyScan.isConnected():
                self.connected()
            else:
                self.disconnected()
        else:
            self.disconnected()

    def connected(self):
        can_scan = self.energyScan.canScanEnergy()
        if self.element is not None:
            self.setEnabled(can_scan)
        else:
            self.setEnabled(False)
        self.emit(PYSIGNAL('energyScanConnected'), (True, can_scan))
        self.emit(PYSIGNAL('energyScanCanMove'), (can_scan, ))

    def disconnected(self):
        self.setEnabled(False)
        self.emit(PYSIGNAL('energyScanConnected'), (False, ))
        self.emit(PYSIGNAL('energyScanCanMove'), (False, ))

    def scanReady(self, state):
        self.startScanButton.setEnabled(state)
        self.statusBox.setEnabled(state)

    def scanStatusChanged(self, msg=None):
        if msg is None:
            msg = ""
            color = self.scanBox.paletteBackgroundColor()
        else:
            color = EnergyScanBrick.STATES['progress']
        self.scanStatus.setText(str(msg))
        self.scanStatus.setPaletteBackgroundColor(QColor(color))

    def startEnergyScan(self):
        self.scanParameters = {}
        go_on = True
        if self.sessionId is None or self.sessionId == "":
            res = QMessageBox.question(
                self, 'Energy scan',
                "You are not properly logged, therefore your scan won't be stored in ISPyB.\nProceed with the energy scan?",
                "Proceed", "Cancel")
            if res != 0:
                go_on = False
        if not go_on:
            self.startScanButton.commandFailed()
            return

        if self.sessionId is not None and self.sessionId != "":
            self.scanParameters["sessionId"] = self.sessionId
            self.scanParameters["element"] = self.element[0]
            self.scanParameters["edgeEnergy"] = self.element[1]
            self.scanParameters["startTime"] = time.strftime(
                "%Y-%m-%d %H:%M:%S")

        self.statusBox.setTitle("%s - %s" % (self.element[0], self.element[1]))
        self.inflectionInput.setText("")
        self.peakInput.setText("")
        self.remoteInput.setText("")
        self.remote2Input.setText("")

        #print("Calling self.energyScan.startEnergyScan...")
        scan_result=self.energyScan.startEnergyScan(self.element[0],self.element[1],\
            str(self.directoryInput.text()),\
            str(self.prefixInput.text()),\
            self.sessionId,self.blSampleId)
        if not scan_result:
            self.scanFailed()

    def cancelEnergyScan(self):
        self.energyScan.cancelEnergyScan()

    def scanStarted(self):
        self.choochGraphs.newcurve("spline", [], [])
        self.choochGraphs.newcurve("fp", [], [])
        self.choochGraphs.replot()

        self.startScanButton.commandStarted()
        self.emit(PYSIGNAL("energyScanning"), (True, ))
        self.parametersBox.setEnabled(False)
        self.acceptBox.setEnabled(False)
        self.inflectionInput.setEnabled(False)
        self.peakInput.setEnabled(False)
        self.remoteInput.setEnabled(False)
        self.remote2Input.setEnabled(False)

    def scanFailed(self):
        color = EnergyScanBrick.STATES['error']
        self.scanStatus.setPaletteBackgroundColor(QColor(color))
        self.startScanButton.commandFailed()
        self.emit(PYSIGNAL("energyScanning"), (False, ))
        self.parametersBox.setEnabled(True)
        self.acceptBox.setEnabled(True)
        self.inflectionInput.setEnabled(True)
        self.peakInput.setEnabled(True)
        self.remoteInput.setEnabled(True)
        self.remote2Input.setEnabled(True)

    def chooch_finished(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm,
                        chooch_graph_x, chooch_graph_y1, chooch_graph_y2,
                        title):
        # display Chooch graphs
        self.choochGraphs.setTitle(title)
        self.choochGraphs.newcurve("spline", chooch_graph_x, chooch_graph_y1)
        self.choochGraphs.newcurve("fp", chooch_graph_x, chooch_graph_y2)
        self.choochGraphs.replot()

    def scanFinished(self, *args):
        pass

    def clearEnergies(self):
        self.inflectionInput.setText("")
        self.peakInput.setText("")
        self.remoteInput.setText("")
        self.remote2Input.setText("")
        self.statusBox.setTitle("(no element)")
Esempio n. 2
0
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")
Esempio n. 3
0
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"]))
Esempio n. 4
0
class EnergyScanBrickPX2(BlissWidget):
    STATES = {
        'error': QWidget.red,
        'ok': QWidget.green,
        'progress': QWidget.yellow
    }

    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.energyScan = None
        self.scanObject = None
        self.element = None

        self.sessionId = None
        self.blSampleId = None
        self.scanParameters = {}
        self.archive_directory = None

        self.addProperty('mnemonic', 'string', '')
        self.addProperty('icons', 'string', '')
        self.addProperty('formatString', 'formatString', '##.####')
        self.addProperty('decimalPlaces', 'string', '4')

        self.defineSlot('setDirectory', ())
        self.defineSlot('setPrefix', ())
        self.defineSlot('setElement', ())
        self.defineSlot('setSample', ())
        self.defineSlot('setSession', ())

        self.defineSignal('energyScanning', ())
        self.defineSignal('energyScanConnected', ())
        self.defineSignal('energyScanCanMove', ())
        self.defineSignal('edgeScanEnergies', ())
        self.defineSignal('addNewPoint', ())
        self.defineSignal('newScan', ())
        self.defineSignal('setDirectory', ())
        self.defineSignal('setValues', ())

        self.parametersBox = QHGroupBox("Parameters", self)
        # self.parametersBox.hide()
        self.parametersBox.setInsideMargin(4)
        self.parametersBox.setInsideSpacing(2)
        self.parametersBox.setCheckable(True)
#        self.parametersBox.setChecked(False)
        self.parametersBox.setChecked(True)

        QLabel("Prefix:", self.parametersBox)
        self.prefixInput = QLineEdit(self.parametersBox)
        self.prefixInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        QObject.connect(
            self.prefixInput,
            SIGNAL('textChanged(const QString &)'),
            self.prefixChanged)
        QLabel("Directory:", self.parametersBox)
        self.directoryInput = QLineEdit(self.parametersBox)
        self.directoryInput.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        QObject.connect(
            self.directoryInput,
            SIGNAL('textChanged(const QString &)'),
            self.directoryChanged)

        self.browseButton = QToolButton(self.parametersBox)
        self.browseButton.setTextLabel("Browse")
        self.browseButton.setUsesTextLabel(True)
        self.browseButton.setTextPosition(QToolButton.BesideIcon)
        QObject.connect(
            self.browseButton,
            SIGNAL("clicked()"),
            self.browseButtonClicked)

        self.scanBox = QHGroupBox("Energy scan", self)
        self.scanBox.setInsideMargin(4)
        self.scanBox.setInsideSpacing(2)
        # self.scanBox.hide()
        self.startScanButton = MenuButton(self.scanBox, "Start scan")
        # self.startScanButton.hide()
        self.connect(
            self.startScanButton,
            PYSIGNAL('executeCommand'),
            self.startEnergyScan)
        self.connect(
            self.startScanButton,
            PYSIGNAL('cancelCommand'),
            self.cancelEnergyScan)

        self.statusBox = QHGroupBox("(no element)", self.scanBox)
        # self.statusBox.hide()
        # self.statusBox.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.MinimumExpanding)
        self.statusBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.statusBox.setAlignment(QGroupBox.AlignCenter)
        self.scanStatus = QLabel(self.statusBox)
        self.scanStatus.setSizePolicy(
            QSizePolicy.Expanding,
            QSizePolicy.MinimumExpanding)
        self.scanStatus.setAlignment(QLabel.AlignCenter)

        box4 = QVBox(self.scanBox)
        peakLabel = QLabel("Peak:", box4)
        peakLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev1Label = QLabel("(keV)", box4)
        kev1Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        # kev2Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.peakInput = shortLineEdit(self.scanBox)
        self.peakInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.peakInput.setValidator(QDoubleValidator(self))

        box5 = QVBox(self.scanBox)
        inflectionLabel = QLabel("Inflection:", box5)
        inflectionLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev2Label = QLabel("(keV)", box5)
        kev2Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        # kev1Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.inflectionInput = shortLineEdit(self.scanBox)
        self.inflectionInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.inflectionInput.setValidator(QDoubleValidator(self))

        box6 = QVBox(self.scanBox)
        remoteLabel = QLabel("Remote:", box6)
        remoteLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev3Label = QLabel("(keV)", box6)
        kev3Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        # kev3Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.remoteInput = shortLineEdit(self.scanBox)
        self.remoteInput.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.remoteInput.setValidator(QDoubleValidator(self))

        box7 = QVBox(self.scanBox)
        remoteLabel = QLabel("2nd Remote:", box7)
        remoteLabel.setAlignment(QLabel.AlignHCenter | QLabel.AlignBottom)
        kev4Label = QLabel("(keV)", box7)
        kev4Label.setAlignment(QLabel.AlignHCenter | QLabel.AlignTop)
        # kev4Label.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Fixed)
        self.remote2Input = shortLineEdit(self.scanBox)
        self.remote2Input.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.remote2Input.setValidator(QDoubleValidator(self))

        self.acceptBox = QVBox(self.scanBox)
        self.acceptBox.setSpacing(2)
        self.acceptButton = MenuButton2(self.acceptBox, "Accept")
        self.resetButton = MenuButton2(self.acceptBox, "Reset")
        # self.acceptBox.hide()
        QObject.connect(self.resetButton, SIGNAL('clicked()'), self.resetEnergies)
        QObject.connect(self.acceptButton, SIGNAL('clicked()'), self.acceptEnergies)

        self.parametersBox.setSizePolicy(
            QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        self.scanBox.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)

        self.instanceSynchronize(
            "parametersBox",
            "prefixInput",
            "directoryInput",
            "peakInput",
            "inflectionInput",
            "remoteInput",
            "remote2Input")

        self.choochGraphs = QtBlissGraph(self)
        self.choochGraphs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)

        QVBoxLayout(self)
        self.layout().addWidget(self.parametersBox)
        self.layout().addWidget(self.scanBox)
        self.layout().addWidget(self.choochGraphs)

        self.setEnabled(True)

    def setIcons(self, icons):
        icons_list = icons.split()
        try:
            self.startScanButton.setIcons(icons_list[0], icons_list[1])
        except IndexError:
            pass
        try:
            self.acceptButton.setPixmap(Icons.load(icons_list[2]))
        except IndexError:
            pass
        try:
            self.resetButton.setPixmap(Icons.load(icons_list[3]))
        except IndexError:
            pass
        try:
            self.browseButton.setPixmap(Icons.load(icons_list[4]))
        except IndexError:
            pass

    def prefixChanged(self, txt):
        txt = str(txt).replace(" ", "_")
        self.prefixInput.setText(txt)

    def directoryChanged(self, txt):
        txt = str(txt).replace(" ", "_")
        self.directoryInput.setText(txt)

    def browseButtonClicked(self):
        get_dir = QFileDialog(self)
        s = self.font().pointSize()
        f = get_dir.font()
        f.setPointSize(s)
        get_dir.setFont(f)
        get_dir.updateGeometry()
        d = get_dir.getExistingDirectory(self.directoryInput.text(), self, "",
                                         "Select a directory", True, False)
        if d is not None and len(d) > 0:
            self.setDirectory(d)

    def setSample(self, samples_list):
        #print "EnergyScanBrick.setSample",samples_list
        if len(samples_list) == 0:
            self.blSampleId = None
        else:
            if len(samples_list) > 1:
                logging.getLogger().warning(
                    "EnergyScanBrick: multiple samples selected (attaching scan only to first sample)!")
            for sample in samples_list:
                try:
                    blsample_id = int(sample[0])
                except BaseException:
                    pass
                else:
                    self.blSampleId = blsample_id
                    break

    def setSession(self, session_id, prop_code=None,
                   prop_number=None, prop_id=None, expiration_time=0):
        #print "EnergyScanBrick.setSession",session_id
        self.sessionId = session_id
        if prop_code is None or prop_number is None:
            pass
        else:
            self.archive_directory = str(prop_code) + str(prop_number)

    def setDirectory(self, scan_dir):
        self.directoryInput.setText(scan_dir)

    def setPrefix(self, scan_prefix):
        self.prefixInput.setText(scan_prefix)

    def setElement(self, symbol, edge):
        logging.getLogger().info("ENERGYSCANBRICK.setElement %s, %s" % (symbol, edge))
        if symbol is None:
            self.clearEnergies()
            self.setEnabled(False)
            self.element = None
        else:
            if self.energyScan is not None and self.energyScan.canScanEnergy():
                self.setEnabled(True)
            self.element = (symbol, edge)
            self.statusBox.setTitle("%s - %s" % (self.element[0], self.element[1]))

    def resetEnergies(self):
        confirm_dialog = QMessageBox("Confirm reset",
                                     "This will also clear your energies in the Collect tab. Press OK to reset the energies.",
                                     QMessageBox.Warning, QMessageBox.Ok, QMessageBox.Cancel,
                                     QMessageBox.NoButton, self)

        s = self.font().pointSize()
        f = confirm_dialog.font()
        f.setPointSize(s)
        confirm_dialog.setFont(f)
        confirm_dialog.updateGeometry()

        if confirm_dialog.exec_loop() == QMessageBox.Ok:
            self.inflectionInput.setText("")
            self.peakInput.setText("")
            self.remoteInput.setText("")
            self.remote2Input.setText("")
            self.emit(PYSIGNAL('edgeScanEnergies'), ({},))

    def acceptEnergies(self):
        if self.peakInput.hasAcceptableInput():
            pk = float(self.peakInput.text())
        else:
            pk = None
        if self.inflectionInput.hasAcceptableInput():
            ip = float(self.inflectionInput.text())
        else:
            ip = None
        if self.remoteInput.hasAcceptableInput():
            rm = float(self.remoteInput.text())
        else:
            rm = None
        if self.remote2Input.hasAcceptableInput():
            rm2 = float(self.remote2Input.text())
        else:
            rm2 = None
        energies = {"pk": pk, "ip": ip, "rm": rm, "rm2": rm2}
        self.emit(PYSIGNAL('edgeScanEnergies'), (energies,))

    def propertyChanged(self, propertyName, oldValue, newValue):
        if propertyName == 'mnemonic':
            if self.energyScan is not None:
                self.disconnect(self.energyScan, 'energyScanStarted', self.scanStarted)
                self.disconnect(
                    self.energyScan,
                    'energyScanFinished2',
                    self.scanFinished)
                self.disconnect(self.energyScan, 'energyScanFailed', self.scanFailed)
                self.disconnect(
                    self.energyScan,
                    'scanStatusChanged',
                    self.scanStatusChanged)
                self.disconnect(self.energyScan, 'energyScanReady', self.scanReady)
                self.disconnect(self.energyScan, 'connected', self.connected)
                self.disconnect(self.energyScan, 'disconnected', self.disconnected)
                self.disconnect(self.energyScan, 'addNewPoint', self.addNewPoint)
                self.disconnect(self.energyScan, 'newScan', self.newScan)
                self.disconnect(self.energyScan, 'setElement', self.setElement)
                self.disconnect(self.energyScan, 'setDirectory', self.setDirectory)

            self.clearEnergies()
            self.energyScan = self.getHardwareObject(newValue)
            if self.energyScan is not None:
                self.scanObject = None
                # try:
                #  specversion = self.energyScan.getCommandObject("doEnergyScan").specVersion
                # except:
                #  logging.getLogger().exception("%s: could not get spec version from Energy Scan Hardware Object", self.name())
                # else:
                #  self.scanObject = QSpecScan(specversion)

                self.connect(self.energyScan, 'energyScanStarted', self.scanStarted)
                self.connect(self.energyScan, 'energyScanFinished2', self.scanFinished)
                self.connect(self.energyScan, 'energyScanFailed', self.scanFailed)
                self.connect(
                    self.energyScan,
                    'scanStatusChanged',
                    self.scanStatusChanged)
                self.connect(self.energyScan, 'energyScanReady', self.scanReady)
                self.connect(self.energyScan, 'connected', self.connected)
                self.connect(self.energyScan, 'disconnected', self.disconnected)
                self.connect(self.energyScan, 'chooch_finished', self.chooch_finished)
                self.connect(self.energyScan, 'addNewPoint', self.addNewPoint)
                self.connect(self.energyScan, 'newScan', self.newScan)
                self.connect(self.energyScan, 'setElement', self.setElement)
                self.connect(self.energyScan, 'setDirectory', self.setDirectory)

                if self.energyScan.isConnected():
                    self.connected()
                else:
                    self.disconnected()
            else:
                self.disconnected()

        elif propertyName == 'icons':
            self.setIcons(newValue)
        else:
            BlissWidget.propertyChanged(self, propertyName, oldValue, newValue)

    def run(self):
        logging.getLogger().info("Anonmalous Scattering Factors determination based on Chooch 5.0.6 by Gwyndaf Evans\nCopyright (C) 1994--2007\[email protected]\nG. Evans & R. F. Pettifer (2001)\nJ. Appl. Cryst. 34, 82-86.")

        if self.energyScan is not None:
            if self.energyScan.isConnected():
                self.connected()
            else:
                self.disconnected()
        else:
            self.disconnected()

    def connected(self):
        can_scan = self.energyScan.canScanEnergy()
        if self.element is not None:
            self.setEnabled(can_scan)
        else:
            self.setEnabled(False)
        self.emit(PYSIGNAL('energyScanConnected'), (True, can_scan))
        self.emit(PYSIGNAL('energyScanCanMove'), (can_scan,))

    def disconnected(self):
        self.setEnabled(False)
        self.emit(PYSIGNAL('energyScanConnected'), (False,))
        self.emit(PYSIGNAL('energyScanCanMove'), (False,))

    def scanReady(self, state):
        self.startScanButton.setEnabled(state)
        self.statusBox.setEnabled(state)

    def scanStatusChanged(self, msg=None):
        if msg is None:
            msg = ""
            color = self.scanBox.paletteBackgroundColor()
        else:
            color = self.STATES['progress']
        self.scanStatus.setText(str(msg))
        self.scanStatus.setPaletteBackgroundColor(QColor(color))

    def startEnergyScan(self):
        self.scanParameters = {}
        go_on = True
        if self.sessionId is None or self.sessionId == "":
            res = QMessageBox.question(
                self,
                'Energy scan',
                "You are not properly logged, therefore your scan won't be stored in ISPyB.\nProceed with the energy scan?",
                "Proceed",
                "Cancel")
            if res != 0:
                go_on = False
        if not go_on:
            self.startScanButton.commandFailed()
            return

        if self.sessionId is not None and self.sessionId != "":
            self.scanParameters["sessionId"] = self.sessionId
            self.scanParameters["element"] = self.element[0]
            self.scanParameters["edgeEnergy"] = self.element[1]
            self.scanParameters["startTime"] = time.strftime("%Y-%m-%d %H:%M:%S")

        self.statusBox.setTitle("%s - %s" % (self.element[0], self.element[1]))
        self.inflectionInput.setText("")
        self.peakInput.setText("")
        self.remoteInput.setText("")
        self.remote2Input.setText("")

        scan_result = self.energyScan.startEnergyScan(self.element[0], self.element[1],
                                                      str(self.directoryInput.text()),
                                                      str(self.prefixInput.text()),
                                                      self.sessionId, self.blSampleId)
        if not scan_result:
            self.scanFailed()

    def cancelEnergyScan(self):
        self.energyScan.cancelEnergyScan()

    def scanStarted(self):
        self.choochGraphs.newcurve("spline", [], [])
        self.choochGraphs.newcurve("fp", [], [])
        self.choochGraphs.replot()

        self.startScanButton.commandStarted()
        self.emit(PYSIGNAL("energyScanning"), (True,))
        self.parametersBox.setEnabled(False)
        self.acceptBox.setEnabled(False)
        self.inflectionInput.setEnabled(False)
        self.peakInput.setEnabled(False)
        self.remoteInput.setEnabled(False)
        self.remote2Input.setEnabled(False)

    def scanFailed(self):
        color = self.STATES['error']
        self.scanStatus.setPaletteBackgroundColor(QColor(color))
        self.startScanButton.commandFailed()
        self.emit(PYSIGNAL("energyScanning"), (False,))
        self.parametersBox.setEnabled(True)
        self.acceptBox.setEnabled(True)
        self.inflectionInput.setEnabled(True)
        self.peakInput.setEnabled(True)
        self.remoteInput.setEnabled(True)
        self.remote2Input.setEnabled(True)

    def chooch_finished(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl,
                        rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title):
        # display Chooch graphs
        self.choochGraphs.setTitle(title)
        self.choochGraphs.newcurve("spline", chooch_graph_x, chooch_graph_y1)
        self.choochGraphs.newcurve("fp", chooch_graph_x, chooch_graph_y2)
        self.choochGraphs.replot()

#    def scanFinished(self, *args):
    def scanFinished(self, scanData):
        print "EnergyScanBrick : scanCommandFinished scanData = ", scanData
        color = self.STATES['ok']
        self.scanStatusChanged("scan finished")

        scanDesc = scanData
        #print 'self.scanObject', self.scanObject
        pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, \
            chooch_graph_x, chooch_graph_y1, chooch_graph_y2, \
            title = self.energyScan.choochResults
        #self.energyScan.doChooch(scanData['element'], scanData['edgeEnergy'], scanArchiveFilePrefix='/927bis/ccd/Database', scanFilePrefix='Archive2')
        #self.energyScan.doChooch(self.scanObject, scanDesc)

        # self.element[0],
        # self.element[1])
        # ,
        #scanArchiveFilePrefix = 'scanArchiveFilePrefix' ,
        # scanFilePrefix = 'scanFilePrefix')

        # display Chooch graphs
        self.choochGraphs.setTitle(title)
        self.choochGraphs.newcurve("spline", chooch_graph_x, chooch_graph_y1)
        self.choochGraphs.newcurve("fp", chooch_graph_x, chooch_graph_y2)
        self.choochGraphs.replot()

        # display Chooch results
        energy_str = self['formatString'] % pk
        self.peakInput.setText(energy_str)
        energy_str = self['formatString'] % ip
        self.inflectionInput.setText(energy_str)
        energy_str = self['formatString'] % rm
        self.remoteInput.setText(energy_str)

        self.scanStatus.setPaletteBackgroundColor(QColor(color))

        self.startScanButton.commandDone()
        self.emit(PYSIGNAL("energyScanning"), (False,))
        self.parametersBox.setEnabled(True)
        self.acceptBox.setEnabled(True)
        self.inflectionInput.setEnabled(True)
        self.peakInput.setEnabled(True)
        self.remoteInput.setEnabled(True)
        self.remote2Input.setEnabled(True)

    def addNewPoint(self, x, y):
        self.emit(PYSIGNAL('addNewPoint'), (x, y))

    def newScan(self, scanParameters):
        self.emit(PYSIGNAL('newScan'), (scanParameters,))

    def clearEnergies(self):
        self.inflectionInput.setText("")
        self.peakInput.setText("")
        self.remoteInput.setText("")
        self.remote2Input.setText("")
        self.statusBox.setTitle("(no element)")
Esempio n. 5
0
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 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") 
Esempio n. 7
0
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']))