Пример #1
0
    def __init__(self, layout: QtWidgets.QLayout, text: str = None, value: str = None):
        """ A colored button what acts as an color input

        Args:
            layout: the layout to which to add the widget
            text: the label text
            value: the value of the color widget
        """
        super().__init__()
        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self)

        if text is not None:
            self.label = QtWidgets.QLabel(text)
            self.layout.addWidget(self.label)

        self.button = QtWidgets.QPushButton()
        self.layout.addWidget(self.button)

        self.button.clicked.connect(self.OpenDialog)
        # default value for the color
        if value is None:
            value = "#FF0000FF"
        # set the color
        self.setColor(value)

        self.editingFinished = self.valueChanged
Пример #2
0
def _add_label(
        layout: QtWidgets.QLayout,
        text: Optional[str],
        object_name: Optional[str] = None) -> Optional[QtWidgets.QLabel]:
    """
    Create a QLabel with the given text and object name in the given layout.

    Configures the label to open external links.

    Parameters
    ----------
    layout : `QtWidgets.QLayout`
        The layout to add the label to.

    text : str, optional
        The initial text to set.

    object_name : str, optional
        The object name to set.

    Returns
    -------
    `QtWidgets.QLabel`
    """
    text = text or ""
    label = QtWidgets.QLabel(text)
    label.setOpenExternalLinks(True)
    layout.addWidget(label)
    label.setObjectName(
        str(object_name or text.replace(" ", "_")[:20] or "label"))
    return label
Пример #3
0
    def __init__(self, layout: QtWidgets.QLayout, text: str, multiline: bool = False, horizontal: bool = True):
        """ a text input widget with a label.

        Args:
            layout: the layout to which to add the widget
            text: the label text
            multiline: whether the text input should be a single line or not
            horizontal:  whether the layout should be left or above the input
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        if horizontal:
            self.layout = QtWidgets.QHBoxLayout(self)
        else:
            self.layout = QtWidgets.QVBoxLayout(self)
        self.label = QtWidgets.QLabel(text)
        self.layout.addWidget(self.label)
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.multiline = multiline
        if multiline:
            self.input1 = QtWidgets.QTextEdit()
            self.input1.textChanged.connect(self.valueChangeEvent)
            self.input1.text = self.input1.toPlainText
        else:
            self.input1 = QtWidgets.QLineEdit()
            self.input1.editingFinished.connect(self.valueChangeEvent)
        self.layout.addWidget(self.input1)
Пример #4
0
    def __init__(self, layout: QtWidgets.QLayout, text: str, min: float = None, use_float: bool = True):
        """ A spin box with a label next to it.

        Args:
            layout: the layout to which to add the widget
            text: the label text
            min: the minimum value of the spin box
            use_float: whether to use a float spin box or an int spin box.
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        self.layout = QtWidgets.QHBoxLayout(self)
        self.label = QtWidgets.QLabel(text)
        self.layout.addWidget(self.label)
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.type = float if use_float else int
        if use_float is False:
            self.input1 = QtWidgets.QSpinBox()
        else:
            self.input1 = QtWidgets.QDoubleSpinBox()
        if min is not None:
            self.input1.setMinimum(min)
        self.input1.valueChanged.connect(self.valueChangeEvent)
        self.layout.addWidget(self.input1)
Пример #5
0
def hide_items_in_layout(
        layout: QtWidgets.QLayout
):
    """Hides all items within a Qt-layout
    """
    for i in range(layout.count()):
        item = layout.itemAt(i)
        if type(item) == QtWidgets.QWidgetItem:
            item.widget().hide()
Пример #6
0
 def addWidget(layout: QLayout, widget: QWidget, label: str = ""):
     """Add widget to arbitrary layout with optional label."""
     if isinstance(layout, QFormLayout):
         return layout.addRow(label, widget)
     elif isinstance(layout, (QHBoxLayout, QVBoxLayout)):
         if label:
             label_widget = QLabel(label)
             label_widget.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
             layout.addWidget(label_widget)
         return layout.addWidget(widget)
Пример #7
0
def HiddeableLayout(parent_layout: QtWidgets.QLayout, layout_class: QtWidgets.QLayout) -> QtWidgets.QLayout:
    widget = QtWidgets.QWidget()
    parent_layout.addWidget(widget)
    new_layout = layout_class(widget)
    new_layout.widget = widget
    new_layout.setHidden = widget.setHidden
    new_layout.setVisible = widget.setVisible
    new_layout.isHidden = widget.isHidden
    new_layout.isVisible = widget.isVisible
    return new_layout
Пример #8
0
def clear_layout(
        layout: QtWidgets.QLayout
):
    """Clears all widgets within a layout
    """
    while layout.count():
        child = layout.takeAt(0)
        if child.widget() is not None:
            child.widget().deleteLater()
        elif child.layout() is not None:
            clear_layout(child.layout())
Пример #9
0
def clearLayout(layout: QLayout) -> None:
    if layout.count() == 0:
        return

    item: QLayoutItem = layout.takeAt(0)
    while item is not None:
        if item.widget() is not None:
            item.widget().deleteLater()
        elif item.layout() is not None:
            item.layout().deleteLater()

        item = layout.takeAt(0)
Пример #10
0
 def setGeometry(self, rect):
     """
     Reorganizes columns and rows and resizes managed items within a
     rectangle.
     """
     QLayout.setGeometry(self, rect)
     if self.isEmpty():
         return
     self.__data.numColumns = self.columnsForWidth(rect.width())
     self.__data.numRows = self.itemCount() / self.__data.numColumns
     if self.itemCount() % self.__data.numColumns:
         self.__data.numRows += 1
     itemGeometries = self.layoutItems(rect, self.__data.numColumns)
     for it, geo in zip(self.__data.itemList, itemGeometries):
         it.setGeometry(geo)
Пример #11
0
    def __init__(self, layout: QtWidgets.QLayout, text: str, join: str, unit: str, free: bool = False):
        """ a widget that lets the user input a pair of dimensions (e.g. widh and height)

        Args:
            layout: the layout to which to add the widget
            text: the label of the widget
            join: a text between the two parts
            unit: a unit for the values
            free: whether to use free number input widgets instead of QSpinBox
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        self.layout = QtWidgets.QHBoxLayout(self)
        self.text = QtWidgets.QLabel(text)
        self.layout.addWidget(self.text)
        self.layout.setContentsMargins(0, 0, 0, 0)

        if free:
            self.input1 = FreeNumberInput()
        else:
            self.input1 = QtWidgets.QDoubleSpinBox()
            self.input1.setSuffix(" " + unit)
            self.input1.setSingleStep(0.1)
            self.input1.setMaximum(99999)
            self.input1.setMinimum(-99999)
        self.input1.valueChanged.connect(self.onValueChanged)
        self.layout.addWidget(self.input1)

        self.text2 = QtWidgets.QLabel(join)
        self.text2.setMaximumWidth(self.text2.fontMetrics().width(join))
        self.layout.addWidget(self.text2)

        if free:
            self.input2 = FreeNumberInput()
        else:
            self.input2 = QtWidgets.QDoubleSpinBox()
            self.input2.setSuffix(" " + unit)
            self.input2.setSingleStep(0.1)
            self.input2.setMaximum(99999)
            self.input2.setMinimum(-99999)
        self.input2.valueChanged.connect(self.onValueChanged)
        self.layout.addWidget(self.input2)

        self.editingFinished = self.valueChanged
Пример #12
0
 def __init__(self, *args):
     self.__data = None
     parent = None
     margin = 0
     spacing = -1
     if len(args) in (2, 3):
         parent, margin = args[:2]
         if len(args) == 3:
             spacing = args[-1]
     elif len(args) == 1:
         if isinstance(args[0], int):
             (spacing, ) = args
         else:
             (parent, ) = args
     elif len(args) != 0:
         raise TypeError("%s() takes 0, 1, 2 or 3 argument(s) (%s given)" %
                         (self.__class__.__name__, len(args)))
     QLayout.__init__(self, parent)
     self.__data = QwtDynGridLayout_PrivateData()
     self.setSpacing(spacing)
     self.setContentsMargins(margin, margin, margin, margin)
Пример #13
0
    def __init__(
            self,
            fit: chisurf.fitting.fit.FitGroup,
            control_layout: QtWidgets.QLayout,
            close_confirm: bool = None,
            fit_widget: chisurf.fitting.widgets.FittingControllerWidget = None,
            *args,
            **kwargs):
        super().__init__(*args, **kwargs)
        self.fit = fit
        self.fit_widget = fit_widget
        if close_confirm is None:
            close_confirm = chisurf.settings.gui['confirm_close_fit']
        self.close_confirm = close_confirm

        layout = self.layout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.plot_tab_widget = QtWidgets.QTabWidget()
        layout.addWidget(self.plot_tab_widget)

        self.current_plt_ctrl = QtWidgets.QWidget(self)
        self.current_plt_ctrl.hide()

        plots = list()
        for plot_class, kwargs in fit.model.plot_classes:
            plot = plot_class(fit, **kwargs)
            plot.pltControl.hide()
            plots.append(plot)
            self.plot_tab_widget.addTab(plot, plot_class.name)
            control_layout.addWidget(plot.pltControl)

        fit.plots = plots
        for f in fit:
            f.plots = plots

        self.on_change_plot()
        self.plot_tab_widget.currentChanged.connect(self.on_change_plot)
        xs, ys = chisurf.settings.cs_settings['gui']['fit_windows_size']
        self.resize(xs, ys)
Пример #14
0
    def __init__(self, layout: QtWidgets.QLayout, simulation: springModule, window: "Window"):
        super().__init__()
        layout.addWidget(self)
        self.mysim = simulation
        self.window = window
        self.signal = window.simulation_changed
        layout = QtWidgets.QVBoxLayout(self)
        self.list = MyList(layout)
        self.updateList()
        self.list.currentItemChanged.connect(self.selected)
        self.input_properties = {}
        for name, widget in [["Spring", PropertiesSpring], ["Dashpot", PropertiesDashpot], ["Force", PropertiesForce], ["SinForce", PropertiesSinForce]]:
            self.input_properties[name] = widget(layout, window.simulation_changed)
            self.input_properties[name].setVisible(False)

        self.input_remove = QtWidgets.QPushButton("remove")
        self.input_remove.clicked.connect(self.remove)
        layout.addWidget(self.input_remove)
        layout = QtWidgets.QHBoxLayout()
        self.layout().addLayout(layout)
        self.input_type = QInputChoice(layout, "Type", Spring, [Spring, Dashpot, Force, SinForce], ["Spring", "Dashpot", "Force", "SinForce"])
        self.input_add = QtWidgets.QPushButton("add")
        self.input_add.clicked.connect(self.add)
        layout.addWidget(self.input_add)

        window.simulation_changed.connect(self.updateList)
Пример #15
0
    def __init__(self, layout: QtWidgets.QLayout, texts: Sequence[str]):
        """ a group of radio buttons

        Args:
            layout: the layout to which to add the widget
            texts: the text label
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.radio_buttons = []

        self.texts = texts

        for name in texts:
            radio = QtWidgets.QRadioButton(name)
            radio.toggled.connect(self.onToggled)
            self.layout.addWidget(radio)
            self.radio_buttons.append(radio)
        self.radio_buttons[0].setChecked(True)
Пример #16
0
 def insertWidget(layout: QLayout, position: int, widget: QWidget, label: str = ""):
     """Add widget to arbitrary layout at position, with optional label."""
     if position < 0:
         position = layout.count() + position + 1
     if isinstance(layout, QFormLayout):
         layout.insertRow(position, label, widget)
     else:
         layout.insertWidget(position, widget)
         if label:
             label_widget = QLabel(label)
             label_widget.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
             layout.insertWidget(position, label_widget)
Пример #17
0
    def __init__(self, layout: QtWidgets.QLayout, text: str, values: Sequence):
        """ A combo box widget with a label

        Args:
            layout: the layout to which to add the widget
            text: the label text
            values: the possible values of the combo box
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        self.layout = QtWidgets.QHBoxLayout(self)
        self.label = QtWidgets.QLabel(text)
        self.layout.addWidget(self.label)
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.values = values

        self.input1 = QtWidgets.QComboBox()
        self.input1.addItems(values)
        self.layout.addWidget(self.input1)

        self.input1.currentIndexChanged.connect(self.valueChangeEvent)
        self.layout.addWidget(self.input1)
Пример #18
0
    def __init__(self, layout: QtWidgets.QLayout, simulation: springModule, window: "Window"):
        super().__init__()
        layout.addWidget(self)
        self.mysim = simulation
        self.window = window
        layout = QtWidgets.QVBoxLayout(self)
        self.list = MyList(layout)
        self.updateList()
        self.list.currentItemChanged.connect(self.selected)
        self.input_properties = PropertiesPoint(layout, window.simulation_changed)

        self.input_remove = QtWidgets.QPushButton("remove")
        self.input_remove.clicked.connect(self.remove)
        layout.addWidget(self.input_remove)
        self.input_add = QtWidgets.QPushButton("add")
        self.input_add.clicked.connect(self.add)
        layout.addWidget(self.input_add)

        window.simulation_changed.connect(self.updateList)
Пример #19
0
def get_widgets_in_layout(
        layout: QtWidgets.QLayout
):
    """Returns a list of all widgets within a layout
    """
    return (layout.itemAt(i) for i in range(layout.count()))
Пример #20
0
    def __init__(self,
                 fitting_parameter: chisurf.fitting.parameter.
                 FittingParameter = None,
                 layout: QtWidgets.QLayout = None,
                 decimals: int = None,
                 hide_label: bool = None,
                 hide_error: bool = None,
                 fixable: bool = None,
                 hide_bounds: bool = None,
                 name: str = None,
                 label_text: str = None,
                 hide_link: bool = None):
        if hide_link is None:
            hide_link = parameter_settings['hide_link']
        if hide_bounds is None:
            hide_bounds = parameter_settings['hide_bounds']
        if name is None:
            name = self.__class__.__name__
        if label_text is None:
            label_text = name
        if fixable is None:
            fixable = parameter_settings['fixable']
        hide_fix_checkbox = fixable
        if hide_error is None:
            hide_error = parameter_settings['hide_error']
        if hide_label is None:
            hide_label = parameter_settings['hide_label']
        if decimals is None:
            decimals = parameter_settings['decimals']

        if fitting_parameter is None:
            fitting_parameter = chisurf.fitting.parameter.FittingParameter(
                name=name, value=1.0)
        self.fitting_parameter = fitting_parameter

        self.widget_value = pg.SpinBox(dec=True, decimals=decimals)
        self.horizontalLayout.addWidget(self.widget_value)

        self.widget_lower_bound = pg.SpinBox(dec=True, decimals=decimals)
        self.horizontalLayout_2.addWidget(self.widget_lower_bound)

        self.widget_upper_bound = pg.SpinBox(dec=True, decimals=decimals)
        self.horizontalLayout_2.addWidget(self.widget_upper_bound)

        # Hide and disable widgets
        self.label.setVisible(not hide_label)
        self.lineEdit.setVisible(not hide_error)
        self.widget_bounds_on.setDisabled(hide_bounds)
        self.widget_fix.setVisible(fixable or not hide_fix_checkbox)
        self.widget.setHidden(hide_bounds)
        self.widget_link.setDisabled(hide_link)

        # Display of values
        self.widget_value.setValue(float(self.fitting_parameter.value))
        self.label.setText(label_text.ljust(5))

        # variable bounds
        if not self.fitting_parameter.bounds_on:
            self.widget_bounds_on.setCheckState(QtCore.Qt.Unchecked)
        else:
            self.widget_bounds_on.setCheckState(QtCore.Qt.Checked)

        # variable fixed
        if self.fitting_parameter.fixed:
            self.widget_fix.setCheckState(QtCore.Qt.Checked)
        else:
            self.widget_fix.setCheckState(QtCore.Qt.Unchecked)
        self.widget.hide()

        # The variable value
        self.widget_value.editingFinished.connect(lambda: chisurf.run(
            "cs.current_fit.model.parameters_all_dict['%s'].value = %s\n"
            "cs.current_fit.update()" %
            (self.fitting_parameter.name, self.widget_value.value())))

        self.widget_fix.toggled.connect(lambda: chisurf.run(
            "cs.current_fit.model.parameters_all_dict['%s'].fixed = %s" %
            (self.fitting_parameter.name, self.widget_fix.isChecked())))

        # Variable is bounded
        self.widget_bounds_on.toggled.connect(lambda: chisurf.run(
            "cs.current_fit.model.parameters_all_dict['%s'].bounds_on = %s" %
            (self.fitting_parameter.name, self.widget_bounds_on.isChecked())))

        self.widget_lower_bound.editingFinished.connect(lambda: chisurf.run(
            "cs.current_fit.model.parameters_all_dict['%s'].bounds = (%s, %s)"
            % (self.fitting_parameter.name, self.widget_lower_bound.value(),
               self.widget_upper_bound.value())))

        self.widget_upper_bound.editingFinished.connect(lambda: chisurf.run(
            "cs.current_fit.model.parameters_all_dict['%s'].bounds = (%s, %s)"
            % (self.fitting_parameter.name, self.widget_lower_bound.value(),
               self.widget_upper_bound.value())))

        self.widget_link.clicked.connect(self.onLinkFitGroup)

        if isinstance(layout, QtWidgets.QLayout):
            layout.addWidget(self)
Пример #21
0
 def __init__(self, parent=None, margin=-1, h_spacing=-1, v_spacing=-1):
     QLayout.__init__(self, parent)
     self.setContentsMargins(margin, margin, margin, margin)
     self.m_h_space = h_spacing
     self.m_v_space = v_spacing
     self.item_list = []
Пример #22
0
 def invalidate(self):
     """Invalidate all internal caches"""
     self.__data.isDirty = True
     QLayout.invalidate(self)
Пример #23
0
 def __init__(self, parent=None, margin=-1, h_spacing=-1, v_spacing=-1):
     QLayout.__init__(self, parent)
     self.setContentsMargins(margin, margin, margin, margin)
     self.m_h_space = h_spacing
     self.m_v_space = v_spacing
     self.item_list = []
Пример #24
0
 def __init__(self, layout: QtWidgets.QLayout, signal: QtCore.Signal):
     super().__init__()
     self.signal = signal
     layout.addWidget(self)
     QtWidgets.QVBoxLayout(self)