Ejemplo n.º 1
0
    def initUI(self):
        # Qt stuff
        self.gotoLineEdit = QLineEdit('1000')
        self.gotoLineEdit.setValidator(QDoubleValidator())
        self.gotoButton = QPushButton('Go to')
        self.kindComboBox = QComboBox()

        self.metadataWidget = MetadataWidget()

        #self.kindComboBox.addItems(Dataset.kinds)
        self.rangeLineEdit1 = QLineEdit('1000')
        self.rangeLineEdit1.setValidator(QDoubleValidator())
        self.rangeLineEdit2 = QLineEdit('2000')
        self.rangeLineEdit2.setValidator(QDoubleValidator())
        self.stepLineEdit = QLineEdit('10')
        self.stepLineEdit.setValidator(QDoubleValidator())
        self.startButton = QPushButton('Start Scan')
        self.abortButton = QPushButton('Abort Scan')
        
        self.plot = AcquirePlotWidget()
        
        # Start with everything disabled
        self.disableButtons()

        # GUI Layout
        hbox_range = QHBoxLayout()
        hbox_range.addWidget(self.rangeLineEdit1)
        hbox_range.addWidget(QLabel('to'))
        hbox_range.addWidget(self.rangeLineEdit2)

        hbox_goto = QHBoxLayout()
        hbox_goto.setContentsMargins(0, 0, 0, 0)
        hbox_goto.addWidget(self.gotoLineEdit)
        hbox_goto.addWidget(self.gotoButton)

        vbox = QVBoxLayout()
        vbox.addWidget(QLabel('Go to wavelength (nm):'))
        vbox.addLayout(hbox_goto)
        vbox.addWidget(QLabel('Wavelength range (nm):'))
        vbox.addLayout(hbox_range)
        vbox.addWidget(QLabel('Step size (nm):'))
        vbox.addWidget(self.stepLineEdit)
        vbox.addWidget(self.startButton)
        vbox.addWidget(self.abortButton)
        vbox.addStretch(1)

        hbox2 = QHBoxLayout()
        hbox2.addLayout(vbox)
        hbox2.addWidget(self.plot)

        layout = QVBoxLayout()
        layout.addWidget(self.metadataWidget)
        layout.addLayout(hbox2)

        self.setLayout(layout)

        # Connect GUI slots and signals
        self.gotoButton.clicked.connect(self.onGoto)
        self.gotoSignal.connect(self._acquirer.goto)
        self.startButton.clicked.connect(self.onStart)
        self.startScanSignal.connect(self._acquirer.scan)
        self.abortButton.clicked.connect(self._acquirer.abort)

        self._acquirer.initialized.connect(self.enableButtons)
        self._acquirer.goto_done.connect(self.enableButtons)
        self._acquirer.scan_aborted.connect(self.enableButtons)
        self._acquirer.scan_finished.connect(self.enableButtons)
        self._acquirer.new_data.connect(self.plot.add_data)
Ejemplo n.º 2
0
class AcquireWidget(QWidget):
    def __init__(self, acquirer, configWidget):
        super(AcquireWidget, self).__init__()
        self._acquirer = acquirer
        self.configWidget = configWidget
        self.initUI()

    def initUI(self):
        # Qt stuff
        self.gotoLineEdit = QLineEdit('1000')
        self.gotoLineEdit.setValidator(QDoubleValidator())
        self.gotoButton = QPushButton('Go to')
        self.kindComboBox = QComboBox()

        self.metadataWidget = MetadataWidget()

        #self.kindComboBox.addItems(Dataset.kinds)
        self.rangeLineEdit1 = QLineEdit('1000')
        self.rangeLineEdit1.setValidator(QDoubleValidator())
        self.rangeLineEdit2 = QLineEdit('2000')
        self.rangeLineEdit2.setValidator(QDoubleValidator())
        self.stepLineEdit = QLineEdit('10')
        self.stepLineEdit.setValidator(QDoubleValidator())
        self.startButton = QPushButton('Start Scan')
        self.abortButton = QPushButton('Abort Scan')
        
        self.plot = AcquirePlotWidget()
        
        # Start with everything disabled
        self.disableButtons()

        # GUI Layout
        hbox_range = QHBoxLayout()
        hbox_range.addWidget(self.rangeLineEdit1)
        hbox_range.addWidget(QLabel('to'))
        hbox_range.addWidget(self.rangeLineEdit2)

        hbox_goto = QHBoxLayout()
        hbox_goto.setContentsMargins(0, 0, 0, 0)
        hbox_goto.addWidget(self.gotoLineEdit)
        hbox_goto.addWidget(self.gotoButton)

        vbox = QVBoxLayout()
        vbox.addWidget(QLabel('Go to wavelength (nm):'))
        vbox.addLayout(hbox_goto)
        vbox.addWidget(QLabel('Wavelength range (nm):'))
        vbox.addLayout(hbox_range)
        vbox.addWidget(QLabel('Step size (nm):'))
        vbox.addWidget(self.stepLineEdit)
        vbox.addWidget(self.startButton)
        vbox.addWidget(self.abortButton)
        vbox.addStretch(1)

        hbox2 = QHBoxLayout()
        hbox2.addLayout(vbox)
        hbox2.addWidget(self.plot)

        layout = QVBoxLayout()
        layout.addWidget(self.metadataWidget)
        layout.addLayout(hbox2)

        self.setLayout(layout)

        # Connect GUI slots and signals
        self.gotoButton.clicked.connect(self.onGoto)
        self.gotoSignal.connect(self._acquirer.goto)
        self.startButton.clicked.connect(self.onStart)
        self.startScanSignal.connect(self._acquirer.scan)
        self.abortButton.clicked.connect(self._acquirer.abort)

        self._acquirer.initialized.connect(self.enableButtons)
        self._acquirer.goto_done.connect(self.enableButtons)
        self._acquirer.scan_aborted.connect(self.enableButtons)
        self._acquirer.scan_finished.connect(self.enableButtons)
        self._acquirer.new_data.connect(self.plot.add_data)

    # Signals
    gotoSignal = Signal(float)
    startScanSignal = Signal(object)

    @Slot()
    def enableButtons(self):
        self.metadataWidget.setEnabled(True)
        self.gotoLineEdit.setEnabled(True)
        self.gotoButton.setEnabled(True)
        self.rangeLineEdit1.setEnabled(True)
        self.rangeLineEdit2.setEnabled(True)
        self.stepLineEdit.setEnabled(True)
        self.startButton.setEnabled(True)
        self.abortButton.setEnabled(False)

    def disableButtons(self):
        self.metadataWidget.setEnabled(False)
        self.gotoLineEdit.setEnabled(False)
        self.gotoButton.setEnabled(False)
        self.rangeLineEdit1.setEnabled(False)
        self.rangeLineEdit2.setEnabled(False)
        self.stepLineEdit.setEnabled(False)
        self.startButton.setEnabled(False)
        self.abortButton.setEnabled(True)

    @Slot()
    def onGoto(self):
        nm = self.gotoLineEdit.text()
        if nm:
            self.gotoSignal.emit(float(nm))
            self.disableButtons()

    @Slot()
    def onStart(self):
        range1 = self.rangeLineEdit1.text()
        range2 = self.rangeLineEdit2.text()
        step = self.stepLineEdit.text()
        if range1 and range2 and step:
            req = ScanRequest(float(range1), float(range2), float(step), 
                        self.configWidget.config(),
                        self.metadataWidget.metadata(),
                        self.metadataWidget.systemResponse())
            self.startScanSignal.emit(req)
            self.disableButtons()