def update_edit_color(a_edit: QtWidgets.QLineEdit):
        try:
            utils.parse_input(a_edit.text())

            a_edit.setStyleSheet(qt_utils.QSTYLE_COLOR_WHITE)
        except ValueError:
            a_edit.setStyleSheet(qt_utils.QSTYLE_COLOR_RED)
Example #2
0
    def accept_parameters(self):
        flash_table = []
        try:
            for row in range(self.ui.flash_table.rowCount()):
                flash_table.append(
                    FlashTableRow(number=int(
                        self.ui.flash_table.item(
                            row, EditMeasureParametersDialog.FlashColumn.NUMBER
                        ).text()),
                                  eeprom_offset=int(
                                      self.ui.flash_table.item(
                                          row, EditMeasureParametersDialog.
                                          FlashColumn.EEPROM_OFFSET).text()),
                                  size=int(
                                      self.ui.flash_table.item(
                                          row, EditMeasureParametersDialog.
                                          FlashColumn.SIZE).text()),
                                  start_value=utils.parse_input(
                                      self.ui.flash_table.item(
                                          row, EditMeasureParametersDialog.
                                          FlashColumn.START_VALUE).text()),
                                  end_value=utils.parse_input(
                                      self.ui.flash_table.item(
                                          row, EditMeasureParametersDialog.
                                          FlashColumn.END_VALUE).text())))

            table_valid = True
        except ValueError:
            table_valid = False

        if table_valid:
            self.measure_parameters = MeasureParameters()

            if self.ui.aci_radio.isChecked():
                self.measure_parameters.signal_type = clb.SignalType.ACI
            elif self.ui.acv_radio.isChecked():
                self.measure_parameters.signal_type = clb.SignalType.ACV
            elif self.ui.dci_radio.isChecked():
                self.measure_parameters.signal_type = clb.SignalType.DCI
            else:  # self.ui.dcv_radio.isChecked():
                self.measure_parameters.signal_type = clb.SignalType.DCV

            self.measure_parameters.flash_after_finish = self.ui.flash_after_finish_checkbox.isChecked(
            )
            self.measure_parameters.enable_correction = self.ui.enable_correction_checkbox.isChecked(
            )

            self.measure_parameters.flash_table = flash_table

            self.accept()
        else:
            QtWidgets.QMessageBox.critical(
                self, "Ошибка", "Таблица прошивки заполнена неверно",
                QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
Example #3
0
 def process_input(self, a_input: str):
     try:
         processed_value = utils.parse_input(a_input)
         processed_value = self.bound_input(processed_value)
     except ValueError:
         processed_value = self.bound_input(0)
     return self.value_to_user(processed_value)
 def normalize_edit_value(self, edit: QtWidgets.QLineEdit):
     try:
         value = utils.parse_input(edit.text(), a_precision=20)
         edit.setText(utils.float_to_string(value, a_precision=20))
     except ValueError:
         edit.setText("0")
     self.update_edit_color(edit)
Example #5
0
 def set_float_edit_param(self):
     edit = self.sender()
     object_field, type_ = self.get_parameter_name_type(edit)
     try:
         value = utils.parse_input(edit.text())
         edit.setText(utils.float_to_string(value))
         setattr(self.__variables_owner, object_field, type_(value))
     except ValueError:
         edit.setText("0")
         setattr(self.__variables_owner, object_field, type_(0.))
Example #6
0
 def get_list(self) -> List[float]:
     out_list = []
     try:
         for idx in range(self.ui.list_widget.count()):
             item = self.ui.list_widget.item(idx).text()
             if item not in out_list:
                 out_list.append(utils.parse_input(item))
         return out_list
     except ValueError:
         return list()
Example #7
0
 def sort_list(self):
     items = OrderedDict()
     for idx in range(self.ui.list_widget.count()):
         text = self.ui.list_widget.item(idx).text()
         value = utils.parse_input(text)
         items[value] = text
     self.ui.list_widget.clear()
     items = OrderedDict(sorted(items.items()))
     for value in items.values():
         self.ui.list_widget.addItem(QtWidgets.QListWidgetItem(value))
     return list(items.keys())
Example #8
0
 def write_variable(self, a_item: QtWidgets.QTableWidgetItem):
     try:
         if self.netvars.connected():
             variable_number = int(
                 self.ui.variables_table.item(a_item.row(),
                                              self.Column.NUMBER).text())
             try:
                 variable_value = utils.parse_input(a_item.text())
                 self.netvars.write_variable(variable_number,
                                             variable_value)
             except ValueError:
                 pass
     except Exception as err:
         logging.debug(utils.exception_handler(err))
    def setData(self, index: QModelIndex, value: str, role=Qt.EditRole):
        if not index.isValid(
        ) or role != Qt.EditRole or self.rowCount() <= index.row():
            return False

        try:
            value = utils.parse_input(
                value, a_precision=DeviceCoefficientsModel.EDIT_DATA_PRECISION)
            result = True
        except ValueError:
            result = False

        if index.column(
        ) == DeviceCoefficientsModel.Column.COEFFICIENT and value == 0:
            result = False

        if result:
            self.__values[index.row()][index.column()] = value
            self.dataChanged.emit(index, index)

        return result
    def setData(self, index: QModelIndex, value: str, role=Qt.EditRole):
        if not index.isValid(
        ) or role != Qt.EditRole or self.rowCount() <= index.row():
            return False

        result = True
        cell_data = self.__cells[index.row()][index.column()]

        if not value:
            cell_data.reset()
        else:
            try:
                float_value = utils.parse_input(value, a_precision=20)
                if not utils.are_float_equal(
                        float_value,
                        cell_data.get_value()) or not cell_data.has_value():
                    cell_data.set_value(float_value)
                else:
                    result = False
            except ValueError:
                result = False

        if result:
            if index.row(
            ) == MeasureDataModel.HEADER_ROW and self.__signal_type_is_ac:
                # Изменение частоты для переменного сигнала, нужно пересчитать коэффициент для всех авто ячеек
                frequency = self.get_frequency(index.column())
                for row in range(MeasureDataModel.HEADER_ROW + 1,
                                 self.rowCount()):
                    cell_data = self.__cells[row][index.column()]
                    cell_data.update_coefficient(
                        frequency, self.__shared_measure_parameters)

                self.dataChanged.emit(index, index)
            self.set_save_state(False)
            self.__reset_status()

        return result
    def accept_config(self):
        extra_parameters = []
        try:
            for row in range(self.ui.extra_variables_table.rowCount()):
                extra_parameters.append(
                    CellConfig.ExtraParameter(
                        name=self.ui.extra_variables_table.item(
                            row,
                            EditCellConfigDialog.ExtraParamsColumn.NAME).text(
                            ),
                        index=int(
                            self.ui.extra_variables_table.item(
                                row, EditCellConfigDialog.ExtraParamsColumn.
                                INDEX).text()),
                        bit_index=int(
                            self.ui.extra_variables_table.item(
                                row, EditCellConfigDialog.ExtraParamsColumn.
                                BIT_INDEX).text()),
                        type=self.ui.extra_variables_table.item(
                            row,
                            EditCellConfigDialog.ExtraParamsColumn.TYPE).text(
                            ),
                        work_value=utils.parse_input(
                            self.ui.extra_variables_table.item(
                                row, EditCellConfigDialog.ExtraParamsColumn.
                                WORK_VALUE).text()),
                        default_value=utils.parse_input(
                            self.ui.extra_variables_table.item(
                                row, EditCellConfigDialog.ExtraParamsColumn.
                                DEFAULT_VALUE).text())))
            data_valid = True
        except ValueError:
            data_valid = False

        coefficient = utils.parse_input(self.ui.coefficient_edit.text(),
                                        a_precision=20)
        if coefficient == 0:
            data_valid = False

        if data_valid:
            self.cell_config = CellConfig()

            self.cell_config.measure_delay = self.ui.measure_delay_spinbox.value(
            )
            self.cell_config.measure_time = self.ui.measure_time_spinbox.value(
            )
            self.cell_config.coefficient = coefficient

            self.cell_config.auto_calc_coefficient = self.ui.auto_coefficient_checkbox.isChecked(
            )

            self.cell_config.consider_output_value = self.ui.consider_output_value_checkbox.isChecked(
            )

            self.cell_config.meter_config_string = self.ui.meter_config_edit.text(
            )

            self.cell_config.coil, self.cell_config.divider, self.cell_config.meter = self.__get_scheme(
            )

            self.cell_config.extra_parameters = extra_parameters

            self.cell_config.additional_parameters = self.additional_parameters

            self.accept()
        else:
            QtWidgets.QMessageBox.critical(
                self, "Ошибка",
                "Таблица дополнительных параметров заполнена неверно,"
                "либо коэффициент равен нулю", QtWidgets.QMessageBox.Ok,
                QtWidgets.QMessageBox.Ok)