Exemple #1
0
    def initUI(self):
        self.text_panel_code = TextEditor(objectName="text3", tooltip='Ugly')

        self.check_box_line = CheckBox(label="Minidom(0)\nBS4(1)")
        # self.check_box_line.cb.stateChanged.connect(self.hideTable)

        button_generat = SimpleBtn(label="¬жух",
                                   click_func=self.generat,
                                   width=200)

        self.text_panel_view = TextEditor(objectName="text2", tooltip='Beauty')

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.text_panel_code)
        splitter.addWidget(self.text_panel_view)

        self.main_layout.addWidget(splitter, 0, 0, 5, 2)
        self.main_layout.addWidget(self.check_box_line, 1, 2, 1, 1)
        self.main_layout.addWidget(button_generat, 2, 2, 1, 1)
Exemple #2
0
    def initUI(self):

        self.text_panel_code = TextEditor(objectName="text3", tooltip='Код для всавки в <b>проект</b>')

        button_except = SimpleBtn(label="Добавить", click_func=self.view_code)
        button_generat = SimpleBtn(label="Сгенерировать", click_func=self.generat)
        button_clean = SimpleBtn(label="Очистить", click_func=self.clean)
        button_reverce = SimpleBtn(label="Обратно", click_func=self.reverce_code)

        self.plc_line = LineText(text='ICore_2', placeholder='plc_name')
        self.plc_resource = LineText(text='Resource1', placeholder='plc_resource')

        self.text_panel = TextEditor(objectName="text1", tooltip='Генерация промежуточного значения', height=200,
                                     text="""['<<[COM999:1:60210] mb_master_hr_real_in_v > канал 1>>',
                                     '{GP0021_SHOL7_QF24_EOFF.Значение}']""")

        self.text_panel_view = TextEditor(objectName="text2", tooltip='Промежуточное значение')

        self.status = QLabel('')
        self.set_status(status="База не открыта", color='#780d04')

        self.ignore_setting = CheckBox(label='Игнорировать')

        self.bd_window = SimpleDBPath(mainwin=self)
        self.bd_window.my_signal.connect(self.BD_is_open)

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.text_panel_code)
        splitter.addWidget(self.text_panel_view)

        splitter_v = QSplitter(Qt.Vertical)
        splitter_v.addWidget(splitter)
        splitter_v.addWidget(self.text_panel)

        self.main_layout.addWidget(splitter_v, 0, 0, 27, 20)

        self.main_layout.addWidget(self.plc_line, 5, 21, 1, 2)
        self.main_layout.addWidget(self.plc_resource, 6, 21, 1, 2)
        self.main_layout.addWidget(self.ignore_setting, 4, 21, 1, 2)

        self.main_layout.addWidget(button_clean, 15, 22, 1, 1)
        self.main_layout.addWidget(button_except, 15, 21, 1, 1)
        self.main_layout.addWidget(self.bd_window, 0, 21, 1, 2)
        self.main_layout.addWidget(button_generat, 16, 21, 1, 2)
        self.main_layout.addWidget(button_reverce, 17, 21, 1, 2)
        self.main_layout.addWidget(self.status, 25, 21, 1, 2)
Exemple #3
0
class Tab(LibTab):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.text_panel_code = TextEditor(objectName="text3", tooltip='Ugly')

        self.check_box_line = CheckBox(label="Minidom(0)\nBS4(1)")
        # self.check_box_line.cb.stateChanged.connect(self.hideTable)

        button_generat = SimpleBtn(label="¬жух",
                                   click_func=self.generat,
                                   width=200)

        self.text_panel_view = TextEditor(objectName="text2", tooltip='Beauty')

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.text_panel_code)
        splitter.addWidget(self.text_panel_view)

        self.main_layout.addWidget(splitter, 0, 0, 5, 2)
        self.main_layout.addWidget(self.check_box_line, 1, 2, 1, 1)
        self.main_layout.addWidget(button_generat, 2, 2, 1, 1)

    def generat(self):
        text = self.text_panel_code.toPlainText().replace('', '')
        try:
            if self.check_box_line.isChecked():
                bs = BeautifulSoup(text, 'xml')
                xml_pretty_str = bs.prettify()
            else:
                xml = minidom.parseString(text)
                xml_pretty_str = xml.toprettyxml()
            xml_pretty_str = xml_pretty_str.replace(
                '<?xml version="1.0" ?>',
                '<?xml version="1.0" encoding="UTF-8"?>')
            self.text_panel_view.setText(xml_pretty_str)
        except Exception as e:
            QMessageBox().warning(self, "ќшибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)
Exemple #4
0
    def initUI(self):

        self.table = TableSimple(name=["MARKA"])
        # self.table.setSelectionBehavior(QAbstractItemView.SelectItems)  # Выделяет всю строку

        self.table_for_test = TableSimple(name=["SOMETHING"])
        # self.table_for_test.setSelectionBehavior(QAbstractItemView.SelectItems)  # Выделяет всю строку
        # self.table_for_test.setMaximumWidth(500)

        button_open = SimpleBtn(label="Открыть исх. файл",
                                click_func=self.open_xml)

        self.count_element = LineLabel(
            label="Кол-во в ряду/строке", number='20')
        self.dx = LineLabel(label="dx", number='100')
        self.dy = LineLabel(label="dy ", number='100')

        button_generat = SimpleBtn(label="Сгенерировать",
                                   click_func=self.gerait_xml)
        button_open_teml = SimpleBtn(label="Открыть шаблон",
                                     click_func=self.get_tempalte)
        button_save_teml = SimpleBtn(label="Сохранить шаблон",
                                     click_func=self.save_template)

        self.xml_template = SimpleLabel(text="None", WordWrap=True)

        self.table.setMaximumWidth(1700)
        self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)

        self.text_panel = TextEditor(
            objectName="text1",
            tooltip='Правила вставки',
            text=
            """[f"2/PLC_GP_21_1BR/1/{str(item1).rjust(2,'0')}/DI_DIG_3A" for item1 in range(1, 3)]"""
        )

        self.offset = CheckBox(label='Смещение по оси x',
                               value=True)

        button_generat_tab2 = SimpleBtn(label="get_table2",
                                        click_func=self.generate_table2)

        self.xml_template = SimpleLabel(text="None", WordWrap=True)

        splitter_v = QSplitter(Qt.Vertical)
        splitter_v.addWidget(self.table_for_test)
        splitter_v.addWidget(self.text_panel)

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.table)
        splitter.addWidget(splitter_v)

        self.main_layout.addWidget(splitter, 0, 0, 27, 2)

        self.main_layout.addWidget(button_generat, 23, 2, 1, 2)
        self.main_layout.addWidget(button_generat_tab2, 5, 2, 1, 2)
        self.main_layout.addWidget(self.xml_template, 1, 2, 1, 2)

        self.main_layout.addWidget(button_open, 14, 2, 1, 2)
        self.main_layout.addWidget(button_open_teml, 16, 2, 1, 2)
        self.main_layout.addWidget(button_save_teml, 15, 2, 1, 2)

        self.main_layout.addWidget(self.count_element, 9, 2, 1, 2)
        self.main_layout.addWidget(self.dx, 11, 2, 1, 2)
        self.main_layout.addWidget(self.dy, 12, 2, 1, 2)
        self.main_layout.addWidget(self.offset, 8, 2, 1, 2)
Exemple #5
0
class Tab(LibTab):
    def __init__(self):
        super().__init__()
        self.new_templates = Template()
        self.rows = []
        self.initData()
        self.initUI()

    def initData(self):
        self.rows = []
        self.main_title = None

    def initUI(self):

        self.table = TableSimple(name=["MARKA"])
        # self.table.setSelectionBehavior(QAbstractItemView.SelectItems)  # Выделяет всю строку

        self.table_for_test = TableSimple(name=["SOMETHING"])
        # self.table_for_test.setSelectionBehavior(QAbstractItemView.SelectItems)  # Выделяет всю строку
        # self.table_for_test.setMaximumWidth(500)

        button_open = SimpleBtn(label="Открыть исх. файл",
                                click_func=self.open_xml)

        self.count_element = LineLabel(
            label="Кол-во в ряду/строке", number='20')
        self.dx = LineLabel(label="dx", number='100')
        self.dy = LineLabel(label="dy ", number='100')

        button_generat = SimpleBtn(label="Сгенерировать",
                                   click_func=self.gerait_xml)
        button_open_teml = SimpleBtn(label="Открыть шаблон",
                                     click_func=self.get_tempalte)
        button_save_teml = SimpleBtn(label="Сохранить шаблон",
                                     click_func=self.save_template)

        self.xml_template = SimpleLabel(text="None", WordWrap=True)

        self.table.setMaximumWidth(1700)
        self.table.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)

        self.text_panel = TextEditor(
            objectName="text1",
            tooltip='Правила вставки',
            text=
            """[f"2/PLC_GP_21_1BR/1/{str(item1).rjust(2,'0')}/DI_DIG_3A" for item1 in range(1, 3)]"""
        )

        self.offset = CheckBox(label='Смещение по оси x',
                               value=True)

        button_generat_tab2 = SimpleBtn(label="get_table2",
                                        click_func=self.generate_table2)

        self.xml_template = SimpleLabel(text="None", WordWrap=True)

        splitter_v = QSplitter(Qt.Vertical)
        splitter_v.addWidget(self.table_for_test)
        splitter_v.addWidget(self.text_panel)

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.table)
        splitter.addWidget(splitter_v)

        self.main_layout.addWidget(splitter, 0, 0, 27, 2)

        self.main_layout.addWidget(button_generat, 23, 2, 1, 2)
        self.main_layout.addWidget(button_generat_tab2, 5, 2, 1, 2)
        self.main_layout.addWidget(self.xml_template, 1, 2, 1, 2)

        self.main_layout.addWidget(button_open, 14, 2, 1, 2)
        self.main_layout.addWidget(button_open_teml, 16, 2, 1, 2)
        self.main_layout.addWidget(button_save_teml, 15, 2, 1, 2)

        self.main_layout.addWidget(self.count_element, 9, 2, 1, 2)
        self.main_layout.addWidget(self.dx, 11, 2, 1, 2)
        self.main_layout.addWidget(self.dy, 12, 2, 1, 2)
        self.main_layout.addWidget(self.offset, 8, 2, 1, 2)

    def get_tempalte(self):
        options = QFileDialog.Options()
        # options |= QFileDialog.DontUseNativeDialog
        path, _ = QFileDialog.getOpenFileName(self,
                                              'Открыть xml',
                                              "",
                                              "Xml (*.xml)",
                                              options=options)

        if path == '':
            return

        try:
            self.new_templates.get_tempalte(path)
            self.table_view_set()
            self.watch_path(path)
        except Exception as e:
            self.error_message()
            QMessageBox().warning(self, "Ошибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)

    def save_template(self):
        options = QFileDialog.Options()
        # options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getSaveFileName(self,
                                                  "Сохранить xml",
                                                  "",
                                                  "xml (*.xml)",
                                                  options=options)

        if fileName == '':
            return

        if fileName.find('.xml') == -1:
            fileName += '.xml'

        try:
            self.new_templates.save_to_file(fileName)
        except Exception as e:
            self.error_message()
            QMessageBox().warning(self, "Ошибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)

    def table_clean(self):
        self.table.setRowCount(0)

    def tab_view(self):
        # exec(f'connection = {self.text_panel.toPlainText()}')
        # connection = eval('[dict(MARKA=f"GP0011_SPPV_{item1}_P", NAME=f"{item2}",OBJSIGN=f"P",KLASSNAME="[ВСЕ]\Водоснабжение\ГП0011 СППВ",EVKLASSNAME="[Все технологические]\Водоснабжение\ГП0011 СППВ", PLCNAME="ICore_2") for item1, item2 in [["TO_K1", "Давление на входе насоса K1"],["FROM_K1", "Рабочее давление K1"],["TO_K8", "Давление на входе насоса K8"],["FROM_K8", "Рабочее давление K8"],["TO_K10", "Давление на входе насоса K10"],["FROM_K10", "Рабочее давление K10"],["TO_K14", "Давление на входе насоса K14"],["FROM_K14","Рабочее давление K14"]]]')
        # connection = eval(self.text_panel.toPlainText())
        pass

    def open_xml(self):
        options = QFileDialog.Options()
        # options |= QFileDialog.DontUseNativeDialog
        path, _ = QFileDialog.getOpenFileName(self,
                                              'Открыть xml',
                                              "",
                                              "Xml (*.xml)",
                                              options=options)

        if path == '':
            return

        try:
            with open(path, "r", encoding='UTF-8') as f:
                self.new_templates.open_xml(path)
                self.table_view_set()

            self.watch_path(path)
            self.dx.line_edit.setText(
                str(roundUpToMultiple(self.new_templates.maximum_x, 50)))
            self.dy.line_edit.setText(
                str(roundUpToMultiple(self.new_templates.maximum_y, 50)))

        except Exception as e:
            self.error_message()
            QMessageBox().warning(self, "Ошибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)

    def table_view_set(self):
        self.table.setColumnCount(
            len(self.new_templates.atr_dict.keys()) +
            1)  # Устанавливаем три колонки
        labels_list = ['№']
        labels_list.extend(list(self.new_templates.atr_dict.keys()))
        self.table.setHorizontalHeaderLabels(labels_list)
        self.table.setRowCount(1)  # и одну строку в таблице
        header = self.table.horizontalHeader()
        self.table.setItem(0, 0, QTableWidgetItem('1'))
        for in_col, key in enumerate(list(self.new_templates.atr_dict.keys())):
            self.table.setItem(
                0, in_col + 1,
                QTableWidgetItem(str(self.new_templates.atr_dict[key])))
            header.setSectionResizeMode(in_col + 1,
                                        QHeaderView.Stretch)  # Stretch)
        self.table.setWordWrap(True)

    def gerait_xml(self):
        try:
            bloks_templ = Environment(loader=BaseLoader).from_string(
                self.new_templates.bloks_data)
            links_templ = Environment(loader=BaseLoader).from_string(
                self.new_templates.links_data)
            env = Environment(loader=FileSystemLoader('.'))
            template = env.get_template('templates/tab11/main.html')

            options = QFileDialog.Options()
            # options |= QFileDialog.DontUseNativeDialog
            fileName, _ = QFileDialog.getSaveFileName(self,
                                                      "Сохранить xml",
                                                      "",
                                                      "xml (*.xml)",
                                                      options=options)

            if fileName == '':
                return

            if fileName.find('.xml') == -1:
                fileName += '.xml'

            with open(fileName, "w", encoding='utf8') as f:
                count_element_max = int(self.count_element.line_edit.text())
                x0 = 0
                y0 = 0
                x = x0
                y = y0
                dx = int(self.dx.line_edit.text())
                dy = int(self.dy.line_edit.text())

                list_atrib = ['X', 'Y', 'index']
                list_atrib.extend(list(self.new_templates.atr_dict.keys()))
                dicr_atr = collections.namedtuple('dicr_atr', list_atrib)
                links = []
                count = self.table.rowCount()
                index_of_element = 0
                bloks = []
                index_row = 1
                for index in range(count):

                    at = [
                        self.table.item(index, col).text()
                        for col in range(1, self.table.columnCount())
                    ]
                    my_dict = dicr_atr(x, y, index_of_element, *at)
                    links.append(str(links_templ.render(dict=my_dict)))
                    bloks.append(str(bloks_templ.render(dict=my_dict)))
                    if self.offset.isChecked():
                        x += dx
                        if index_row >= count_element_max:
                            x = x0
                            y += dy
                            index_row = 0
                    else:
                        y += dy
                        if index_row >= count_element_max:
                            y = y0
                            x += dx
                            index_row = 0
                    index_row += 1
                    index_of_element += self.new_templates.delta + 1
                f.write(template.render(bloks=bloks, links=links))
        except Exception as e:
            self.text_panel.setText('Что-то пошло не так')
            QMessageBox().warning(self, "Ошибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)

    @staticmethod
    def check_type(data):
        return '' if isinstance(data, type(None)) else data.text()

    def generate_table2(self):
        self.table_for_test.setRowCount(0)
        try:
            connection = eval(self.text_panel.toPlainText())
            for conn in connection:
                index = self.table_for_test.rowCount()
                self.table_for_test.setRowCount(
                    index + 1)  # и одну строку в таблице
                self.table_for_test.setRowHeight(index, 50)
                self.table_for_test.setItem(index, 0, QTableWidgetItem(conn))
            self.table_for_test.resizeRowsToContents()
        except Exception as e:
            self.table_for_test.setRowCount(1)
            self.table_for_test.setItem(0, 0, "Что-то не так")
            QMessageBox().warning(self, "Ошибка", str(e), QMessageBox.Ok,
                                  QMessageBox.Ok)

    def watch_path(self, path):
        now = datetime.now()
        self.xml_template.setText(path + '\n' + str(now.hour) + ':' +
                                  str(now.minute) + ':' + str(now.second))

    def error_message(self):
        self.xml_template.setText("Ошибка! :(")