Пример #1
0
    def define_browser_menu(self, item):
        experiment = self.manager.experiments.with_browser_item(item)
        menu = QtGui.QMenu(self)

        # Change Color
        action_change_color = QtGui.QAction(menu)
        action_change_color.setText("Change Color")
        action_change_color.triggered.connect(
            lambda: self.change_color(experiment))
        menu.addAction(action_change_color)

        # Remove
        action_remove = QtGui.QAction(menu)
        action_remove.setText("Remove Graph")
        if self.manager.is_running():
            if self.manager.running_experiment(
            ) == experiment:  # Experiment running
                action_remove.setEnabled(False)
        action_remove.triggered.connect(
            lambda: self.remove_experiment(experiment))
        menu.addAction(action_remove)

        # Use parameters
        action_use = QtGui.QAction(menu)
        action_use.setText("Use These Parameters")
        action_use.triggered.connect(lambda: self.set_parameters(experiment))
        menu.addAction(action_use)
        menu_dict = {
            "menu": menu,
            "color": action_change_color,
            "remove": action_remove,
            "use": action_use
        }
        return menu_dict
Пример #2
0
    def define_browser_menu(self, item):
        menu_dict = super().define_browser_menu(item)
        menu = menu_dict['menu']
        experiment = self.manager.experiments.with_browser_item(item)

        action_open_pulse = QtGui.QAction(menu)
        action_open_pulse.setText("Use Settings in Pulse GUI")
        if self.manager.is_running():
            if self.manager.running_experiment(
            ) == experiment:  # Experiment running
                action_open_pulse.setEnabled(False)
        action_open_pulse.triggered.connect(
            lambda: self.open_pulse_gui(experiment))
        menu.addAction(action_open_pulse)
        menu_dict['pulse'] = action_open_pulse

        action_open_fit = QtGui.QAction(menu)
        action_open_fit.setText("Use Settings in Fit GUI")
        if self.manager.is_running():
            if self.manager.running_experiment(
            ) == experiment:  # Experiment running
                action_open_fit.setEnabled(False)
        action_open_fit.triggered.connect(
            lambda: self.open_fit_gui(experiment))
        menu.addAction(action_open_fit)
        menu_dict['fit'] = action_open_fit

        return menu_dict
Пример #3
0
 def _add_widget(self, name, vbox):
     indicators = self._procedure.indicator_objects
     widget = getattr(self, name)
     hbox = QtGui.QHBoxLayout()
     if not isinstance(widget, self.NO_LABEL_INPUTS):
         label = QtGui.QLabel(self)
         label.setText("%s:" % indicators[name].name)
         hbox.addWidget(label)
     hbox.addWidget(widget)
     vbox.addLayout(hbox)
Пример #4
0
 def __init__(self, instruments, *args, names=(), **kwargs):
     super().__init__(*args, **kwargs)
     self.tab = QtGui.QTabWidget()
     if not names:
         names = [type(instrument).__name__ for instrument in instruments]
     for name, instrument in zip(names, instruments):
         self.add_tab(name, instrument)
     layout = QtGui.QGridLayout()
     layout.addWidget(self.tab, 0, 0)
     self.setLayout(layout)
     self.setWindowTitle("Instrument Control")
Пример #5
0
 def _add_widget(self, name, vbox):
     parameters = self._procedure.parameter_objects()
     widget = getattr(self, name)
     hbox = QtGui.QHBoxLayout()
     if not isinstance(widget, self.NO_LABEL_INPUTS):
         label = QtGui.QLabel(self)
         label.setText("%s:" % parameters[name].name)
         hbox.addWidget(label)
     hbox.addWidget(widget)
     vbox.addLayout(hbox)
     vbox.addStretch(0)
Пример #6
0
    def _setup_ui(self):
        self.plot = QtGui.QTreeWidget()
        param_header = QtGui.QTreeWidgetItem(self.x_label)
        self.plot.setHeaderItem(param_header)
        self.plot.setColumnWidth(0, 150)
        self.plot.setAlternatingRowColors(True)
        self.plot.setSortingEnabled(True)
        self.plot.sortItems(0, QtCore.Qt.AscendingOrder)

        # patch addItem and removeItem from pyqtgraph PlotItem
        self.plot.addItem = self.addItem
        self.plot.removeItem = self.removeItem
Пример #7
0
    def _setup_ui(self):
        self.log_widget = LogWidget()
        self.log.addHandler(
            self.log_widget.handler)  # needs to be in Qt context?
        log.info("ManagedWindow connected to logging")

        self.queue_button = QtGui.QPushButton('Queue', self)
        self.queue_button.clicked.connect(self.queue)

        self.abort_button = QtGui.QPushButton('Abort', self)
        self.abort_button.setEnabled(False)
        self.abort_button.clicked.connect(self.abort)

        #self.queue_button = QtGui.QPushButton('Set', self)
        #self.queue_button.clicked.connect(self.procedure.refresh_parameters())

        self.plot_widget = PlotWidget(self.procedure_class.DATA_COLUMNS,
                                      self.x_axis, self.y_axis)
        self.plot = self.plot_widget.plot

        self.browser_widget = BrowserWidget(self.procedure_class,
                                            self.displays,
                                            [self.x_axis, self.y_axis],
                                            parent=self)
        self.browser_widget.show_button.clicked.connect(self.show_experiments)
        self.browser_widget.hide_button.clicked.connect(self.hide_experiments)
        self.browser_widget.clear_button.clicked.connect(
            self.clear_experiments)
        self.browser_widget.open_button.clicked.connect(self.open_experiment)
        self.browser = self.browser_widget.browser

        self.browser.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.browser.customContextMenuRequested.connect(self.browser_item_menu)
        self.browser.itemChanged.connect(self.browser_item_changed)

        self.inputs = InputsWidget(self.procedure_class,
                                   self.inputs,
                                   parent=self)

        self.manager = Manager(self.plot,
                               self.browser,
                               log_level=self.log_level,
                               parent=self)
        self.manager.abort_returned.connect(self.abort_returned)
        self.manager.queued.connect(self.queued)
        self.manager.running.connect(self.running)
        self.manager.finished.connect(self.finished)
        self.manager.log.connect(self.log.handle)
Пример #8
0
    def paint(self, p, *args):
        opts = self.item.opts
        if opts.get('fillLevel') is not None and opts.get(
                'fillBrush') is not None:
            p.setBrush(pg.mkBrush(opts['fillBrush']))
            p.setPen(pg.mkPen(None))
            p.drawPolygon(
                QtGui.QPolygonF([
                    QtCore.QPointF(*self.line[:2]),
                    QtCore.QPointF(*self.line[2:]),
                    QtCore.QPointF(*self.line[1:3][::-1])
                ]))

        if not isinstance(self.item, pg.ScatterPlotItem):
            if opts.get('shadowPen') is not None:
                p.setPen(pg.mkPen(opts['shadowPen']))
                p.drawLine(*self.line)
            pen = pg.mkPen(opts['pen'])
            pattern = np.array(pen.dashPattern())
            new_pattern = pattern
            # something is wrong with pyqtgraph scaling. This sort of fixes it
            new_pattern[::2] = pattern[::2] / 5
            pen.setDashPattern(list(new_pattern))
            p.setPen(pen)
            p.drawLine(*self.line)
        symbol = opts.get('symbol')
        if symbol is not None:
            pen = pg.mkPen(opts.get('symbolPen'))
            brush = pg.mkBrush(opts.get('symbolBrush'))
            size = opts.get('symbolSize', 0)
            p.translate(np.mean([self.line[0], self.line[2]]),
                        np.mean([self.line[1], self.line[3]]))
            drawSymbol(p, symbol, size, pen, brush)
Пример #9
0
 def update_color(self, experiment, color):
     pixelmap = QtGui.QPixmap(24, 24)
     pixelmap.fill(color)
     # disable browser_item_changed() while changing the icon
     self.browser.itemChanged.disconnect()
     experiment.browser_item.setIcon(0, QtGui.QIcon(pixelmap))
     self.browser.itemChanged.connect(self.browser_item_changed)
     # update all of the curves
     for index, p in enumerate(self.plot):
         for curve in experiment.curve[index]:
             if curve.pen is not None:
                 curve.pen.setColor(color)
             if curve.symbolBrush is not None:
                 # symbolBrush.setColor() doesn't work as of pyqtgraph 0.12.1
                 curve.setSymbolBrush(pg.mkBrush(color=color))
             curve.update()
Пример #10
0
    def addItem(self, curve):
        results = []
        for x_axis in curve.x:
            try:
                result = curve.results.data[x_axis]
                if isinstance(result[0], str):
                    results.append(result[0])
                elif isinstance(
                        result,
                    (list, tuple)) and len(result) == 2 and result[1] != 0:
                    # assuming result = (value, error)
                    digit = -int(np.floor(np.log10(np.abs(result[
                        1])))) + 1  # two leading digits from the error term
                    results.append(
                        f"{np.round(result[0], digit):g} \u00b1 {np.round(result[1], digit): g}"
                    )
                else:
                    results.append(f"{result[0]:g}")
            except IndexError:
                pass
        if results:
            item = QtGui.QTreeWidgetItem(results)
            self.plot.addTopLevelItem(item)
            self.curves.append([curve, item])

        for index in range(self.plot.columnCount()):
            self.plot.resizeColumnToContents(index)
Пример #11
0
    def _layout(self):
        # make the sweep dock widget
        base_dock = QtGui.QWidget(self)
        base_inputs_vbox = QtGui.QVBoxLayout()
        base_inputs_vbox.addWidget(self.base_inputs_widget)
        base_inputs_vbox.addStretch(0)
        base_dock.setLayout(base_inputs_vbox)
        # add the dock widget to the left
        base_inputs_dock = QtGui.QDockWidget('Sweeps')
        base_inputs_dock.setWidget(base_dock)
        features = base_inputs_dock.features()
        base_inputs_dock.setFeatures(features
                                     & ~QtGui.QDockWidget.DockWidgetClosable)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, base_inputs_dock)

        super()._layout()
Пример #12
0
    def _layout(self):
        vbox = QtGui.QVBoxLayout(self)
        vbox.setSpacing(6)
        vbox.setContentsMargins(0, 0, 0, 0)
        inputs = list(self._inputs)

        remove_indices = []
        for ind, name in enumerate(inputs):
            if isinstance(getattr(self, name), (FileInput, DirectoryInput)):
                remove_indices.append(ind)
                self._add_widget(name, vbox)
        inputs = [
            inputs[ind] for ind in range(len(inputs))
            if ind not in remove_indices
        ]

        remove_indices = []
        for ind, name in enumerate(inputs):
            if isinstance(getattr(self, name),
                          (NoiseInput, BooleanListInput, RangeInput)):
                continue
            remove_indices.append(ind)
            self._add_widget(name, vbox)
        inputs = [
            inputs[ind] for ind in range(len(inputs))
            if ind not in remove_indices
        ]

        for name in inputs:
            self._add_widget(name, vbox)
        self.setLayout(vbox)
Пример #13
0
    def _layout(self):
        parameters = self._procedure.parameter_objects()
        vbox = QtGui.QVBoxLayout(self)
        vbox.setSpacing(6)

        directory = getattr(self, self._inputs["directory_inputs"])
        font = QtGui.QFont()
        font.setBold(True)
        directory.label.setFont(font)
        vbox.addWidget(directory)
        grid = QtGui.QGridLayout()
        for index, (_,
                    parameter) in enumerate(self._inputs["frequency_inputs"]):
            label = QtGui.QLabel()
            label.setText(parameters[parameter].name)
            grid.addWidget(label, 0, index)
            text_edit = QtGui.QTextEdit()
            text_edit.sizeHint = lambda: QtCore.QSize(0, 120)
            grid.addWidget(getattr(self, parameter), 1, index)
        vbox.addLayout(grid)

        for inputs in self._inputs["sweep_inputs"]:
            label = QtGui.QLabel()
            label.setText(inputs[-1] + ":")
            font = QtGui.QFont()
            font.setBold(True)
            label.setFont(font)
            vbox.addWidget(label)
            hbox = QtGui.QHBoxLayout()
            for name in inputs[1:-1]:
                if not isinstance(getattr(self, name), self.NO_LABEL_INPUTS):
                    label = QtGui.QLabel(self, width=1)
                    label.setText("%s:" % parameters[name].name)
                    hbox.addWidget(label)
                input_box = getattr(self, name)
                hbox.addWidget(input_box)
                hbox.addStretch()
            vbox.addLayout(hbox)

            self.setLayout(vbox)

        directory_inputs = [self._inputs["directory_inputs"]]
        frequency_inputs = [
            inputs[1] for inputs in self._inputs["frequency_inputs"]
        ]
        sweep_inputs = [
            item for inputs in self._inputs["sweep_inputs"]
            for item in inputs[1:-1]
        ]

        self._inputs = directory_inputs + frequency_inputs + sweep_inputs
Пример #14
0
 def _layout(self):
     vbox = QtGui.QVBoxLayout(self)
     vbox.setSpacing(6)
     vbox.setContentsMargins(0, 0, 0, 0)
     inputs = list(self._procedure.indicator_objects.keys())
     for name in inputs:
         self._add_widget(name, vbox)
     self.setLayout(vbox)
Пример #15
0
    def _layout(self):
        vbox = QtGui.QVBoxLayout(self)
        vbox.setSpacing(0)

        hbox = QtGui.QHBoxLayout()
        hbox.setSpacing(10)
        hbox.setContentsMargins(-1, 6, -1, 6)
        hbox.addWidget(self.show_button)
        hbox.addWidget(self.hide_button)
        hbox.addWidget(self.clear_button)
        hbox.addStretch()
        hbox.addWidget(self.open_button)

        vbox.addLayout(hbox)
        vbox.addSpacing(10)
        vbox.addWidget(self.browser)
        self.setLayout(vbox)
Пример #16
0
    def _layout(self):
        vbox = QtGui.QVBoxLayout(self)
        vbox.setSpacing(6)
        left, top, right, bottom = vbox.getContentsMargins()
        vbox.setContentsMargins(left, top // 2, right, bottom // 2)

        label = QtGui.QLabel(self)
        label.setText(self.parameter.name + ":")
        vbox.addWidget(label)

        vbox.addWidget(self.take_noise)
        hbox = QtGui.QHBoxLayout()
        label = QtGui.QLabel(self)
        label.setText("%s:" % self.integration.parameter.name)
        hbox.addWidget(label)
        hbox.addWidget(self.integration)
        vbox.addLayout(hbox)
        hbox = QtGui.QHBoxLayout()
        label = QtGui.QLabel(self)
        label.setText("%s:" % self.n_int.parameter.name)
        hbox.addWidget(label)
        hbox.addWidget(self.n_int)
        vbox.addLayout(hbox)

        if self._populate_off_resonance:
            vbox.addWidget(self.off_resonance)
            hbox = QtGui.QHBoxLayout()
            label = QtGui.QLabel(self)
            label.setText("%s:" % self.offset.parameter.name)
            hbox.addWidget(label)
            hbox.addWidget(self.offset)
            vbox.addLayout(hbox)

            hbox = QtGui.QHBoxLayout()
            label = QtGui.QLabel(self)
            label.setText("%s:" % self.n_off.parameter.name)
            hbox.addWidget(label)
            hbox.addWidget(self.n_off)
            vbox.addLayout(hbox)
        self.setLayout(vbox)
        self.setFrameShape(QtGui.QFrame.Panel)
        self.setFrameShadow(QtGui.QFrame.Raised)
        self.setLineWidth(3)
Пример #17
0
    def _setup_ui(self):
        """
        Loads custom QT UI for center calibration
        """
        super()._setup_ui()
        self.stop_button = QtGui.QPushButton('Stop', self)
        self.queue_button.clicked.connect(self.stop)

        self.inputs.hide()
        self.run_directory = os.path.dirname(os.path.realpath(__file__))
        self.inputs = fromUi(os.path.join(self.run_directory,
                                          'temp_control_gui.ui'))
Пример #18
0
    def __init__(self, parameter, parent=None, **kwargs):
        self.button = QtGui.QPushButton("Find")
        self.button.clicked.connect(self.get_file)
        self.line_edit = QtGui.QLineEdit()
        self.label = QtGui.QLabel()

        if qt_min_version(5):
            super().__init__(parameter=parameter, parent=parent, **kwargs)
        else:
            QtGui.QWidget.__init__(self, parent=parent, **kwargs)
            inputs.Input.__init__(self, parameter)
        vbox = QtGui.QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        if parameter.name:
            self.label.setText(self.parameter.name + ":")
            vbox.addWidget(self.label)
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.button)
        hbox.addWidget(self.line_edit)
        vbox.addLayout(hbox)
        self.setLayout(vbox)
Пример #19
0
    def _layout(self):
        if self.horizontal:
            box = QtGui.QHBoxLayout(self)
        else:
            box = QtGui.QVBoxLayout(self)

        box.setSpacing(6)
        left, top, right, bottom = box.getContentsMargins()
        box.setContentsMargins(left, top // 2, right, bottom // 2)
        if self.parameter.name:
            label = QtGui.QLabel(self)
            label.setText("%s:" % self.parameter.name)
            box.addWidget(label)
        for row in self.rows:
            if self.horizontal:
                box.addStretch()
            box.addWidget(row)

        self.setLayout(box)
        self.setFrameShape(QtGui.QFrame.Panel)
        self.setFrameShadow(QtGui.QFrame.Raised)
        self.setLineWidth(3)
Пример #20
0
    def _setup_ui(self):
        self.columns_x = QtGui.QComboBox(self)
        self.columns_y = QtGui.QComboBox(self)
        self.columns_x.hide()
        self.columns_y.hide()
        for column in self.columns:
            self.columns_x.addItem(column)
            self.columns_y.addItem(column)
        self.columns_x.activated.connect(self.update_x_column)
        self.columns_y.activated.connect(self.update_y_column)

        if self.x_label is None:
            x_label = self.x_axes if isinstance(self.x_axes,
                                                str) else self.x_axes[0]
        else:
            x_label = self.x_label
        if self.y_label is None:
            y_label = self.y_axes if isinstance(self.y_axes,
                                                str) else self.y_axes[0]
        else:
            y_label = self.y_label
        self.plot_frame = widgets.PlotFrame(x_label, y_label,
                                            self.refresh_time,
                                            self.check_status)
        self.updated = self.plot_frame.updated
        self.plot = self.plot_frame.plot
        self.columns_x.setCurrentIndex(0)
        self.columns_y.setCurrentIndex(1)
        if self.legend_text is not None:
            style_cycle = self.style_cycle()
            self.legend = self.plot_frame.plot_widget.addLegend(offset=(-1, 1))
            for text in self.legend_text:
                legend_item = pg.PlotDataItem(
                    **copy_options(next(style_cycle)))
                legend_item_sample = ItemSample(legend_item)
                self.legend.addItem(legend_item_sample, text)
        # Set the results curve class
        self.curve_class = MKIDResultsCurve
Пример #21
0
    def __init__(self, data_x, data_y, title='', refresh_time=2, **kwargs):
        super().__init__(**kwargs)
        self.setAutoFillBackground(False)
        self.setStyleSheet("background: #fff")
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setFrameShadow(QtGui.QFrame.Sunken)
        self.setMidLineWidth(1)

        self.data_x = data_x
        self.data_y = data_y

        self.coordinates = QtGui.QLabel(self)
        self.coordinates.setMinimumSize(QtCore.QSize(0, 20))
        self.coordinates.setStyleSheet("background: #fff")
        self.coordinates.setText("")
        self.coordinates.setAlignment(QtCore.Qt.AlignRight
                                      | QtCore.Qt.AlignTrailing
                                      | QtCore.Qt.AlignVCenter)
        self.plot_widget = pg.PlotWidget(
            background='w',
            title=title,
            axisItems={'bottom': TimeAxisItem(orientation='bottom')},
            **kwargs)
        self.plot = self.plot_widget.getPlotItem()
        self.curve = self.plot.plot(pen='k')
        self.crosshairs = Crosshairs(self.plot,
                                     pen=pg.mkPen(color='#AAAAAA',
                                                  style=QtCore.Qt.DashLine))
        self.crosshairs.coordinates.connect(self.update_coordinates)

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(refresh_time * 1000)

        vbox = QtGui.QVBoxLayout(self)
        vbox.addWidget(self.plot_widget)
        vbox.addWidget(self.coordinates)
        self.setLayout(vbox)
Пример #22
0
 def _layout(self):
     if len(self.labels) > 1:
         width = 60
         vbox = QtGui.QVBoxLayout(self)
         vbox.setSpacing(6)
         left, top, right, bottom = vbox.getContentsMargins()
         vbox.setContentsMargins(left, top // 2, right, bottom // 2)
         if self.parameter.name:
             label = QtGui.QLabel(self)
             label.setText("%s:" % self.parameter.name)
             vbox.addWidget(label)
         for index, row in enumerate(self.rows):
             hbox = QtGui.QHBoxLayout()
             try:
                 label = QtGui.QLabel(self)
                 label.setText("%s" % self.labels[index])
                 hbox.addWidget(label)
             except IndexError:
                 pass
             for input in row:
                 input.setFixedWidth(width)
                 hbox.addWidget(input)
                 label = QtGui.QLabel(self)
                 label.setText(input._parameter.name)
                 hbox.addWidget(label)
             hbox.addStretch()
             vbox.addLayout(hbox)
         self.setLayout(vbox)
         self.setFrameShape(QtGui.QFrame.Panel)
         self.setFrameShadow(QtGui.QFrame.Raised)
         self.setLineWidth(3)
     else:
         width = 60
         hbox = QtGui.QHBoxLayout(self)
         left, top, right, bottom = hbox.getContentsMargins()
         hbox.setContentsMargins(0, top // 2, 0, bottom // 2)
         label = QtGui.QLabel(self)
         label.setText("%s:" % self.parameter.name)
         hbox.addWidget(label)
         for input in self.rows[0]:
             input.setFixedWidth(width)
             hbox.addWidget(input)
             label = QtGui.QLabel(self)
             label.setText(input._parameter.name)
             hbox.addWidget(label)
         hbox.addStretch()
         self.setLayout(hbox)
Пример #23
0
    def _layout(self):
        width = 60
        hbox = QtGui.QHBoxLayout(self)
        hbox.setContentsMargins(0, 0, 0, 0)
        hbox.addStretch()
        hbox.addWidget(self.vary)

        self.guess.setFixedWidth(width)
        hbox.addWidget(self.guess)
        label = QtGui.QLabel(self)
        label.setText("guess")
        hbox.addWidget(label)

        self.min.setFixedWidth(width)
        hbox.addWidget(self.min)
        label = QtGui.QLabel(self)
        label.setText("min")
        hbox.addWidget(label)

        self.max.setFixedWidth(width)
        hbox.addWidget(self.max)
        label = QtGui.QLabel(self)
        label.setText("max")
        hbox.addWidget(label)
Пример #24
0
    def _layout(self):
        self.main = QtGui.QWidget(self)

        inputs_dock = QtGui.QWidget(self)
        inputs_vbox = QtGui.QVBoxLayout(self.main)

        hbox = QtGui.QHBoxLayout()
        hbox.setSpacing(10)
        hbox.setContentsMargins(-1, 6, -1, 6)
        hbox.addWidget(self.queue_button)
        hbox.addWidget(self.abort_button)
        hbox.addWidget(self.stop_button)
        hbox.addStretch()

        inputs_vbox.addWidget(self.inputs)
        inputs_vbox.addLayout(hbox)
        inputs_vbox.addStretch()
        inputs_dock.setLayout(inputs_vbox)

        dock = QtGui.QDockWidget('Input Parameters')
        dock.setWidget(inputs_dock)
        dock.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)

        tabs = QtGui.QTabWidget(self.main)
        tabs.addTab(self.plot_widget, "Results Graph")
        tabs.addTab(self.log_widget, "Experiment Log")

        splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
        splitter.addWidget(tabs)
        splitter.addWidget(self.browser_widget)
        self.plot_widget.setMinimumSize(100, 200)

        vbox = QtGui.QVBoxLayout(self.main)
        vbox.setSpacing(0)
        vbox.addWidget(splitter)

        self.main.setLayout(vbox)
        self.setCentralWidget(self.main)
        self.main.show()
        self.resize(1000, 800)
Пример #25
0
def test_color_change(sweep_gui, qtbot):
    sweep_gui.inputs.n_points.setValue(10)
    n_atten = sweep_gui.base_inputs_widget.n_atten.value()
    n_field = sweep_gui.base_inputs_widget.n_field.value()
    n_temp = sweep_gui.base_inputs_widget.n_temp.value()
    frequencies1 = sweep_gui.base_inputs_widget.frequencies1.value()
    frequencies2 = sweep_gui.base_inputs_widget.frequencies2.value()
    n_freq = np.max([np.array(frequencies1).size, np.array(frequencies2).size])
    n_sweep = n_atten * n_field * n_temp * n_freq
    qtbot.mouseClick(sweep_gui.queue_button, QtCore.Qt.LeftButton)
    for _ in range(n_sweep):
        with qtbot.waitSignal(sweep_gui.manager.finished,
                              timeout=1000,
                              raising=True):
            pass
    item = sweep_gui.browser.topLevelItem(0)
    experiment = sweep_gui.manager.experiments.with_browser_item(item)
    color = QtGui.QColor(255, 0, 0)
    sweep_gui.update_color(experiment, color)
Пример #26
0
    def _setup_ui(self):
        preview_tab = QtGui.QTabWidget()
        param_vbox = QtGui.QVBoxLayout()
        param_vbox_widget = QtGui.QWidget()

        self.plot_widget = []
        self.plot = []
        vbox_widget = []
        vbox = []
        for index, plot_widget in enumerate(self.plot_widget_classes):
            vbox_widget.append(QtGui.QWidget())
            vbox.append(QtGui.QVBoxLayout())
            color_cycle = self.color_cycle[:1]
            self.plot_widget.append(
                plot_widget(self.columns,
                            x_axes=self.x_axes[index],
                            y_axes=self.y_axes[index],
                            x_label=self.x_labels[index],
                            y_label=self.y_labels[index],
                            legend_text=self.legend_text[index],
                            color_cycle=color_cycle))
            self.plot.append(self.plot_widget[-1].plot)
            vbox[-1].addWidget(self.plot_widget[-1])
            vbox_widget[-1].setLayout(vbox[-1])
            preview_tab.addTab(vbox_widget[-1], self.plot_names[index])

        self.preview_param = QtGui.QTreeWidget()
        param_header = QtGui.QTreeWidgetItem(["Name", "Value"])
        self.preview_param.setHeaderItem(param_header)
        self.preview_param.setColumnWidth(0, 150)
        self.preview_param.setAlternatingRowColors(True)

        param_vbox.addWidget(self.preview_param)
        param_vbox_widget.setLayout(param_vbox)
        preview_tab.addTab(param_vbox_widget, "Run Parameters")
        self.layout().addWidget(preview_tab, 0, 3, 4, 1)
        self.layout().setColumnStretch(3, 2)
        self.setMinimumSize(900, 500)
        self.resize(1300, 500)

        self.setFileMode(QtGui.QFileDialog.ExistingFiles)
        self.currentChanged.connect(self.update_plot)
Пример #27
0
    def add_tab(self, name, instrument):
        vbox = QtGui.QVBoxLayout()
        for label, method, arguments in instrument.CONTROL:
            hbox = QtGui.QHBoxLayout()
            label_widget = QtGui.QLabel(label + ":")
            hbox.addWidget(label_widget)
            hbox.addStretch()
            inputs = []
            for argument in arguments:
                if argument[0] is not float:
                    raise ValueError(
                        "Non-float arguments are not implemented yet.")
                inputs.append(QtGui.QDoubleSpinBox())
                if len(argument) > 1 and argument[1]:
                    inputs[-1].setPrefix(argument[1])
                if len(argument) > 2 and argument[2]:
                    inputs[-1].setSuffix(argument[2])
                if len(argument) > 3 and (argument[3] or argument[3] == 0):
                    inputs[-1].setDecimals(argument[3])
                if len(argument) > 4 and (argument[4] or argument[4] == 0):
                    inputs[-1].setMaximum(argument[4])
                if len(argument) > 5 and (argument[5] or argument[5] == 0):
                    inputs[-1].setMinimum(argument[5])
                hbox.addWidget(inputs[-1])

            def evaluate(inst, func, values):
                def run():
                    try:
                        getattr(inst, func)(*[v.value() for v in values])
                    except Exception as error:
                        logging.exception(error)
                        raise error

                thread = threading.Thread(target=run)
                thread.start()

            write = QtGui.QPushButton()
            write.setText("Send Command")
            write.clicked.connect(partial(evaluate, instrument, method,
                                          inputs))
            hbox.addWidget(write)
            vbox.addLayout(hbox)
        vbox.addStretch()
        tab_widget = QtGui.QWidget()
        tab_widget.setLayout(vbox)
        self.tab.addTab(tab_widget, name)
Пример #28
0
    def update_plot(self, filename):
        for plot in self.plot:
            plot.clear()
        if not os.path.isdir(filename) and filename != '':
            try:
                results = self.procedure_class().load(str(filename))
            except Exception as error:
                try:
                    results = Results.load(str(filename))
                except ValueError:
                    return
                except Exception as e:
                    raise e
            for index, plot_widget in enumerate(self.plot_widget):
                curve_list = plot_widget.new_curve(results)
                for curve in curve_list:
                    curve.update()
                    self.plot[index].addItem(curve)

            self.preview_param.clear()
            for key, param in results.procedure.parameter_objects().items():
                new_item = QtGui.QTreeWidgetItem([param.name, str(param)])
                self.preview_param.addTopLevelItem(new_item)
            self.preview_param.sortItems(0, QtCore.Qt.AscendingOrder)
Пример #29
0
    def __init__(self):
        super(MainWindow,
              self).__init__(procedure_class=DepProcedure,
                             inputs=[
                                 'plate_e', 'pulse', 'delay', 'repeats',
                                 'deltat', 'current_range', 'filename'
                             ],
                             displays=[
                                 'plate_e', 'pulse', 'delay', 'repeats',
                                 'deltat', 'current_range'
                             ],
                             x_axis='Time (s)',
                             y_axis='Potential (V)')
        self.setWindowTitle('Pulsed Electrodeposition - E')

    def queue(self):
        filename = str(DepProcedure.filename)
        #        filename = unique_filename(directory, prefix='IV')

        procedure = self.make_procedure()
        results = Results(procedure, filename)
        experiment = self.new_experiment(results)

        self.manager.queue(experiment)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = MainWindow()
    window.show()
sys.exit(app.exec_())
Пример #30
0
    def _layout(self):
        # main window widget
        self.main = QtGui.QWidget(self)

        # make the parameters dock widget
        inputs_dock = QtGui.QWidget(self)
        inputs_vbox = QtGui.QVBoxLayout()
        inputs_vbox.addWidget(self.inputs)
        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(-1, 6, -1, 6)
        hbox.addStretch()
        hbox.addWidget(self.queue_button)
        hbox.addStretch()
        hbox.addWidget(self.abort_button)
        hbox.addStretch()
        hbox.addWidget(self.abort_all_button)
        hbox.addStretch()
        inputs_vbox.addLayout(hbox)
        inputs_vbox.addStretch()
        inputs_dock.setLayout(inputs_vbox)
        # add the dock to the right
        dock = QtGui.QDockWidget('Parameters')
        dock.setWidget(inputs_dock)
        features = dock.features()
        dock.setFeatures(features & ~QtGui.QDockWidget.DockWidgetClosable)
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)

        # make indicators dock widget on the left
        if self.indicators.inputs or self.persistent_indicators:
            indicator_dock = QtGui.QWidget(self)
            indicator_vbox = QtGui.QVBoxLayout()
            if self.indicators.inputs:
                indicator_vbox.addWidget(self.indicators)
            for indicator in self.persistent_indicators:
                indicator_vbox.addWidget(indicator)
            indicator_vbox.addStretch()
            indicator_dock.setLayout(indicator_vbox)
            indicator_dock_widget = QtGui.QDockWidget('Indicators')
            indicator_dock_widget.setWidget(indicator_dock)
            features = indicator_dock_widget.features()
            indicator_dock_widget.setFeatures(
                features & ~QtGui.QDockWidget.DockWidgetClosable)
            self.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                               indicator_dock_widget)

        # make the browser dock widget
        browser_dock = QtGui.QWidget(self)
        browser_vbox = QtGui.QVBoxLayout()
        browser_vbox.addWidget(self.browser_widget)
        browser_dock.setLayout(browser_vbox)
        # add the dock to the bottom
        browser_dock_widget = QtGui.QDockWidget('Browser')
        browser_dock_widget.setWidget(browser_dock)
        features = browser_dock_widget.features()
        browser_dock_widget.setFeatures(
            features & ~QtGui.QDockWidget.DockWidgetClosable)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, browser_dock_widget)

        # make the plot tabs
        tabs = QtGui.QTabWidget(self.main)
        for index, plot_widget in enumerate(self.plot_widget):
            tabs.addTab(plot_widget, self.plot_names[index])
        tabs.addTab(self.log_widget, "Log")
        self.plot_widget[0].setMinimumSize(100, 200)
        # add the tabs as the main window layout
        vbox = QtGui.QVBoxLayout(self.main)
        vbox.setSpacing(0)
        vbox.addWidget(tabs)
        self.main.setLayout(vbox)

        # set the central widget and show
        self.setCentralWidget(self.main)
        self.main.show()
        self.resize(1400, 1000)