Пример #1
0
    def extract_params(self) -> List[Scale.Limit]:
        try:
            scales = []
            for row_idx in range(self.ui.limits_table.rowCount()):
                limit = utils.parse_input(
                    self.ui.limits_table.item(
                        row_idx, ScaleLimitsDialog.Column.LIMIT).text())
                device_class = self.ui.limits_table.cellWidget(
                    row_idx, ScaleLimitsDialog.Column.CLASS).value()
                signal_type = \
                    self.ui.limits_table.cellWidget(row_idx, ScaleLimitsDialog.Column.SIGNAL_TYPE).currentIndex()
                frequency = \
                    self.ui.limits_table.cellWidget(row_idx, ScaleLimitsDialog.Column.FREQUENCY).get_frequency_text()
                limit_id = int(
                    self.ui.limits_table.item(
                        row_idx, ScaleLimitsDialog.Column.ID).text())

                scales.append(
                    Scale.Limit(a_id=limit_id,
                                a_limit=limit,
                                a_device_class=device_class,
                                a_signal_type=clb.SignalType(signal_type),
                                a_frequency=frequency))
            return scales
        except Exception as err:
            utils.exception_handler(err)
Пример #2
0
    def current_case_changed(self):
        """
        Вызывается каждый раз, когда меняются параметры сигнала
        """
        try:
            if not self.calibrator.signal_enable:
                self.current_case = self.measure_manager.current_case()
                self.set_window_elements()
                self.update_case_params()

                # Чтобы обновились единицы измерения
                self.set_amplitude(self.calibrator.amplitude)
                self.set_frequency(self.calibrator.frequency)
                self.calibrator.signal_type = self.current_case.signal_type
                self.fill_fixed_step_combobox()

                self.stop_measure_timer.stop()
                self.close_wait_dialog()

            else:
                self.enable_signal(False)
                self.stop_measure_timer.start(1100)
                self.show_wait_dialog()

        except AssertionError as err:
            utils.exception_handler(err)
Пример #3
0
 def update_config(self):
     try:
         edit_template_params_dialog = EditMeasureParamsDialog(
             self.settings, self.measure_config, self.db_connection, self)
         edit_template_params_dialog.exec()
     except AssertionError as err:
         utils.exception_handler(err)
Пример #4
0
 def select_case(self, a_idx):
     try:
         self.cases_bar.setCurrentIndex(a_idx)
         self.measure_view.reset(self.cases[a_idx])
         self.current_case_changed.emit()
     except Exception as err:
         utils.exception_handler(err)
    def add_new_tab(self, a_template_id: int, a_scale: cfg.Scale = None):
        try:
            new_tab_index = self.ui.tabWidget.count() - 1

            if a_scale is None:
                a_scale = self.templates_db.new_scale(a_template_id, a_scale)
                a_scale.number = new_tab_index

            config_scale_button = QtWidgets.QPushButton("Пределы", self)
            config_scale_button.clicked.connect(self.edit_scale_limits)
            scale_list = EditedListOnlyNumbers(
                parent=self,
                a_init_items=(p for p in a_scale.points),
                a_min_value=-float_info.max,
                a_max_value=float_info.max,
                a_optional_widget=config_scale_button,
                a_list_header="Числовые отметки шкалы, деление")

            self.ui.tabWidget.insertTab(new_tab_index, scale_list,
                                        str(self.ui.tabWidget.count()))
            self.ui.tabWidget.setCurrentIndex(new_tab_index)

            self.scales_id[new_tab_index + 1] = a_scale.id

        except Exception as err:
            utils.exception_handler(err)
    def remove_tab(self, a_idx: int):
        try:
            if self.ui.tabWidget.count() > 2:
                res = QtWidgets.QMessageBox.question(
                    self, "Подтвердите действие",
                    "Вы действительно хотите удалить шкалу №{0}?".format(
                        a_idx + 1),
                    QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
                    QtWidgets.QMessageBox.No)
                if res == QtWidgets.QMessageBox.Yes:
                    if a_idx == self.ui.tabWidget.count(
                    ) - 2 and a_idx == self.ui.tabWidget.currentIndex():
                        # Если удаляемая вкладка активна, меняем активную на предыдущую
                        self.ui.tabWidget.setCurrentIndex(
                            self.ui.tabWidget.count() - 3)
                    self.ui.tabWidget.removeTab(a_idx)
                    self.templates_db.delete_scale(self.scales_id[a_idx + 1])

                    # Последнюю вкладку с плюсиком не переименовываем
                    for tab_idx in range(self.ui.tabWidget.count() - 1):
                        old_scale_number = int(
                            self.ui.tabWidget.tabText(tab_idx))
                        actual_scale_number = tab_idx + 1
                        actual_tab_name = str(actual_scale_number)
                        if self.ui.tabWidget.tabText(
                                tab_idx) != actual_tab_name:
                            scale_id = self.scales_id[old_scale_number]
                            del self.scales_id[old_scale_number]
                            self.scales_id[actual_scale_number] = scale_id

                            self.ui.tabWidget.setTabText(
                                tab_idx, actual_tab_name)
        except Exception as err:
            utils.exception_handler(err)
Пример #7
0
 def open_settings(self):
     try:
         settings_dialog = SettingsDialog(self.settings, self.db_connection,
                                          self)
         settings_dialog.exec()
     except Exception as err:
         utils.exception_handler(err)
Пример #8
0
 def template_mode_chosen(self):
     try:
         template_list_dialog = TemplateListWindow(self.settings, self)
         template_list_dialog.config_ready.connect(
             self.start_template_measure)
         template_list_dialog.exec()
     except Exception as err:
         utils.exception_handler(err)
Пример #9
0
 def open_source_mode_window(self):
     try:
         source_mode_dialog = SourceModeDialog(self.settings,
                                               self.calibrator, self)
         self.attach_calibrator_to_window(source_mode_dialog)
         source_mode_dialog.exec()
     except Exception as err:
         utils.exception_handler(err)
Пример #10
0
 def save_pressed(self):
     try:
         self.save()
         if self.marks_widget.save():
             if self.generate_protocol():
                 self.close()
         else:
             self.ui.marks_and_points_tabwidget.setCurrentIndex(0)
     except Exception as err:
         utils.exception_handler(err)
Пример #11
0
 def create_protocol(self):
     try:
         measure_id = self.get_selected_id()
         assert measure_id is not None, "measure id must not be None!"
         create_protocol_dialog = CreateProtocolDialog(
             self.settings, measure_id, self.control_db_connection, self)
         create_protocol_dialog.exec()
         self.update_table()
     except Exception as err:
         utils.exception_handler(err)
Пример #12
0
    def save_geometry(self, a_window_name: str, a_geometry: QtCore.QByteArray):
        try:
            self.add_ini_section(self.GEOMETRY_SECTION)

            self.settings[self.GEOMETRY_SECTION][
                a_window_name] = self.__to_base64(a_geometry)

            self.save()
        except Exception as err:
            utils.exception_handler(err)
Пример #13
0
 def choose_template(self):
     try:
         item = self.ui.templates_list.currentItem()
         if item is not None:
             variable_params_dialog = VariableTemplateFieldsDialog(self)
             params = variable_params_dialog.exec_and_get_params()
             if params is not None:
                 self.config_ready.emit(self.current_template, params)
                 self.reject()
     except Exception as err:
         utils.exception_handler(err)
Пример #14
0
    def delete_case(self):
        try:
            sender = self.sender()
            tab_idx = self.get_tab_idx(sender)
            self.remove_tab(tab_idx)

            if self.cases_bar.currentIndex() == tab_idx:
                # В этих случаях cases_bar.currentChanged не эмитится
                self.select_case(tab_idx)

        except AssertionError as err:
            utils.exception_handler(err)
Пример #15
0
    def start_fast_measure(self):
        try:
            measure_config = Measure.from_fast_params(self.fast_config)

            self.close_active_window()
            self.change_window(
                MeasureWindow(a_calibrator=self.calibrator,
                              a_measure_config=measure_config,
                              a_db_connection=self.db_connection,
                              a_settings=self.settings,
                              a_parent=self))
        except Exception as err:
            utils.exception_handler(err)
Пример #16
0
    def signal_type_changed(self, a_idx):
        try:
            sender_table_row = self.ui.limits_table.currentRow()
            row_limit_item = self.ui.limits_table.item(
                sender_table_row, ScaleLimitsDialog.Column.LIMIT)

            value_f = utils.parse_input(row_limit_item.text())
            signal_type = clb.SignalType(a_idx)
            units = clb.signal_type_to_units[signal_type]

            value_str = utils.value_to_user_with_units(units)(value_f)
            row_limit_item.setText(value_str)
        except Exception as err:
            utils.exception_handler(err)
Пример #17
0
    def start_template_measure(self, a_template_params: TemplateParams,
                               a_variable_params: VariableTemplateParams):
        try:
            measure_config = Measure.from_template(a_template_params,
                                                   a_variable_params)

            self.close_active_window()
            self.change_window(
                MeasureWindow(a_calibrator=self.calibrator,
                              a_measure_config=measure_config,
                              a_db_connection=self.db_connection,
                              a_settings=self.settings,
                              a_parent=self))
        except Exception as err:
            utils.exception_handler(err)
Пример #18
0
    def save_point(self):
        if self.clb_state != clb.State.WAITING_SIGNAL:
            try:
                if self.measure_manager.view().is_point_measured(
                        self.current_point.amplitude,
                        self.current_point.frequency,
                        self.current_point.approach_side):

                    side_text = "СНИЗУ" if self.current_point.approach_side == PointData.ApproachSide.DOWN \
                        else "СВЕРХУ"

                    point_text = "{0}".format(
                        self.value_to_user(self.current_point.amplitude))
                    if clb.is_ac_signal[self.current_case.signal_type]:
                        point_text += " : {0} Гц".format(
                            utils.float_to_string(
                                self.current_point.frequency))

                    ask_dlg = QMessageBox(self)
                    ask_dlg.setWindowTitle("Выберите действие")
                    ask_dlg.setText(
                        "Значение {0} уже измерено для точки {1}.\n"
                        "Выберите действие для точки {3}({2})".format(
                            side_text, point_text, side_text, point_text))
                    average_btn = ask_dlg.addButton("Усреднить",
                                                    QMessageBox.YesRole)
                    overwrite_btn = ask_dlg.addButton("Перезаписать",
                                                      QMessageBox.YesRole)
                    ask_dlg.addButton("Отменить", QMessageBox.NoRole)
                    ask_dlg.exec()

                    if ask_dlg.clickedButton() == overwrite_btn:
                        self.measure_manager.view().append(self.current_point)
                    elif ask_dlg.clickedButton() == average_btn:
                        self.measure_manager.view().append(self.current_point,
                                                           a_average=True)
                else:
                    if self.clb_state == clb.State.READY:
                        self.measure_manager.view().append(self.current_point)
                    else:
                        self.measure_manager.view().append(
                            PointData(
                                a_point=self.current_point.amplitude,
                                a_frequency=self.current_point.frequency))
            except AssertionError as err:
                utils.exception_handler(err)
        else:
            self.clb_not_ready_warning()
Пример #19
0
 def open_tstlan(self):
     try:
         tstlan_dialog = TstlanDialog(self.netvars, self.calibrator,
                                      self.settings, self)
         tstlan_dialog.exec()
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #20
0
 def update_graphs(self):
     try:
         plot_data = self.graph_data[self.current_test_number][
             self.current_graph_name]
         self.current_graph.setData(plot_data[0], plot_data[1])
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #21
0
 def open_settings(self):
     try:
         settings_dialog = SettingsDialog(self.settings, self.netvars_db,
                                          self)
         settings_dialog.exec()
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #22
0
    def show_test_errors(self, a_group: str, a_name: str):
        try:
            errors_list = self.test_conductor.get_test_errors(a_group, a_name)
            has_errors = True if any(error != ""
                                     for error in errors_list) else False
            if has_errors:
                try:
                    errors_dialog = self.errors_dialogs[(a_group, a_name)]
                    errors_dialog.activateWindow()
                except KeyError:
                    nl = "\n"
                    errors_list = [
                        f'<p style=" color:#ff0000;">Тест №{num + 1}</p>{error.replace(nl, "<br>")}'
                        for num, error in enumerate(errors_list)
                    ]

                    errors_dialog = DialogWithText(errors_list, self.settings,
                                                   self)
                    errors_dialog.setWindowTitle(
                        f'Ошибки теста "{a_group}: {a_name}"')
                    self.errors_dialogs[(a_group, a_name)] = errors_dialog
                    errors_dialog.exec()
                    del self.errors_dialogs[(a_group, a_name)]
            else:
                logging.warning("Выбранный тест не содержит ошибок")
        except Exception as err:
            logging.debug(utils.exception_handler(err))
Пример #23
0
    def show_start_window(self):
        try:
            self.close_active_window()

            self.active_window = StartWindow(self.db_connection, self.db_name,
                                             self.settings, self)
            self.setCentralWidget(self.active_window)
            self.active_window.source_mode_chosen.connect(
                self.open_source_mode_window)
            self.active_window.no_template_mode_chosen.connect(
                self.open_config_no_template_mode)
            self.active_window.template_mode_chosen.connect(
                self.template_mode_chosen)
            self.setWindowTitle(self.active_window.windowTitle())
        except Exception as err:
            utils.exception_handler(err)
Пример #24
0
 def set_test_status(self, a_group_name, a_test_name: str,
                     a_status: tests_base.ClbTest.Status,
                     a_success_count: int):
     try:
         self.tests_widget.set_test_status(a_group_name, a_test_name,
                                           a_status, a_success_count)
     except AssertionError as err:
         logging.debug(utils.exception_handler(err))
Пример #25
0
 def show_graphs(self):
     try:
         if self.graphs_dialog is None:
             self.graphs_dialog = TstlanGraphDialog(self.graphs_data,
                                                    self.settings, self)
             self.graphs_dialog.exec()
             self.graphs_dialog = None
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #26
0
 def autocheck_button_clicked(self):
     try:
         if self.test_conductor.started():
             self.test_conductor.stop()
             self.stop_autocheck()
         else:
             self.start_autocheck()
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #27
0
    def graph_checkbox_clicked(self, a_state):
        try:
            checkbox = self.sender()
            pos = checkbox.mapTo(self.ui.variables_table.viewport(),
                                 checkbox.pos())
            cell_index = self.ui.variables_table.indexAt(pos)

            self.update_graph_variables(cell_index.row(), a_state)
        except Exception as err:
            logging.debug(utils.exception_handler(err))
    def edit_scale_limits(self):
        try:
            current_scale_number = self.ui.tabWidget.currentIndex() + 1
            scale_id = self.scales_id[current_scale_number]
            limits = self.templates_db.get_limits(scale_id)

            scale_limits_dialog = ScaleLimitsDialog(limits, self)

            new_limits, deleted_ids = scale_limits_dialog.exec_and_get_limits()
            if new_limits is not None:
                # Вносим изменения в базу, только если пользователь подтвердил ввод
                self.templates_db.delete_limits(deleted_ids)
                for limit in new_limits:
                    if limit.id != 0:
                        self.templates_db.update_limit(limit)
                    else:
                        self.templates_db.new_limit(scale_id, limit)
        except Exception as err:
            utils.exception_handler(err)
Пример #29
0
 def redraw_graph(self):
     try:
         plot_data = self.graph_data[self.current_test_number][
             self.current_graph_name]
         self.graph_widget.clear()
         self.current_graph = self.graph_widget.plot(plot_data[0],
                                                     plot_data[1],
                                                     pen=self.pen)
     except Exception as err:
         logging.debug(utils.exception_handler(err))
Пример #30
0
 def execute_query(self, sql_query):
     """
     This method is used to execute the sql query and return results.
     :param sql_query: type str
     :return: rows and header
     """
     if self.conn:
         self._logger.info("executing sql query")
         cur = self.conn.cursor()
         try:
             cur.execute(sql_query)
             rows = cur.fetchall()
             self._logger.info("executing done")
             return rows, [desc[0] for desc in cur.description]
         except Exception as e:
             info = "Unable to execute the query!"
             exception_handler(info, e)
     else:
         self._logger.error("PGDB not connected!")