コード例 #1
0
    def refresh_search(self):
        """
        Called to refresh the advanced search
        """

        # Old values stored
        (fields, conditions, values, links, nots) = self.get_filters(False)

        # We remove the old layout
        self.clearLayout(self.layout())
        QObjectCleanupHandler().add(self.layout())

        # Links and add rows removed from every row
        self.rows_borders_removed()

        # Links and add rows reput in the good rows
        self.rows_borders_added(links)

        master_layout = QVBoxLayout()
        main_layout = QGridLayout()

        # Everything added to the layout
        for i in range(0, len(self.rows)):
            for j in range(0, 7):
                widget = self.rows[i][j]
                if widget != None:
                    main_layout.addWidget(widget, i, j)

        # Search button added at the end
        searchLayout = QHBoxLayout(None)
        searchLayout.setObjectName("search layout")
        self.search = QPushButton("Search")
        self.search.setFixedWidth(100)
        self.search.clicked.connect(self.launch_search)
        searchLayout.addWidget(self.search)
        searchLayout.setParent(None)

        # New layout added
        master_layout.addLayout(main_layout)
        master_layout.addLayout(searchLayout)
        self.setLayout(master_layout)
コード例 #2
0
class CalibrationAcqController(QObject):
    def __init__(self, parent=None, calibfunctionslist=None):
        super(CalibrationAcqController, self).__init__(parent)

        self.parent = parent
        self.calibfunctionslist = calibfunctionslist
        self.acquisitionData = None

        self.layout = QHBoxLayout()
        self.b1 = QCheckBox("Plot Shim x")
        self.b1.setGeometry(200, 150, 100,
                            30)  #            setting geometry of check box
        self.b1.setStyleSheet("QCheckBox::indicator"
                              "{"
                              "background-color : white;"
                              "selection-color: black;"
                              "}")  #    adding background color to indicator
        self.b1.toggled.connect(lambda: self.btnstate(self.b1))
        self.layout.addWidget(self.b1)

        self.b2 = QCheckBox("Plot Shim y")
        self.b2.setGeometry(200, 150, 100,
                            30)  #            setting geometry of check box
        self.b2.setStyleSheet("QCheckBox::indicator"
                              "{"
                              "background-color : white;"
                              "selection-color: black;"
                              "}")  #    adding background color to indicator
        self.b2.toggled.connect(lambda: self.btnstate(self.b2))
        self.layout.addWidget(self.b2)

        self.b3 = QCheckBox("Plot Shim z")
        self.b3.setGeometry(200, 150, 100,
                            30)  #            setting geometry of check box
        self.b3.setStyleSheet("QCheckBox::indicator"
                              "{"
                              "background-color : white;"
                              "selection-color: black;"
                              "}")  #    adding background color to indicator
        self.b3.toggled.connect(lambda: self.btnstate(self.b3))
        self.layout.addWidget(self.b3)

    @pyqtSlot(bool)
    def startCalibAcq(self):

        self.layout.setParent(None)
        self.parent.clearPlotviewLayout()
        self.calibfunction = defaultcalibfunctions[
            self.calibfunctionslist.getCurrentCalibfunction()]

        if self.calibfunction.cfn == 'Rabi Flops':
            self.rxd, self.msgs = rabi_flops(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            peakValst = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)
                peakValst.append(dataobject.t_magnitude[0])

                s = s + samples
                i = i + 1

            f_plotview = SpectrumPlot(
                dataobject.f_axis, dataobject.f_fftMagnitude, [], [],
                'Frequency (kHz)', "Amplitude",
                "%s Spectrum (last pulse)" % (self.calibfunction.cfn))
            t_plotview = SpectrumPlot(
                np.linspace(self.calibfunction.rf_pi2_duration0,
                            self.calibfunction.rf_pi2_durationEnd,
                            self.calibfunction.N), peakValst, [], [],
                'Excitation duration (us)', "pi2 pulse duration",
                "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)
            self.parent.plotview_layout.addWidget(f_plotview)

        elif self.calibfunction.cfn == 'Inversion Recovery':
            self.rxd, self.msgs = inversionRecovery(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            peakValst = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)
                peakValst.append(dataobject.t_magnitude[0])

                s = s + samples
                i = i + 1

            f_plotview = SpectrumPlot(
                dataobject.f_axis, dataobject.f_fftMagnitude, [], [],
                'Frequency (kHz)', "Amplitude",
                "%s Spectrum (last pulse)" % (self.calibfunction.cfn))
            t_plotview = SpectrumPlot(
                np.linspace(
                    self.calibfunction.echo_duration / 2 -
                    self.calibfunction.rf_duration * 1e-3,
                    self.calibfunction.echo_duration / 2 -
                    self.calibfunction.rf_duration * 1e-3 +
                    self.calibfunction.N * self.calibfunction.step -
                    self.calibfunction.step, self.calibfunction.N), peakValst,
                [], [], 'Time between pulses (ms)', "Amplitude",
                "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)
            self.parent.plotview_layout.addWidget(f_plotview)

        elif self.calibfunction.cfn == 'Shimming':
            self.rxd, self.msgs = shimming(self.calibfunction, 'x')
            values_x = self.rxd
            self.rxd, self.msgs = shimming(self.calibfunction, 'y')
            values_y = self.rxd
            self.rxd, self.msgs = shimming(self.calibfunction, 'z')
            values_z = self.rxd

            samples = np.int32(len(values_x) / self.calibfunction.N)

            i = 0
            s = 0
            self.peakValsf_x = []
            self.fwhmf_x = []
            self.peakValsf_y = []
            self.fwhmf_y = []
            self.peakValsf_z = []
            self.fwhmf_z = []
            while i < self.calibfunction.N:
                #############################

                d_cropped_x = values_x[s:s + samples]
                d_cropped_y = values_y[s:s + samples]
                d_cropped_z = values_z[s:s + samples]

                #############################

                dataobject_x: DataManager = DataManager(
                    d_cropped_x, self.calibfunction.lo_freq, len(d_cropped_x),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_x.get_peakparameters(
                )
                self.peakValsf_x.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_x.get_fwhm()
                self.fwhmf_x.append(fwhm_hz)

                #############################

                dataobject_y: DataManager = DataManager(
                    d_cropped_y, self.calibfunction.lo_freq, len(d_cropped_y),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_y.get_peakparameters(
                )
                self.peakValsf_y.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_y.get_fwhm()
                self.fwhmf_y.append(fwhm_hz)

                #############################

                dataobject_z: DataManager = DataManager(
                    d_cropped_z, self.calibfunction.lo_freq, len(d_cropped_z),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_z.get_peakparameters(
                )
                self.peakValsf_z.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_z.get_fwhm()
                self.fwhmf_z.append(fwhm_hz)

                ##############################

                s = s + samples
                i = i + 1

            self.plot_shim(axis='x')

        elif self.calibfunction.cfn == 'Larmor Frequency':
            repetitions = np.int32(self.calibfunction.step /
                                   self.calibfunction.resolution)
            while i < repetitions:
                self.peakVals, self.freqs = larmorFreq(self.calibfunction)
                t_plotview = SpectrumPlot(self.freqs, self.peakVals, [], [],
                                          'Larmor Frequency variation (MHz)',
                                          "Amplitude (mV)",
                                          "%s" % (self.calibfunction.cfn))
                self.parent.plotview_layout.addWidget(t_plotview)
                self.calibfunction.step = self.calibfunction.step / 2
                f_signalValue: float = round(np.max(self.peakVals), 4)
                f_signalIdx: int = np.argmax(self.f_signalValue)
                self.calibfunction.lo_freq = self.freqs[f_signalIdx]
                i = i + 1

        elif self.calibfunction.cfn == 'Amplitude':
            self.rxd, self.msgs, self.amps = flipAngle(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)

                s = s + samples
                i = i + 1

#            t_plotview = SpectrumPlot(np.linspace(-self.calibfunction.N/2*self.calibfunction.step, self.calibfunction.N/2*self.calibfunction.step, self.calibfunction.N), peakValsf, [],[],'Flip Angle value', "Amplitude (mV)", "%s" %(self.calibfunction.cfn))
            t_plotview = SpectrumPlot(self.amps, peakValsf, [], [],
                                      'Flip Angle value', "Amplitude (mV)",
                                      "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)

    def plot_shim(self, axis):

        shim_values = np.linspace(self.calibfunction.shim_initial,
                                  self.calibfunction.shim_final,
                                  self.calibfunction.N)

        if axis == 'x':
            plotview1 = SpectrumPlot(
                shim_values, self.peakValsf_x, [], [], "Shim value x",
                "Peak value", "%s x Peak value" % (self.calibfunction.cfn))
            plotview2 = SpectrumPlot(shim_values, self.fwhmf_x, [], [],
                                     "Shim value x ", "FHWM",
                                     "%s x FHWM" % (self.calibfunction.cfn))

        elif axis == 'y':
            plotview1 = SpectrumPlot(
                shim_values, self.peakValsf_y, [], [], "Shim value",
                "Peak value", "%s y Peak value" % (self.calibfunction.cfn))
            plotview2 = SpectrumPlot(shim_values, self.fwhmf_y, [], [],
                                     "Shim value", "FHWM",
                                     "%s y FWHM" % (self.calibfunction.cfn))

        elif axis == 'z':
            plotview1 = SpectrumPlot(
                shim_values, self.peakValsf_z, [], [], "Shim value",
                "Peak value", "%s z Peak value" % (self.calibfunction.cfn))
            plotview2 = SpectrumPlot(shim_values, self.fwhmf_z, [], [],
                                     "Shim value", "FHWM",
                                     "%s z FWHM" % (self.calibfunction.cfn))

        self.layout.setParent(None)
        self.parent.clearPlotviewLayout()
        self.parent.plotview_layout.addLayout(self.layout)
        self.parent.plotview_layout.addWidget(plotview1)
        self.parent.plotview_layout.addWidget(plotview2)

        max_x = self.peakValsf_x.index(round(np.max(self.peakValsf_x), 4))
        max_y = self.peakValsf_y.index(round(np.max(self.peakValsf_y), 4))
        max_z = self.peakValsf_z.index(round(np.max(self.peakValsf_z), 4))

        shim_x = shim_values[max_x]
        shim_y = shim_values[max_y]
        shim_z = shim_values[max_z]

        self.textEdit = QTextEdit()
        self.textEdit.setPlainText(
            'Shim_x=%0.5f,       Shim_y=%0.5f,       Shim_z=%0.5f' %
            (shim_x, shim_y, shim_z))
        self.parent.plotview_layout.addWidget(self.textEdit)

    def btnstate(self, b):

        if b.text() == 'Plot Shim x':
            if b.isChecked() == True:
                self.plot_shim(axis='x')
                self.b2.setChecked(False)
                self.b3.setChecked(False)

        if b.text() == 'Plot Shim y':
            if b.isChecked() == True:
                self.plot_shim(axis='y')
                self.b1.setChecked(False)
                self.b3.setChecked(False)

        if b.text() == 'Plot Shim z':
            if b.isChecked() == True:
                self.plot_shim(axis='z')
                self.b1.setChecked(False)
                self.b2.setChecked(False)
コード例 #3
0
class DeviceWidget(QWidget):

    def __init__(self, device):
        super().__init__()

        self._device = device

        self._layout = QVBoxLayout()
        self.setLayout(self._layout)

        self._gb = QGroupBox(self._device.label)

        self._layout.addWidget(self._gb)

        # label to display this device's polling rate
        self._polling_rate_label = QLabel('Polling rate: --')
        self._layout.addWidget(self._polling_rate_label)
        self._layout.addStretch()

        self._gblayout = QVBoxLayout()
        self._gb.setLayout(self._gblayout)

        self._hasMessage = False
        self._retry_time = self._device._retry_time

        self._retry_thread = None

    def show_error_message(self, message=''):
        if not self._hasMessage:

            self._messageframe = QFrame()
            vbox = QVBoxLayout()
            vbox.setContentsMargins(0, 0, 0, 0)
            self._messageframe.setLayout(vbox)

            self._txtmessage = QLabel()
            self._txtmessage.setWordWrap(True)
            vbox.addWidget(self._txtmessage)

            self._txtretry = QLabel('Retrying ...') #in {} seconds...'.format(self._retry_time))
            vbox.addWidget(self._txtretry)

            self._gb.setEnabled(False)
            self._layout.insertWidget(0, self._messageframe)

            self._hbox = QHBoxLayout()
            self._btnRetry = QPushButton('Force Retry')
            self._polling_rate_label.setText('Polling rate: --')
            self._btnRetry.clicked.connect(self.force_retry_connect)
            self._hbox.addStretch()
            self._hbox.addWidget(self._btnRetry)
            self._hbox.addStretch()
            self._layout.insertLayout(3, self._hbox)

            self._hasMessage = True

        self._txtmessage.setText('<font color="red">{}</font>'.format(message))

        if self._retry_thread is not None:
            # probably ok since the thread isn't doing anything critical
            del self._retry_thread

        #self._retry_thread = threading.Thread(target=self.test_update_retry_label, args=())
        #self._retry_thread.start()

    def force_retry_connect(self):
        self._device.unlock()

    '''
    def test_update_retry_label(self):
        for i in range(self._retry_time):
            self._txtretry.setText('Retrying in {} seconds...'.format(self._retry_time - i))
            time.sleep(1)
        self._device.unlock()
        self._txtretry.setText('Retrying')
    '''

    def set_retry_label(self, time):
        self._txtretry.setText('Retrying in {} seconds...'.format(str(time)))

    def hide_error_message(self):
        if self._hasMessage:
            wdg = self._layout.itemAt(0).widget()
            wdg.deleteLater()
            self._gb.setEnabled(True)
            self._hasMessage = False

            self._btnRetry.deleteLater()
            self._hbox.setParent(None)

    @property
    def gblayout(self):
        return self._gblayout
コード例 #4
0
class MacroLine(QObject):

    changed = pyqtSignal()

    types = ["Text", "Down", "Up", "Tap"]
    type_to_cls = [ActionText, ActionDown, ActionUp, ActionTap]

    def __init__(self, parent, action):
        super().__init__()

        self.parent = parent
        self.container = parent.container

        self.arrows = QHBoxLayout()
        self.btn_up = QToolButton()
        self.btn_up.setText("▲")
        self.btn_up.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.btn_up.clicked.connect(self.on_move_up)
        self.btn_down = QToolButton()
        self.btn_down.setText("▼")
        self.btn_down.clicked.connect(self.on_move_down)
        self.btn_down.setToolButtonStyle(Qt.ToolButtonTextOnly)

        self.arrows.addWidget(self.btn_up)
        self.arrows.addWidget(self.btn_down)
        self.arrows.setSpacing(0)

        self.select_type = QComboBox()
        self.select_type.addItems(self.types)
        self.select_type.setCurrentIndex(self.type_to_cls.index(type(action)))
        self.select_type.currentIndexChanged.connect(self.on_change_type)

        self.action = action
        self.action.changed.connect(self.on_change)
        self.row = -1

        self.btn_remove = QToolButton()
        self.btn_remove.setText("×")
        self.btn_remove.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.btn_remove.clicked.connect(self.on_remove_clicked)

    def insert(self, row):
        self.row = row
        self.container.addLayout(self.arrows, row, 0)
        self.container.addWidget(self.select_type, row, 1)
        self.container.addWidget(self.btn_remove, row, 3)
        self.action.insert(row)

    def remove(self):
        self.container.removeItem(self.arrows)
        self.container.removeWidget(self.select_type)
        self.container.removeWidget(self.btn_remove)
        self.action.remove()

    def delete(self):
        self.action.delete()
        self.btn_remove.setParent(None)
        self.btn_remove.deleteLater()
        self.select_type.setParent(None)
        self.select_type.deleteLater()
        self.arrows.setParent(None)
        self.arrows.deleteLater()
        self.btn_up.setParent(None)
        self.btn_up.deleteLater()
        self.btn_down.setParent(None)
        self.btn_down.deleteLater()

    def on_change_type(self):
        self.action.remove()
        self.action.delete()
        self.action = self.type_to_cls[self.select_type.currentIndex()](
            self.container)
        self.action.changed.connect(self.on_change)
        self.action.insert(self.row)

    def on_remove_clicked(self):
        self.parent.on_remove(self)

    def on_move_up(self):
        self.parent.on_move(self, -1)

    def on_move_down(self):
        self.parent.on_move(self, 1)

    def on_change(self):
        self.changed.emit()

    def serialize(self):
        return self.action.serialize()