Example #1
0
 def featuresWidget(self):
     features = QWidget()
     featuresLayout = QFormLayout()
     featuresLayout.setSpacing(5)
     featuresLayout.addRow(self.bookLabel, self.bookFeatures())
     featuresLayout.addRow(self.chapterLabel, self.chapterFeatures())
     featuresLayout.addRow(self.verseLabel, self.verseFeatures())
     features.setLayout(featuresLayout)
     return features
Example #2
0
    def __init__(self, parent):
        super().__init__(parent)

        # Create colored icon using theme
        self._image = QLabel()
        self._image.setObjectName("logo_silhouette")
        self._image.setMinimumSize(300, 300)
        self._label = QtWelcomeLabel(
            trans.
            _("Drag image(s) here to open\nor\nUse the menu shortcuts below:"))

        # Widget setup
        self.setAutoFillBackground(True)
        self.setAcceptDrops(True)
        self._image.setAlignment(Qt.AlignCenter)
        self._label.setAlignment(Qt.AlignCenter)

        # Layout
        text_layout = QVBoxLayout()
        text_layout.addWidget(self._label)

        # TODO: Use action manager for shortcut query and handling
        shortcut_layout = QFormLayout()
        sc = QKeySequence('Ctrl+O', QKeySequence.PortableText).toString(
            QKeySequence.NativeText)
        shortcut_layout.addRow(
            QtShortcutLabel(sc),
            QtShortcutLabel(trans._("open image(s)")),
        )
        self._shortcut_label = QtShortcutLabel("")
        shortcut_layout.addRow(
            self._shortcut_label,
            QtShortcutLabel(trans._("show all key bindings")),
        )
        shortcut_layout.setSpacing(0)

        layout = QVBoxLayout()
        layout.addStretch()
        layout.setSpacing(30)
        layout.addWidget(self._image)
        layout.addLayout(text_layout)
        layout.addLayout(shortcut_layout)
        layout.addStretch()

        self.setLayout(layout)
        self._show_shortcuts_updated()
        action_manager.events.shorcut_changed.connect(
            self._show_shortcuts_updated)
class AxisSettingsDisplay(Display):
    def __init__(self, main_display, parent=None):
        super(AxisSettingsDisplay, self).__init__(parent=parent)
        self.main_layout = QFormLayout()
        self.main_display = main_display

        self.chart = self.main_display.chart

        self.x_axis_lbl = QLabel("x-axis Label")
        self.x_axis_label_line_edt = QLineEdit()
        current_x_label = self.chart.labels["bottom"]
        if current_x_label:
            current_x_label = current_x_label[current_x_label.
                                              find(X_AXIS_LABEL_SEPARATOR) +
                                              len(X_AXIS_LABEL_SEPARATOR):]
            self.x_axis_label_line_edt.setText(current_x_label)
        self.x_axis_label_line_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "bottom"))

        self.x_axis_font_btn = QPushButton()
        self.x_axis_font_btn.setMaximumHeight(32)
        self.x_axis_font_btn.setMaximumWidth(32)
        self.x_axis_font_btn.setIcon(IconFont().icon("font"))
        self.x_axis_font_btn.clicked.connect(
            partial(self.handle_font_change, "bottom"))

        self.x_axis_unit_lbl = QLabel("x-axis Unit")
        self.x_axis_unit_edt = QLineEdit()
        self.x_axis_unit_edt.setMaximumWidth(150)
        self.x_axis_unit_edt.setText(self.chart.units["bottom"])
        self.x_axis_unit_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "bottom", is_unit=True))

        self.y_axis_lbl = QLabel("y-axis Label")
        self.y_axis_label_line_edt = QLineEdit()
        self.y_axis_label_line_edt.setText(self.chart.labels["left"])
        self.y_axis_label_line_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "left"))

        self.y_axis_font_btn = QPushButton()
        self.y_axis_font_btn.setMaximumHeight(32)
        self.y_axis_font_btn.setMaximumWidth(32)
        self.y_axis_font_btn.setIcon(IconFont().icon("font"))
        self.y_axis_font_btn.clicked.connect(
            partial(self.handle_font_change, "left"))

        self.y_axis_unit_lbl = QLabel("y-axis Unit")
        self.y_axis_unit_edt = QLineEdit()
        self.y_axis_unit_edt.setMaximumWidth(150)
        self.y_axis_unit_edt.setText(self.chart.units["left"])
        self.y_axis_unit_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "left", is_unit=True))

        self.right_y_axis_label_line_edt = QLineEdit()

        self.display_right_y_axis_chk = QCheckBox("Display the right y-axis")
        self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis())
        self.display_right_y_axis_chk.clicked.connect(
            self.handle_right_y_axis_checkbox_changed)
        self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis())

        self.right_y_axis_lbl = None
        self.right_y_axis_unit_edt = None
        self.right_y_axis_unit_lbl = None
        self.right_y_axis_unit_edt = None

        self.close_dialog_btn = QPushButton("Close")
        self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked)

        self.setWindowTitle("Axis Settings")
        self.setMinimumSize(500, 300)
        self.setWindowModality(Qt.ApplicationModal)

        self.setup_ui()

    def ui_filepath(self):
        """
        The path to the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def ui_filename(self):
        """
        The name of the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def setup_ui(self):
        x_axis_layout = QHBoxLayout()
        x_axis_layout.addWidget(self.x_axis_label_line_edt)
        x_axis_layout.addWidget(self.x_axis_font_btn)

        y_axis_layout = QHBoxLayout()
        y_axis_layout.addWidget(self.y_axis_label_line_edt)
        y_axis_layout.addWidget(self.y_axis_font_btn)

        # Add widgets to the form layout
        self.main_layout.setSpacing(10)
        self.main_layout.addRow(self.x_axis_lbl, x_axis_layout)
        self.main_layout.addRow(self.x_axis_unit_lbl, self.x_axis_unit_edt)
        self.main_layout.addRow(self.y_axis_lbl, y_axis_layout)
        self.main_layout.addRow(self.y_axis_unit_lbl, self.y_axis_unit_edt)
        self.main_layout.addRow(self.display_right_y_axis_chk, None)
        self.main_layout.addRow(None, self.close_dialog_btn)

        self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis())
        if self.chart.getShowRightAxis():
            self.display_right_y_axis_chk.clicked.emit(
                self.chart.getShowRightAxis())

        self.setLayout(self.main_layout)

    def handle_right_y_axis_checkbox_changed(self, is_checked):
        self.chart.setShowRightAxis(is_checked)

        if is_checked:
            right_label = self.chart.labels["right"]
            if not right_label:
                right_label = self.y_axis_label_line_edt.text()
            right_unit = self.chart.units["right"]
            if not right_unit:
                right_unit = self.y_axis_unit_edt.text()

            self.right_y_axis_font_btn = QPushButton()
            self.right_y_axis_font_btn.setMaximumHeight(32)
            self.right_y_axis_font_btn.setMaximumWidth(32)
            self.right_y_axis_font_btn.setIcon(IconFont().icon("font"))
            self.right_y_axis_font_btn.clicked.connect(
                partial(self.handle_font_change, "right"))

            self.right_y_axis_lbl = QLabel("Right y-axis Label")
            self.right_y_axis_label_line_edt = QLineEdit()
            self.right_y_axis_label_line_edt.textChanged.connect(
                partial(self.handle_axis_label_change, "right"))

            self.right_y_axis_unit_lbl = QLabel("Right y-axis Unit")
            self.right_y_axis_unit_edt = QLineEdit()
            self.right_y_axis_unit_edt.setMaximumWidth(150)
            self.right_y_axis_unit_edt.textChanged.connect(
                partial(self.handle_axis_label_change, "right", is_unit=True))

            self.right_y_axis_label_line_edt.setText(right_label)
            self.right_y_axis_unit_edt.setText(right_unit)

            right_y_axis_layout = QHBoxLayout()
            right_y_axis_layout.addWidget(self.right_y_axis_label_line_edt)
            right_y_axis_layout.addWidget(self.right_y_axis_font_btn)

            self.main_layout.insertRow(self.main_layout.rowCount() - 1,
                                       self.right_y_axis_lbl,
                                       right_y_axis_layout)
            self.main_layout.insertRow(self.main_layout.rowCount() - 1,
                                       self.right_y_axis_unit_lbl,
                                       self.right_y_axis_unit_edt)
        else:
            self.chart.showAxis("right", show=False)
            self.right_y_axis_lbl.deleteLater()
            self.right_y_axis_label_line_edt.deleteLater()
            self.right_y_axis_unit_lbl.deleteLater()
            self.right_y_axis_unit_edt.deleteLater()
            self.right_y_axis_font_btn.deleteLater()

    def handle_axis_label_change(self,
                                 axis_position,
                                 new_label,
                                 is_unit=False):
        if is_unit:
            self.chart.setLabel(axis_position, units=new_label)
            self.chart.units[axis_position] = new_label
        else:
            if axis_position == "bottom":
                current_label = self.chart.getBottomAxisLabel()
                if X_AXIS_LABEL_SEPARATOR in current_label:
                    current_label = current_label[:current_label.find(
                        X_AXIS_LABEL_SEPARATOR) - len(X_AXIS_LABEL_SEPARATOR)]
                new_label = current_label + X_AXIS_LABEL_SEPARATOR + new_label
            self.chart.setLabel(axis_position, text=new_label)
            self.chart.labels[axis_position] = new_label
        return

    def change_axis_font(self, axis, font):
        axis.setTickFont(font)
        axis.label.setFont(font)

    def handle_font_change(self, axis_position):
        axis = self.chart.getAxis(axis_position)
        label = axis.label
        initial = axis.tickFont

        dialog = QFontDialog(self)
        if initial:
            dialog.setCurrentFont(initial)
        dialog.setOption(QFontDialog.DontUseNativeDialog, True)
        dialog.fontSelected.connect(partial(self.change_axis_font, axis))
        dialog.open()

    def closeEvent(self, event):
        self.handle_close_button_clicked()

    def handle_close_button_clicked(self):
        """
        Close the dialog when the Close button is clicked.
        """
        self.close()
class ChartDataExportDisplay(Display):
    def __init__(self, main_display, parent=None):
        super(ChartDataExportDisplay, self).__init__(parent=parent)
        self.main_layout = QVBoxLayout()
        self.main_layout.setAlignment(Qt.AlignTop)
        self.main_layout.setSpacing(5)
        self.main_display = main_display

        self.export_options_lbl = QLabel()
        self.export_options_lbl.setText("Export Options")
        self.export_options_cmb = QComboBox()
        self.export_options_cmb.addItems(
            ("Curve Data", "Chart Settings", "Image File"))
        self.export_options_cmb.currentIndexChanged.connect(
            self.handle_export_options_index_changed)

        # Options for Chart Settings
        self.include_pv_chk = QCheckBox("Include currently plotted PVs")
        self.include_pv_chk.setChecked(True)

        self.include_chart_settings_chk = QCheckBox(
            "Include current chart settings")
        self.include_chart_settings_chk.setChecked(True)

        # Options for Image File
        self.image_dimension_layout = QFormLayout()
        self.image_dimension_layout.setSpacing(10)

        self.image_width_lbl = QLabel("Image width")
        self.image_width_edt = QLineEdit()
        self.image_width_edt.editingFinished.connect(
            self.handle_image_dimension_value)
        self.image_width_edt.setText(DEFAULT_EXPORTED_IMAGE_WIDTH)

        self.image_height_lbl = QLabel("Image height")
        self.image_height_edt = QLineEdit()
        self.image_height_edt.editingFinished.connect(
            self.handle_image_dimension_value)
        self.image_height_edt.setText(DEFAULT_EXPORTED_IMAGE_HEIGHT)

        self.anti_alias_chk = QCheckBox("Anti-alias")
        self.anti_alias_chk.setChecked(True)

        self.export_image_background_color_lbl = QLabel("Background Color ")
        self.export_image_background_btn = QPushButton()
        self.export_image_background_btn.setMaximumWidth(20)
        self.export_image_background_btn.setStyleSheet(
            "background-color: black")
        self.export_image_background_btn.clicked.connect(
            self.handle_export_image_background_button_clicked)

        self.export_format_lbl = QLabel()
        self.export_format_lbl.setText("Export Format")
        self.file_format_cmb = QComboBox()
        self.file_format_cmb.addItems(("csv", "json", "png"))
        self.file_format = ""
        self.exported_image_background_color = QColor(Qt.black)

        self.save_file_btn = QPushButton("Export...")
        self.save_file_btn.clicked.connect(self.handle_save_file_btn_clicked)

        self.image_width = 0
        self.image_height = 0

        self.setFixedSize(QSize(300, 150))
        self.setWindowTitle("Export Chart Data")
        self.setWindowModality(Qt.ApplicationModal)
        self.setup_ui()

    def ui_filepath(self):
        """
        The path to the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def ui_filename(self):
        """
        The name of the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def setup_ui(self):
        self.main_layout.addWidget(self.export_options_lbl)
        self.main_layout.addWidget(self.export_options_cmb)
        self.main_layout.addWidget(self.include_pv_chk)
        self.main_layout.addWidget(self.include_chart_settings_chk)

        self.image_dimension_layout.addRow(self.image_width_lbl,
                                           self.image_width_edt)
        self.image_dimension_layout.addRow(self.image_height_lbl,
                                           self.image_height_edt)
        self.main_layout.addLayout(self.image_dimension_layout)

        self.main_layout.addWidget(self.anti_alias_chk)
        self.main_layout.addWidget(self.export_image_background_color_lbl)
        self.main_layout.addWidget(self.export_image_background_btn)
        self.main_layout.addWidget(self.export_format_lbl)
        self.main_layout.addWidget(self.file_format_cmb)
        self.main_layout.addWidget(self.save_file_btn)
        self.setLayout(self.main_layout)

        self.export_options_cmb.currentIndexChanged.emit(0)

        self.image_width_edt.editingFinished.emit()
        self.image_height_edt.editingFinished.emit()

    def handle_export_options_index_changed(self, selected_index):
        if selected_index == 0:
            self.setFixedSize(QSize(300, 150))
            self.main_layout.setAlignment(Qt.AlignTop)
        elif selected_index == 1:
            self.setFixedSize(QSize(300, 200))
            self.main_layout.setAlignment(Qt.AlignTop)
        elif selected_index == 2:
            self.setFixedSize(QSize(300, 300))
            self.main_layout.setAlignment(Qt.AlignVCenter)

        self.include_pv_chk.setVisible(selected_index == 1)
        self.include_chart_settings_chk.setVisible(selected_index == 1)

        self.image_width_lbl.setVisible(selected_index == 2)
        self.image_width_edt.setVisible(selected_index == 2)
        self.image_height_lbl.setVisible(selected_index == 2)
        self.image_height_edt.setVisible(selected_index == 2)
        self.anti_alias_chk.setVisible(selected_index == 2)
        self.export_image_background_color_lbl.setVisible(selected_index == 2)
        self.export_image_background_btn.setVisible(selected_index == 2)

        self.file_format = ""
        self.file_format_cmb.setCurrentIndex(selected_index)
        supported_formats = self.file_format_cmb.currentText().split(",")
        for f in supported_formats:
            self.file_format += "*." + f + ";;"
        self.file_format = self.file_format[:-2]
        self.file_format_cmb.setEnabled(False)

    def handle_save_file_btn_clicked(self):
        saved_file_info = QFileDialog.getSaveFileName(self, caption="Save File",
                                                      filter=self.file_format)
        saved_file_name = saved_file_info[0]
        if saved_file_info[1][1:] not in saved_file_name:
            saved_file_name += saved_file_info[1][1:]

        if saved_file_name:
            if self.export_options_cmb.currentIndex() == 0:
                data_exporter = CSVExporter(self.main_display.chart.plotItem)
                data_exporter.export(saved_file_name)
            elif self.export_options_cmb.currentIndex() == 2:
                image_exporter = TimeChartImageExporter(
                    self.main_display.chart.plotItem)
                image_exporter.params = Parameter(name='params', type='group',
                                                  children=[
                                                      {'name': 'width',
                                                       'type': 'int',
                                                       'value': self.image_width,
                                                       'limits': (0, None)},
                                                      {'name': 'height',
                                                       'type': 'int',
                                                       'value': self.image_height,
                                                       'limits': (0, None)},
                                                      {'name': 'antialias',
                                                       'type': 'bool',
                                                       'value': True},
                                                      {'name': 'background',
                                                       'type': 'color',
                                                       'value': self.exported_image_background_color},
                                                  ])

                image_exporter.widthChanged()
                image_exporter.heightChanged()
                image_exporter.export(fileName=saved_file_name)
            else:
                settings_exporter = SettingsExporter(self.main_display,
                                                     self.include_pv_chk.isChecked(),
                                                     self.include_chart_settings_chk.isChecked())
                settings_exporter.export_settings(saved_file_name)

            self.close()
            QMessageBox.information(self, "Data Export", "Data exported successfully!")

    def handle_export_image_background_button_clicked(self):
        self.exported_image_background_color = QColorDialog.getColor()
        self.export_image_background_btn.setStyleSheet("background-color: " +
                                                       self.exported_image_background_color.name())

    def handle_image_dimension_value(self):
        image_width = self.image_width_edt.text()
        image_height = self.image_height_edt.text()
        try:
            if image_width:
                self.image_width = int(image_width)
                if self.image_width <= 0:
                    raise ValueError
            if image_height:
                self.image_height = int(image_height)
                if self.image_height <= 0:
                    raise ValueError
            elif not image_width and not image_height:
                raise ValueError
        except ValueError:
            display_message_box(QMessageBox.Critical, "Invalid Values",
                                "Only integer values larger than 0 are accepted.")
Example #5
0
class CurveSettingsDisplay(Display):
    def __init__(self, main_display, pv_name, parent=None):
        """
        Create all the widgets for the curve appearance settings.

        Parameters
        ----------
        main_display : TimeChartDisplay
            The main display window
        pv_name: str
            The name of the PV the current curve is being plotted for
        parent : QWidget
            The parent widget, if applicable
        """
        super(CurveSettingsDisplay, self).__init__(parent=parent)
        self.main_layout = QFormLayout()
        self.main_display = main_display

        self.chart = self.main_display.chart
        self.pv_name = pv_name
        self.channel_map = self.main_display.channel_map
        self.app = self.main_display.app

        self.curve_original_color = None
        self.curve_color_lbl = QLabel("Curve Color ")
        self.curve_color_btn = QPushButton()
        self.curve_color_btn.setMaximumWidth(20)
        self.curve_color_btn.clicked.connect(
            self.handle_curve_color_button_clicked)

        self.symbol_lbl = QLabel("Symbol")
        self.symbol_cmb = QComboBox()
        self.symbol_size_lbl = QLabel("Symbol Size")
        self.symbol_size_spin = QSpinBox()

        self.line_style_lbl = QLabel("Line Style")
        self.line_style_cmb = QComboBox()
        self.line_width_lbl = QLabel("Line Width")
        self.line_width_spin = QSpinBox()

        self.set_defaults_btn = QPushButton("Reset")
        self.set_defaults_btn.clicked.connect(self.handle_reset_button_clicked)

        self.close_dialog_btn = QPushButton("Close")
        self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked)

        self.setWindowTitle(self.pv_name.split("://")[1])
        self.setFixedSize(QSize(300, 200))
        self.setWindowModality(Qt.ApplicationModal)

        self.setup_ui()

    def ui_filepath(self):
        """
        The path to the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def ui_filename(self):
        """
        The name of the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def setup_ui(self):
        """
        Initialize the widgets and layouts.
        """
        # Populate the values
        for k, _ in BasePlotCurveItem.symbols.items():
            self.symbol_cmb.addItem(k)
        self.symbol_size_spin.setRange(1, 10)

        for k, _ in BasePlotCurveItem.lines.items():
            self.line_style_cmb.addItem(k)
        self.line_width_spin.setRange(1, 5)

        # Set the widget values to the current settings of the current curve
        self.set_widgets_to_current_curve_settings()

        # Connect to slots to handle signal events
        self.symbol_cmb.currentIndexChanged.connect(
            self.handle_symbol_index_changed)
        self.symbol_size_spin.valueChanged.connect(
            self.handle_symbol_size_changed)

        self.line_style_cmb.currentIndexChanged.connect(
            self.handle_line_style_index_changed)
        self.line_width_spin.valueChanged.connect(
            self.handle_line_width_changed)

        # Add widgets to the form layout
        self.main_layout.setSpacing(10)
        self.main_layout.addRow(self.curve_color_lbl, self.curve_color_btn)
        self.main_layout.addRow(self.symbol_lbl, self.symbol_cmb)
        self.main_layout.addRow(self.symbol_size_lbl, self.symbol_size_spin)
        self.main_layout.addRow(self.line_style_lbl, self.line_style_cmb)
        self.main_layout.addRow(self.line_width_lbl, self.line_width_spin)
        self.main_layout.addRow(self.set_defaults_btn, self.close_dialog_btn)

        # Add the form layout to the main layout of this dialog
        self.setLayout(self.main_layout)

    def set_widgets_to_current_curve_settings(self):
        """
        Make the dialog widgets display the current appearance settings of the current curve.
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            self.curve_color_btn.setStyleSheet("background-color: " +
                                               curve.color.name())

            self.set_combo_box(self.symbol_cmb, BasePlotCurveItem.symbols,
                               curve.symbol)
            self.set_combo_box(self.line_style_cmb, BasePlotCurveItem.lines,
                               curve.lineStyle)

            self.symbol_size_spin.setValue(curve.symbolSize)
            self.line_width_spin.setValue(curve.lineWidth)

    def set_combo_box(self, combo_box, reference_dict, curve_setting_value):
        """
        Reverse look up for a dictionary key using a dictionary value, and then set that value to a QComboBox widget.

        Parameters
        ----------
        combo_box : QComboBox
            The combo box to set the current value for
        reference_dict : dict
            The reference dict to find the key from a value to set the combo box
        curve_setting_value : str
            The setting value to look for from the reference_dict
        """
        for k, v in reference_dict.items():
            if curve_setting_value == v:
                combo_box.setCurrentText(k)
                break

    def handle_curve_color_button_clicked(self):
        selected_color = QColorDialog.getColor()
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            self.curve_original_color = curve.color
            curve.color = selected_color
            self.curve_color_btn.setStyleSheet("background-color: " +
                                               curve.color.name())

            self.chart.refreshCurve(curve)
            self.channel_map[self.pv_name] = curve

    def handle_symbol_index_changed(self, selected_index):
        """
        Handle the change in the curve's symbol from a combo box.

        Parameters
        ----------
        selected_index : int
            The currently selected index from the symbol combo box
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            curve.symbol = BasePlotCurveItem.symbols[self.symbol_cmb.itemText(
                selected_index)]
            self.chart.refreshCurve(curve)
            self.channel_map[self.pv_name] = curve

    def handle_symbol_size_changed(self, new_size):
        """
        Handle the symbol size value change from the symbol size spinner.

        Parameters
        ----------
        new_size : int
            The new symbol size set by the user.
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            curve.symbolSize = new_size
            self.chart.refreshCurve(curve)
            self.channel_map[self.pv_name] = curve

    def handle_line_width_changed(self, new_width):
        """
        Handle the symbol size value change from the line width spinner.

        Parameters
        ----------
        new_width: int
            The new line width set by the user.
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            curve.lineWidth = new_width
            self.chart.refreshCurve(curve)
            self.channel_map[self.pv_name] = curve

    def handle_line_style_index_changed(self, selected_index):
        """
        Handle the change in the curve's line style from a combo box.

        Parameters
        ----------
        selected_index : int
            The currently selected index from the line style combo box
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            curve.lineStyle = BasePlotCurveItem.lines[
                self.line_style_cmb.itemText(selected_index)]
            self.chart.refreshCurve(curve)
            self.channel_map[self.pv_name] = curve

    def handle_reset_button_clicked(self):
        """
        Handle the click of the Reset button. This will set all the dialog widgets to the default curve appearance
        settings.
        """
        curve = self.chart.findCurve(self.pv_name)
        if curve:
            if self.curve_original_color:
                curve.color = self.curve_original_color
                self.curve_color_btn.setStyleSheet("background-color: " +
                                                   curve.color.name())

            self.symbol_cmb.setCurrentIndex(0)
            self.symbol_size_spin.setValue(10)

            self.line_style_cmb.setCurrentIndex(1)
            self.line_width_spin.setValue(1)

    def closeEvent(self, event):
        self.handle_close_button_clicked()

    def handle_close_button_clicked(self):
        """
        Close the dialog when the Close button is clicked.
        """
        self.close()

        curve = self.chart.findCurve(self.pv_name)
        if curve:
            # Update the widget checkbox text to the current curve color
            widget = self.main_display.findChild(QGroupBox,
                                                 self.pv_name + "_grb")
            chb = widget.findChild(QCheckBox, self.pv_name + "_chb")
            lbl = widget.findChild(QLabel, self.pv_name + "_lbl")
            widget = [chb, lbl]
            for w in widget:
                palette = w.palette()
                palette.setColor(QPalette.Active, QPalette.WindowText,
                                 curve.color)
                w.setPalette(palette)
Example #6
0
class AxisSettingsDisplay(Display):
    def __init__(self, main_display, parent=None):
        super(AxisSettingsDisplay, self).__init__(parent=parent)
        self.main_layout = QFormLayout()
        self.main_display = main_display

        self.chart = self.main_display.chart
        self.app = self.main_display.app

        self.x_axis_lbl = QLabel("x-axis Label")
        self.x_axis_label_line_edt = QLineEdit()
        current_x_label = self.chart.labels["bottom"]
        if current_x_label:
            current_x_label = current_x_label[current_x_label.
                                              find(X_AXIS_LABEL_SEPARATOR) +
                                              len(X_AXIS_LABEL_SEPARATOR):]
            self.x_axis_label_line_edt.setText(current_x_label)
        self.x_axis_label_line_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "bottom"))

        self.x_axis_unit_lbl = QLabel("x-axis Unit")
        self.x_axis_unit_edt = QLineEdit()
        self.x_axis_unit_edt.setText(self.chart.units["bottom"])
        self.x_axis_unit_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "bottom", is_unit=True))

        self.y_axis_lbl = QLabel("y-axis Label")
        self.y_axis_label_line_edt = QLineEdit()
        self.y_axis_label_line_edt.setText(self.chart.labels["left"])
        self.y_axis_label_line_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "left"))

        self.y_axis_unit_lbl = QLabel("y-axis Unit")
        self.y_axis_unit_edt = QLineEdit()
        self.y_axis_unit_edt.setText(self.chart.units["left"])
        self.y_axis_unit_edt.textChanged.connect(
            partial(self.handle_axis_label_change, "left", is_unit=True))

        self.right_y_axis_label_line_edt = QLineEdit()
        self.right_y_axis_lbl = QLabel("Right y-axis Label")

        self.display_right_y_axis_chk = QCheckBox("Display the right y-axis")
        self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis())
        self.display_right_y_axis_chk.clicked.connect(
            self.handle_right_y_axis_checkbox_changed)
        self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis())

        self.right_y_axis_lbl = None
        self.right_y_axis_unit_edt = None
        self.right_y_axis_unit_lbl = None
        self.right_y_axis_unit_edt = None

        self.close_dialog_btn = QPushButton("Close")
        self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked)

        self.setWindowTitle("Axis Settings")
        self.setFixedSize(QSize(300, 250))
        self.setWindowModality(Qt.ApplicationModal)

        self.setup_ui()

    def ui_filepath(self):
        """
        The path to the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def ui_filename(self):
        """
        The name of the UI file created by Qt Designer, if applicable.
        """
        # No UI file is being used
        return None

    def setup_ui(self):
        # Add widgets to the form layout
        self.main_layout.setSpacing(10)
        self.main_layout.addRow(self.x_axis_lbl, self.x_axis_label_line_edt)
        self.main_layout.addRow(self.x_axis_unit_lbl, self.x_axis_unit_edt)
        self.main_layout.addRow(self.y_axis_lbl, self.y_axis_label_line_edt)
        self.main_layout.addRow(self.y_axis_unit_lbl, self.y_axis_unit_edt)
        self.main_layout.addRow(self.display_right_y_axis_chk, None)
        self.main_layout.addRow(None, self.close_dialog_btn)

        self.setLayout(self.main_layout)

        if self.chart.getShowRightAxis():
            self.display_right_y_axis_chk.clicked.emit(True)

    def handle_right_y_axis_checkbox_changed(self, is_checked):
        self.chart.setShowRightAxis(is_checked)

        # Remove the Close button first
        self.main_layout.removeRow(self.main_layout.rowCount() - 1)

        if is_checked:
            right_label = self.chart.labels["right"]
            if not right_label:
                right_label = self.y_axis_label_line_edt.text()
            right_unit = self.chart.units["right"]
            if not right_unit:
                right_unit = self.y_axis_unit_edt.text()

            self.right_y_axis_label_line_edt.textChanged.connect(
                partial(self.handle_axis_label_change, "right"))

            self.right_y_axis_unit_lbl = QLabel(text="Right y-axis Unit")
            self.right_y_axis_unit_edt = QLineEdit()
            self.right_y_axis_unit_edt.textChanged.connect(
                partial(self.handle_axis_label_change, "right", is_unit=True))

            self.right_y_axis_label_line_edt.setText(right_label)
            self.right_y_axis_unit_edt.setText(right_unit)

            self.main_layout.addRow(self.right_y_axis_lbl,
                                    self.right_y_axis_label_line_edt)
            self.main_layout.addRow(self.right_y_axis_unit_lbl,
                                    self.right_y_axis_unit_edt)
        else:
            self.chart.showAxis("right", show=False)

            for i in range(2):
                self.main_layout.removeRow(self.main_layout.rowCount() - 1)

        # Add the Close button back
        self.close_dialog_btn = QPushButton("Close")
        self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked)
        self.main_layout.addRow(None, self.close_dialog_btn)

        self.app.establish_widget_connections(self.main_display)

    def handle_axis_label_change(self,
                                 axis_position,
                                 new_label,
                                 is_unit=False):
        if is_unit:
            self.chart.setLabel(axis_position, units=new_label)
            self.chart.units[axis_position] = new_label
        else:
            if axis_position == "bottom":
                current_label = self.chart.getBottomAxisLabel()
                if X_AXIS_LABEL_SEPARATOR in current_label:
                    current_label = current_label[:current_label.find(
                        X_AXIS_LABEL_SEPARATOR) - len(X_AXIS_LABEL_SEPARATOR)]
                new_label = current_label + X_AXIS_LABEL_SEPARATOR + new_label
            self.chart.setLabel(axis_position, text=new_label)
            self.chart.labels[axis_position] = new_label
        return

    def closeEvent(self, event):
        self.handle_close_button_clicked()

    def handle_close_button_clicked(self):
        """
        Close the dialog when the Close button is clicked.
        """
        self.close()
Example #7
0
    def _setupSettingsLayout(self):
        label_CamEnbl = QLabel('Enable:', self)
        hbox_CamEnbl = create_propty_layout(parent=self,
                                            prefix=self.cam_prefix,
                                            propty='Enbl',
                                            propty_type='enbldisabl',
                                            width=3)

        label_FrameCnt = QLabel('Frame Count:', self)
        hbox_FrameCnt = create_propty_layout(parent=self,
                                             prefix=self.cam_prefix,
                                             propty='FrameCnt',
                                             propty_type='mon')

        label_Conn = QLabel('Connection:', self)
        hbox_Conn = create_propty_layout(parent=self,
                                         prefix=self.cam_prefix,
                                         propty='Connection',
                                         propty_type='mon')

        label_Reset = QLabel('Reset Camera:', self)
        self.pb_dtl = PyDMPushButton(
            label='',
            icon=qta.icon('fa5s.sync'),
            parent=self,
            pressValue=1,
            init_channel=self.cam_prefix.substitute(propty='Rst-Cmd'))
        self.pb_dtl.setObjectName('reset')
        self.pb_dtl.setStyleSheet(
            "#reset{min-width:25px; max-width:25px; icon-size:20px;}")

        flay_sts = QFormLayout()
        flay_sts.setSpacing(6)
        flay_sts.setFormAlignment(Qt.AlignHCenter)
        flay_sts.setLabelAlignment(Qt.AlignRight)
        flay_sts.addRow(label_CamEnbl, hbox_CamEnbl)
        flay_sts.addRow(label_FrameCnt, hbox_FrameCnt)
        flay_sts.addRow(label_Conn, hbox_Conn)
        flay_sts.addRow(label_Reset, self.pb_dtl)

        label_AcqMode = QLabel('Acq. Mode:', self)
        hbox_AcqMode = create_propty_layout(parent=self,
                                            prefix=self.cam_prefix,
                                            propty='AcqMode',
                                            propty_type='enum')

        label_AcqPeriod = QLabel('Acq. Period [s]:', self)
        hbox_AcqPeriod = create_propty_layout(parent=self,
                                              prefix=self.cam_prefix,
                                              propty='AcqPeriod',
                                              propty_type='sprb')

        label_ExpTime = QLabel('Exp. Time [us]:', self)
        hbox_ExpTime = create_propty_layout(parent=self,
                                            prefix=self.cam_prefix,
                                            propty='ExposureTime',
                                            propty_type='sprb')

        label_Gain = QLabel('Gain [dB]:', self)
        hbox_Gain = create_propty_layout(parent=self,
                                         prefix=self.cam_prefix,
                                         propty='Gain',
                                         propty_type='sprb',
                                         cmd={
                                             'label': '',
                                             'pressValue': 1,
                                             'width': '25',
                                             'height': '25',
                                             'icon': qta.icon('mdi.auto-fix'),
                                             'icon-size': '20',
                                             'toolTip': 'Auto Gain',
                                             'name': 'AutoGain'
                                         })

        flay_ctrl = QFormLayout()
        flay_ctrl.setSpacing(6)
        flay_ctrl.setFormAlignment(Qt.AlignHCenter)
        flay_ctrl.setLabelAlignment(Qt.AlignRight)
        flay_ctrl.addRow(label_AcqMode, hbox_AcqMode)
        flay_ctrl.addRow(label_AcqPeriod, hbox_AcqPeriod)
        flay_ctrl.addRow(label_ExpTime, hbox_ExpTime)
        flay_ctrl.addRow(label_Gain, hbox_Gain)

        self.pb_details = QPushButton(qta.icon('fa5s.ellipsis-h'), '', self)
        self.pb_details.setToolTip('More settings')
        self.pb_details.setObjectName('detail')
        self.pb_details.setStyleSheet(
            "#detail{min-width:25px; max-width:25px; icon-size:20px;}")
        self.pb_details.setSizePolicy(QSzPlcy.Expanding, QSzPlcy.Preferred)
        MyWindow = create_window_from_widget(BaslerCamSettings,
                                             title=self.device +
                                             ' Settings Details',
                                             is_main=True)
        util.connect_window(self.pb_details,
                            MyWindow,
                            parent=self,
                            prefix=self.prefix,
                            device=self.device)

        lay = QHBoxLayout()
        lay.setSpacing(20)
        lay.addLayout(flay_sts)
        lay.addLayout(flay_ctrl)
        lay.addWidget(self.pb_details, alignment=Qt.AlignTop)
        return lay