def __check_if_settings_ok(self): """Check that all the settings are okay. Return: True if the settings are okay and false if some required fields are empty. """ settings_ok = True help_sum = 0 elem_widgets = self.get_element_widgets() # Check if 'scrollArea' is empty (no elements). if not elem_widgets: iv.set_input_field_red(self.scrollArea) settings_ok = False # Check that the element specific settings are okay. for widget in elem_widgets: elem = widget.get_selected_element() if elem is None: settings_ok = False else: help_sum += elem.amount if isclose(help_sum, 1.0, rel_tol=1e-6) or isclose(help_sum, 100.0, rel_tol=1e-6): for widget in elem_widgets: iv.set_input_field_white(widget.amount_spinbox) self.amount_mismatch = False else: for widget in elem_widgets: iv.set_input_field_red(widget.amount_spinbox) settings_ok = False self.amount_mismatch = True self.fields_are_valid = settings_ok
def __add_sample(self): dialog = NewSampleDialog(self.samples) if dialog.name: self.samplesComboBox.addItem(dialog.name) self.samplesComboBox.setCurrentIndex( self.samplesComboBox.findText(dialog.name)) iv.set_input_field_white(self.samplesComboBox)
def __init__(self, value=0.0, minimum=0.0, maximum=math.inf, decimal_places=17, show_btns=True): """ Initializes the spinbox. Args: value: value of spinbox minimum: minimum allowed value maximum: maximum allowed value decimal_places: maximum number of decimals to show show_btns: Whether buttons that increase or decrease the value are shown. """ super().__init__() uic.loadUi(gutils.get_ui_dir() / "ui_scientific_spinbox_widget.ui", self) self._value = Decimal(str(value)) self.minimum = minimum self.maximum = maximum if decimal_places < 1: self._decimal_places = 1 elif decimal_places > 17: self._decimal_places = 17 else: self._decimal_places = decimal_places self.scientificLineEdit: QtWidgets.QLineEdit self._validator = ScientificValidator( self.minimum, self.maximum, self._decimal_places, self, accepted=lambda: iv.set_input_field_white(self.scientificLineEdit), intermediate=lambda: iv.set_input_field_yellow(self. scientificLineEdit), invalid=lambda: iv.set_input_field_red(self.scientificLineEdit)) self.scientificLineEdit.setValidator(self._validator) self.set_value(self._value) if show_btns: self.upButton.clicked.connect( lambda *_: self._step_adjustment(self._up_step)) self.downButton.clicked.connect( lambda *_: self._step_adjustment(self._down_step)) else: self.upButton.hide() self.downButton.hide()