예제 #1
0
class MenubarUI(object):
    def __init__(self, main_window: QMainWindow):
        """
        菜单栏
        外观模式
        :param main_window:
        """
        self.main_window = main_window

        self.menubar = QMenuBar(main_window)

        self.menu_list = []
        self.option_menu = OptionMenu(self.menubar, self.main_window)
        self.view_menu = ViewMenu(self.menubar)
        self.help_menu = HelpMenu(self.menubar, self.main_window)

    def setup_ui(self) -> None:
        font = QFont()
        font.setPointSize(10)
        self.menubar.setFont(font)

        # self.menubar.setGeometry(QRect(0, 0, 800, 25))
        self.menubar.setFixedHeight(30)
        self.menubar.setObjectName("menubar")
        self.main_window.setMenuBar(self.menubar)

        self.load_ui()
        self.show_ui()

        if settings.LOAD_EFFECT_ON:
            load_animation.load_animation(self.menubar)

    # noinspection PyArgumentList
    def retranslate_ui(self) -> None:
        self.menubar.setWindowTitle(_translate("MenubarUI", "菜单栏"))

    def load_ui(self) -> None:
        """
        加载模块
        :return:
        """
        self.menu_list.append(self.option_menu)
        self.menu_list.append(self.view_menu)
        self.menu_list.append(self.help_menu)

    def show_ui(self) -> None:
        """
        显示数据
        :return:
        """
        for view in self.menu_list:
            view.setup_ui()
            view.retranslate_ui()
예제 #2
0
class E(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        self.resize(1920, 900)  # set initial size of the window
        self.center()  # center the window
        # self.setStyleSheet("background-color: white;")

        self.setStyleSheet("background-color: rgb(240, 240, 240)")
        self.menubar = QMenuBar()
        self.menubar.setFont((QFont("Ariel", 10)))
        self.menubar.setStyleSheet("""
            QMenuBar {
                background: #0b794b
            }
            QMenuBar::item {
                color: rgb(255,255,255);
                font-size: 36px
            }
            QMenuBar::item:selected { 
                color: rgb(0, 0, 0);
                background-color: #519f7f
            }
            QMenu {
                background: #519f7f
            }

            """)
        #actionFile = self.menubar.addMenu("File")
        #actionFile.addAction("New")
        #actionFile.addAction("Open")
        #actionFile.addAction("Save")

        #self.menubar.addAction("Switch Profile")

        openFile = QAction("Open Externally", self)
        self.menubar.addAction(openFile)
        openFile.triggered.connect(self.onClickOpenNotepad)

        #action1 = QtWidgets.QWidgetAction(self)
        #self.label1 = QtWidgets.QLabel("Action1")
        #action1.setDefaultWidget(self.label1)
        #action1.setText('Action1')
        #self.menubar.addAction(action1)

        # menubar.setStyleSheet("QMenuBar::item {background: rgb(170,200,200)}")

        self.setWindowTitle(
            'Profile Editing Application- Currently Editing: ' +
            profileNewest)  # set the title of the window

        self.creatingTable(
        )  # create the table that will store the property data
        l1 = QLabel()

        l1.setText(
            "This is an application to edit the properties of Bioschemas profiles. <br><br><font color='green'>Green</font> properties/types are "
            "proposed by Bioschemas, or indicate proposed changes by Bioschemas to Schema.org <br><font color='red'>Red</font> properties/"
            "types exist in the core of Schema.org <br><font color='blue'>Blue</font> properties/types exist in the pending area of Schema.org"
            "<br>Black properties/types are reused from external vocabularies/ontologies"
        )
        l1.setFont((QFont("Ariel", 10)))
        # l1.setStyleSheet("background-color: rgb(220, 220, 220)")
        createNewProperty = QPushButton("Create New Property")
        createNewProperty.setStyleSheet("font: bold;")
        createNewProperty.clicked.connect(self.clickNewPropertyButton)
        createNewProperty.setMaximumWidth(300)

        showAllExamples = QPushButton("Show All Examples")
        showAllExamples.setStyleSheet("font: bold;")
        showAllExamples.clicked.connect(self.clickShowAllExamples)
        showAllExamples.setMaximumWidth(300)

        self.searchbar = QLineEdit()
        self.searchbar.setPlaceholderText("Search Properties")
        self.searchbar.setMaximumWidth(300)
        self.searchbar.textChanged.connect(self.update_display)
        self.searchbar.setStyleSheet(
            "background-color: white; border: 1px solid black")
        self.searchbar.setToolTip(
            "This will let you search through the loaded properties.")

        self.layout = QVBoxLayout(
        )  # this sets the layout to be aligned vertically
        l2 = QVBoxLayout()
        l2.setContentsMargins(10, 0, 0, 0)
        self.layout.addWidget(self.menubar)
        l2.addWidget(l1)
        l2.addWidget(createNewProperty)
        l2.addWidget(showAllExamples)
        l2.addWidget(self.searchbar)
        self.layout.addLayout(l2)
        self.layout.addWidget(
            self.tableWidget)  # add the widgets to the layout
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.setLayout(self.layout)

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def creatingTable(self):
        self.tableWidget = QTableWidget()

        #print("hiawdawde")
        data = importYaml(
        )  # get the initial data from the file and set it to a variable

        b = data['mapping'][0]
        rowNames = []
        for elim in b:
            rowNames.append(elim)
        # print(rowNames)
        h = len(
            data['mapping']) + 4  # this is used to set the height and width of
        # the table to the amount of entries in the file, adjusted for the marginality
        w = len(rowNames)

        self.tableWidget.setRowCount(h)
        self.tableWidget.setColumnCount(w)
        self.tableWidget.setHorizontalHeaderLabels(rowNames)
        for c in range(w):
            self.tableWidget.setColumnWidth(c, 150)
            if c == 0 or c == 1 or c == 8:
                self.tableWidget.setColumnWidth(c, 300)
            if c == 2:
                self.tableWidget.setColumnWidth(c, 500)

        liRec.append([
            "Marginality: Recommended", "", "", "", "", "", "", "", "", "", ""
        ])
        liMin.append(
            ["Marginality: Minimum", "", "", "", "", "", "", "", "", "", ""])
        liOpt.append(
            ["Marginality: Optional", "", "", "", "", "", "", "", "", "", ""])
        liUns.append([
            "Marginality: Unspecified", "", "", "", "", "", "", "", "", "", ""
        ])

        for rows in range(len(data['mapping'])):
            res = findYamlValue(data, rows, rowNames)
            sorter(res)

        liTot = liMin + liRec + liOpt + liUns

        if len(liRec) == 1:
            for c in range(len(liTot)):
                if liTot[c][0] == "Marginality: Recommended":
                    self.tableWidget.hideRow(c)

        font = QFont()
        font.setBold(True)
        font.setPointSize(10)

        fon = "Schema: \n"
        # fon.setFont(font)
        for c in range(len(liTot)):
            exampleList.append(liTot[c][9])
            if liTot[c][0] != "Marginality: Recommended":
                if liTot[c][0] != "Marginality: Minimum":
                    if liTot[c][0] != "Marginality: Optional":
                        if liTot[c][0] != "Marginality: Unspecified":
                            liTot[c][2] = "<b>Schema:</b> <br>" + liTot[c][2]
                            if liTot[c][5] != "":
                                liTot[c][2] = liTot[c][
                                    2] + "<br><br><b>Bioschemas:</b><br>" + liTot[
                                        c][5]

        URL = 'https://schema.org/docs/full.html'
        page = requests.get(URL)
        final = []
        soup = BeautifulSoup(page.content, 'html.parser')
        results = soup.find(id='mainContent')
        q = results.find_all('a')
        for elim in q:
            stringSchema = str(elim)
            frontCheck = stringSchema.split('href="/')
            for g in frontCheck:
                i = g.split('"')[0]
                if i != "<td class=":
                    final.append(i)

        final = list(dict.fromkeys(final))

        for c in range(len(liTot)):
            x = liTot[c][1]
            t = ""
            for s in x:
                if s == ",":
                    t = t + "\n"
                elif s != "[":
                    if s != "]":
                        if s != "'":
                            if s != " ":
                                t = t + s
            # liTot[c][1] = t  # i know this is really ugly, but the input is a string that looks like a list, so
            # had to cut off all the extra bits
            expectedList = t.split('\n')
            colouredList = ""
            for elLength in range(len(expectedList)):
                for schemaList in range(len(final)):
                    if expectedList[elLength] == final[schemaList]:
                        expectedList[
                            elLength] = "<a href=\"https://schema.org/" + expectedList[
                                elLength] + "\" style=\"color:red\">" + expectedList[
                                    elLength] + "<br></a>"

                if liTot[c][0] != "Marginality: Recommended":
                    if liTot[c][0] != "Marginality: Minimum":
                        if liTot[c][0] != "Marginality: Optional":
                            if liTot[c][0] != "Marginality: Unspecified":
                                if "color:red" not in expectedList[elLength]:
                                    expectedList[
                                        elLength] = "<a href=\"https://bioschemas.org/" + expectedList[
                                            elLength] + "\" style=\"color:green\">" + expectedList[
                                                elLength] + "<br></a>"

                colouredList = colouredList + expectedList[elLength]
            liTot[c][1] = colouredList

        for rows in range(len(liTot)):
            for x in range(w):
                self.tableWidget.setItem(rows, x,
                                         QTableWidgetItem(liTot[rows][x]))

        profileName = data['name']
        for rows in range(len(liTot)):
            for x in range(w - 1):
                textEdit = QTextBrowser()
                textEdit.setFont(QFont("Ariel", 9))
                textEdit.setStyleSheet(
                    "background-color: white; border: white")
                textEdit.setText(str(liTot[rows][x]))
                textEdit.setOpenExternalLinks(True)

                if str(liTot[rows][0]) != "Marginality: Minimum" and str(liTot[rows][0]) != "Marginality: Recommended" \
                        and str(liTot[rows][0]) != "Marginality: Optional" and str(
                    liTot[rows][0]) != "Marginality: Unspecified":
                    if x == 0:
                        textEdit.setStyleSheet(
                            "background-color: rgb(180, 180, 180); border: 2px solid white;"
                        )
                        if str(liTot[rows][3]) == "bioschemas":
                            textEdit.setText(
                                "<a href=\"https://bioschemas.org/profiles/" +
                                str(profileName) +
                                "\" style=\"color:green\"><b>" +
                                str(liTot[rows][x]) + "</b></a>")
                        if str(liTot[rows][3]) == "":
                            textEdit.setText("<a href=\"https://schema.org/" +
                                             str(liTot[rows][x]) +
                                             "\" style=\"color:red\"><b>" +
                                             str(liTot[rows][x]) + "</b></a>")

                else:
                    textEdit.setText("<b>" + str(liTot[rows][x]) + "</b>")

                self.tableWidget.setCellWidget(rows, x, textEdit)

                if str(liTot[rows][0]) == "Marginality: Minimum" or str(liTot[rows][0]) == "Marginality: Recommended" \
                        or str(liTot[rows][0]) == "Marginality: Optional" or str(
                    liTot[rows][0]) == "Marginality: Unspecified":
                    textEdit.setStyleSheet(
                        "background-color: rgb(180, 180, 180); border: none")

        for i in range(h):
            self.tableWidget.item(i, 0).setFont(font)
        self.tableWidget.setShowGrid(False)
        self.tableWidget.setFocusPolicy(QtCore.Qt.NoFocus)

        self.tableWidget.setWordWrap(True)
        self.tableWidget.setFont(QFont("Ariel", 9))
        self.tableWidget.insertColumn(w)
        for col in range(h):
            self.tableWidget.setItem(col, w, QTableWidgetItem(
                ""))  # all columns have to have some value to be coloured
            self.tableWidget.item(col,
                                  w).setBackground(QtGui.QColor(180, 180, 180))

        rowNames.append("Edit Property")
        self.tableWidget.setHorizontalHeaderLabels(rowNames)
        for x in range(len(liTot)):
            if liTot[x][0] != "Marginality: Recommended":
                if liTot[x][0] != "Marginality: Minimum":
                    if liTot[x][0] != "Marginality: Optional":
                        if liTot[x][0] != "Marginality: Unspecified":
                            eachButton = self.tableButton()
                            eachButton.setGeometry(200, 150, 100, 40)
                            eachButton.setIcon(QIcon('edit_button.png'))
                            eachButton.setIconSize(QSize(60, 60))
                            eachButton.setStyleSheet(
                                'QPushButton {background-color: #FFFFFF; border:  none}'
                            )

                            self.tableWidget.setCellWidget(x, w, eachButton)
                            buttonList.append(eachButton)
                            eachButton.clicked.connect(self.click)

        for x in range(len(liTot)):
            if liTot[x][0] != "Marginality: Recommended":
                if liTot[x][0] != "Marginality: Minimum":
                    if liTot[x][0] != "Marginality: Optional":
                        if liTot[x][0] != "Marginality: Unspecified":
                            eachExampleButton = self.tableExampleButton()
                            # eachExampleButton.setGeometry(200, 150, 100, 40)
                            eachExampleButton.setIcon(
                                QIcon('example_icon.png'))
                            eachExampleButton.setIconSize(QSize(60, 60))
                            eachExampleButton.setStyleSheet(
                                'QPushButton {background-color: #FFFFFF; border:  none}'
                            )

                            self.tableWidget.setCellWidget(
                                x, w - 1, eachExampleButton)
                            buttonList2.append(eachExampleButton)
                            eachExampleButton.clicked.connect(
                                self.clickExample)
        self.show()

        for c in range(h):
            self.tableWidget.setRowHeight(c, 250)
            self.tableWidget.item(c,
                                  0).setBackground(QtGui.QColor(200, 200, 200))

            if liTot[c][3] == "":
                self.tableWidget.item(c,
                                      0).setForeground(QtGui.QColor(100, 0, 0))
            elif liTot[c][3] == "bioschemas":
                self.tableWidget.item(c,
                                      0).setForeground(QtGui.QColor(0, 100, 0))
            else:
                self.tableWidget.item(c,
                                      0).setForeground(QtGui.QColor(0, 0, 100))

            if liTot[c][0] == "Marginality: Recommended" or liTot[c][
                    0] == "Marginality: Minimum" or liTot[c][
                        0] == "Marginality: Optional" or liTot[c][
                            0] == "Marginality: Unspecified":
                self.tableWidget.setRowHeight(c, 50)
                self.tableWidget.item(c,
                                      0).setForeground(QtGui.QColor(0, 0, 0))
                for s in range(w):
                    self.tableWidget.item(c, s).setBackground(
                        QtGui.QColor(180, 180, 180))

        self.tableWidget.hideColumn(3)
        self.tableWidget.hideColumn(4)
        self.tableWidget.hideColumn(5)
        if w == 10:
            self.tableWidget.hideColumn(6)
        else:
            self.tableWidget.hideColumn(
                7)  # to deal with when there are 10/11 columns

        # self.tableWidget.setStyleSheet('QTableWidget::item {border-bottom: 1px solid blue;}')
        self.tableWidget.setVerticalScrollMode(
            QAbstractItemView.ScrollPerPixel)
        self.tableWidget.verticalScrollBar().setSingleStep(20)
        self.tableWidget.setStyleSheet(
            "::section{Background-color:rgb(160,160,160);border-radius:1px;}")
        self.tableWidget.verticalScrollBar().setStyleSheet(
            'background:rgb(160,160,160)')
        self.tableWidget.horizontalScrollBar().setStyleSheet(
            'background:rgb(160,160,160)')
        self.tableWidget.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        self.tableWidget.horizontalHeader().setStretchLastSection(True)
        self.tableWidget.horizontalHeader().setFont(font)

        self.tableWidget.horizontalHeaderItem(0).setToolTip(
            "This column is for listing the property name.")
        self.tableWidget.horizontalHeaderItem(1).setToolTip(
            "This column is for listing expected type of the property.")
        self.tableWidget.horizontalHeaderItem(2).setToolTip(
            "This column is for the description, as well as\nthe bioschemas description of the property."
        )
        self.tableWidget.horizontalHeaderItem(7).setToolTip(
            "This column is for listing the cardinality of the property.")
        self.tableWidget.horizontalHeaderItem(8).setToolTip(
            "This column is for listing the controlled vocabulary.")
        self.tableWidget.horizontalHeaderItem(9).setToolTip(
            "This column is for listing the examples of the property.")
        self.tableWidget.horizontalHeaderItem(10).setToolTip(
            "This column is for the edit buttons.")

        self.tableWidget.verticalHeader().hide()

        for c in range(h):
            if len(liMin) == 1:
                if self.tableWidget.item(c,
                                         0).text() == "Marginality: Minimum":
                    self.tableWidget.hideRow(c)
            if len(liRec) == 1:
                if self.tableWidget.item(
                        c, 0).text() == "Marginality: Recommended":
                    self.tableWidget.hideRow(c)
            if len(liOpt) == 1:
                if self.tableWidget.item(c,
                                         0).text() == "Marginality: Optional":
                    self.tableWidget.hideRow(c)
            if len(liUns) == 1:
                if self.tableWidget.item(
                        c, 0).text() == "Marginality: Unspecified":
                    self.tableWidget.hideRow(c)

            # if str(self.tableWidget.item(c, 0).background().color().getRgb()) == "(180, 180, 180, 255)":
            # print("yancy")

    def tableButton(self):
        btn = QPushButton("")
        return btn

    def tableExampleButton(self):
        btn = QPushButton("")
        return btn

    def click(self):
        btn = self.tableWidget.focusWidget()
        index = self.tableWidget.indexAt(btn.pos())
        global btnIndex
        btnIndex = index.row()
        self.d = Second()
        self.d.show()

    def clickExample(self):
        btn2 = self.tableWidget.focusWidget()
        index2 = self.tableWidget.indexAt(btn2.pos())
        global btnIndex2
        btnIndex2 = index2.row()
        self.sw = ExampleButtons()
        self.sw.show()

    def clickNewPropertyButton(self):
        global btnIndex
        btnIndex = 0
        self.d = Second()
        self.d.show()

    def clickShowAllExamples(self):
        global btnIndex2
        btnIndex2 = 0
        self.full = ExampleButtons()
        self.full.show()

    def onClickOpenNotepad(self):
        global profileNewest
        p = profileNewest
        #print(p)
        subprocess.call([
            'notepad.exe',
            'BioschemasGitClone/bioschemas.github.io/_profiles/' + p
        ])

    def update_display(self, text):
        data = importYaml(
        )  # get the initial data from the file and set it to a variable
        b = data['mapping'][0]
        h = len(data['mapping']) + 4
        x = self.tableWidget.item(1, 0).text()
        for row in range(h):
            if text.lower() in self.tableWidget.item(row, 0).text().lower() or self.tableWidget.item(row, 0).text() == \
                    "Marginality: Recommended" or self.tableWidget.item(row, 0).text() == "Marginality: Minimum" \
                    or self.tableWidget.item(row, 0).text() == "Marginality: Optional" or \
                    self.tableWidget.item(row, 0).text() == "Marginality: Unspecified":

                self.tableWidget.showRow(row)
            else:
                self.tableWidget.hideRow(row)

    def passed(self):
        return btnIndex

    def closeEvent(self, event):
        global startingHighest
        #print(startingHighest)
        c = startingHighest

        global profileNewest
        f = profileNewest
        location = f.split("/", 1)
        profile = location[0]
        p = os.listdir('BioschemasGitClone/bioschemas.github.io/_profiles/' +
                       profile)
        #print(p)

        h = 0
        newest = ""
        allVersionList = []
        for elim in p:
            m = elim.split("-", 1)
            x = str(m[0])
            x = x[2:]
            x = int(x)
            allVersionList.append(x)
            if x > h:
                h = x
                newest = elim

        lenDirectory = h
        #print(lenDirectory)
        x = natsorted(
            p
        )  # little function i found that will sort the list in a natural way, similar to windows file explorer
        #print(x)
        t = sorted(allVersionList)
        #print(t)
        #print("000")
        #print("oahwdh8o" + str(startingHighest))
        index = t.index(int(startingHighest))
        #print(index)
        count = 0
        for i in range(len(t)):
            #print("c=" + str(count))
            if i > index:
                #print("i= " + str(i))
                #print("nlent" + str(len(t)))
                if i != len(t) - 1:
                    #print(("llllll " + str(len(allVersionList))))
                    os.remove(
                        'BioschemasGitClone/bioschemas.github.io/_profiles/' +
                        profile + '/' + x[i])
            count = count + 1

        currentVersion = startingHighest + 1

        today = date.today()
        dateToday = today.strftime("%Y_%m_%d")

        p = os.listdir('BioschemasGitClone/bioschemas.github.io/_profiles/' +
                       profile)  # get the new length of the directory
        fileToRename = '/0.' + str(
            currentVersion) + '-DRAFT-' + dateToday + '.html'
        # print("\n" + p[-1])
        if t[-1] != startingHighest:
            os.rename(
                'BioschemasGitClone/bioschemas.github.io/_profiles/' +
                profile + '/' + x[-1],
                'BioschemasGitClone/bioschemas.github.io/_profiles/' +
                profile + '/' + fileToRename)
예제 #3
0
class UI(QMainWindow):
    def __init__(self):
        super(UI, self).__init__()
        # -- 基础设置 -- #
        self.cp = QDesktopWidget().availableGeometry().center()
        qr = self.frameGeometry()
        qr.moveCenter(self.cp)
        self.move(qr.topLeft())
        self.resize(340, 150)
        self.setMinimumSize(340, 150)
        self.setMaximumSize(340, 150)
        self.setWindowTitle('pdf转长图助手')
        self.setWindowIcon(QIcon('tools.png'))
        # --字体设置--#
        # 字体8号
        self.font_8 = QFont()
        self.font_8.setPointSize(8)
        # 字体9号
        self.font_9 = QFont()
        self.font_9.setPointSize(9)

        # --菜单控件设置 -- #
        self.menubar = QMenuBar()  # 这里暂时不设置父类
        self.menubar.setFont(self.font_8)
        menu = self.menubar.addMenu('&菜单')
        self.menu_about = self.menubar.addMenu('&关于')
        self.action4 = QAction('版本号', self)
        self.action4.setFont(self.font_8)
        self.menu_about.addAction(self.action4)
        self.action4.triggered.connect(self.about_dialog)  # 菜单栏4触发器
        self.action1 = QAction('使用说明', self)
        self.action1.setFont(self.font_8)
        self.action2 = QAction('更新记录', self)
        self.action2.setFont(self.font_8)
        self.action3 = QAction('我要反馈', self)
        self.action3.setFont(self.font_8)
        menu.addAction(self.action1)
        menu.addAction(self.action2)
        menu.addAction(self.action3)

        # -- 菜单控制连接器
        self.action1.triggered.connect(self.notice_dialog)  # 菜单栏1触发器
        self.action2.triggered.connect(self.update_dialog)  # 菜单栏2触发器
        self.action3.triggered.connect(self.feedback_dialog)  # 菜单栏3触发器

        # -- 窗口1
        self.frame1 = None
        self.line_edit1_1 = None  # 窗口1的文件夹路径
        self.pdf_path = None  # 窗口1的pdf路径
        self.push_button1_1 = QPushButton()  # 按钮1_1,选择文件
        self.push_button1_2 = QPushButton()  # 按钮1_2,pdf转png
        self.push_button1_3 = QPushButton()  # 按钮1_3,我要退出

        # --窗口2
        self.frame2 = None
        self.line_edit2_1 = None  # 输入框
        self.pdf_dir1 = None  # pdf转成图片后的文件夹
        self.push_button2_1 = QPushButton()  # 按钮2_1:自定义路径
        self.push_button2_2 = QPushButton()  # 按钮2_2:一键长图
        self.push_button2_3 = QPushButton()  # 按钮2_3:自定义拼接

        # --窗口3
        self.frame3 = None
        self.pdf_dir2 = None
        self.line_edit3_1 = None  # 输入框
        self.combo_box3_1 = None  # 多选框3_1
        self.combo_box3_2 = None  # 多选框3_2
        self.line_edit3_2 = None  # 输入框百分比
        self.push_button3_1 = QPushButton()  # 自定义路径
        self.push_button3_2 = QPushButton()  # 一键压缩
        self.push_button3_3 = QPushButton()  # 退出软件

        # --- dialog会话 --
        self.dialog_line_edit1 = None  # 会话输入框1:拼接数量
        self.dialog_line_edit2 = None  # 会话输入框2:拼接列数
        self.dialog_line_edit3 = None  # 会话输入框3:拼接行数
        self.dialog_line_edit4 = None  # 会话输入框4:拼接间隙
        self.dialog_push_button1 = None  # 会话按钮1:开始单列拼接
        self.dialog_push_button2 = None  # 会话按钮1:开始矩阵拼接
        self.dialog1 = None  # 单列拼接
        self.dialog2 = None  # 矩阵拼接

        # --运行主界面--#
        self.init_ui()

    def init_ui(self):
        self.show_frame1()
        self.show()

    def show_frame1(self):
        self.frame1 = QWidget(self)
        super(QWidget, self.frame1).__init__()
        # --按钮标签1:格式转换,用来代替按钮1
        button_label1 = QLabel(self.frame1)
        button_label1.setGeometry(90, 0, 80, 24)
        button_label1.setFont(self.font_8)
        button_label1.setText('格式转换')
        button_label1.setAlignment(Qt.AlignCenter)
        # 转换按键
        # --按钮2:图片拼接
        push_button2 = QPushButton(self.frame1)
        push_button2.setGeometry(170, 0, 80, 24)
        push_button2.setFont(self.font_8)
        push_button2.setText('图片拼接')
        push_button2.clicked.connect(self.show_frame2)  # 连接件显示窗口2
        # --按钮3:图片压缩
        push_button3 = QPushButton(self.frame1)
        push_button3.setGeometry(250, 0, 80, 24)
        push_button3.setFont(self.font_8)
        push_button3.setText('图片压缩')
        push_button3.clicked.connect(self.show_frame3)  # 连接件显示窗口3

        # --标签1:pdf路径
        label1_1 = QLabel(self.frame1)
        label1_1.setText('pdf路径')
        label1_1.setFont(self.font_8)
        label1_1.setAlignment(Qt.AlignCenter)
        label1_1.setGeometry(15, 40, 69, 20)

        # --路径1:pdf路径
        self.line_edit1_1 = QLineEdit(self.frame1)
        self.line_edit1_1.setFont(self.font_8)
        self.line_edit1_1.setGeometry(90, 40, 220, 26)
        # 加入上次的路径保留
        pdf_path = self.read_data_dict('pdf_path')
        if pdf_path is not None:
            self.line_edit1_1.setText(pdf_path)

        # -- 按钮1_1:选择pdf文件
        self.push_button1_1 = QPushButton(self.frame1)
        self.push_button1_1.setGeometry(10, 95, 93, 29)
        self.push_button1_1.setText('选择文件')
        self.push_button1_1.setFont(self.font_9)
        # -- 按钮1_2:pdf转png
        self.push_button1_2 = QPushButton(self.frame1)
        self.push_button1_2.setGeometry(115, 95, 93, 29)
        self.push_button1_2.setText('pdf转png')
        self.push_button1_2.setFont(self.font_9)
        # -- 按钮1_3:我要退出
        self.push_button1_3 = QPushButton(self.frame1)
        self.push_button1_3.setGeometry(220, 95, 93, 29)
        self.push_button1_3.setText('退出软件')
        self.push_button1_3.setFont(self.font_9)

        # 移动其它控件
        self.menubar.setParent(self.frame1)  # 设置菜单栏依赖于窗口1
        self.setCentralWidget(self.frame1)  # 设置主窗口的当前窗口为窗口1
        self.frame1.setVisible(True)

    def show_frame2(self):
        # 重新定义构件
        self.frame2 = QWidget(self)
        super(QWidget, self.frame2).__init__()
        # --按钮1:格式转换
        push_button1 = QPushButton(self.frame2)
        push_button1.setGeometry(90, 0, 80, 24)
        push_button1.setFont(self.font_8)
        push_button1.setText('格式转换')
        push_button1.clicked.connect(self.show_frame1)

        # --按钮标签2:格式转换,用来代替按钮2
        button_label2 = QLabel(self.frame2)  # 暂时不设置父标签
        button_label2.setGeometry(170, 0, 80, 24)
        button_label2.setFont(self.font_8)
        button_label2.setText('图片拼接')
        button_label2.setAlignment(Qt.AlignCenter)
        # --按钮3:图片压缩
        push_button3 = QPushButton(self.frame2)
        push_button3.setGeometry(250, 0, 80, 24)
        push_button3.setFont(self.font_8)
        push_button3.setText('图片压缩')
        push_button3.clicked.connect(self.show_frame3)  # 连接件显示窗口3

        # -- 标签2_1:文件夹路径
        label2_1 = QLabel(self.frame2)
        label2_1.setGeometry(15, 40, 80, 20)
        label2_1.setText('文件夹路径')
        label2_1.setFont(self.font_8)

        # -- 输入框2_1:文件夹路径
        self.line_edit2_1 = QLineEdit(self.frame2)
        self.line_edit2_1.setGeometry(90, 40, 220, 26)
        self.line_edit2_1.setFont(self.font_8)

        # 加入默认路径
        pdf_path = self.read_data_dict('pdf_path')
        if pdf_path is not None:
            dir1 = path.split(pdf_path)[0]
            self.pdf_dir1 = dir1 + '/导出图片'
            self.line_edit2_1.setText(self.pdf_dir1)

        # -- 按钮2_1:自定义路径
        self.push_button2_1 = QPushButton(self.frame2)
        self.push_button2_1.setGeometry(10, 95, 93, 29)
        self.push_button2_1.setText('自定义路径')
        self.push_button2_1.setFont(self.font_9)
        # -- 按钮2_2:一键长图
        self.push_button2_2 = QPushButton(self.frame2)
        self.push_button2_2.setGeometry(115, 95, 93, 29)
        self.push_button2_2.setText('一键长图')
        self.push_button2_2.setFont(self.font_9)
        # -- 按钮2_3:自定义拼接
        self.push_button2_3 = QPushButton(self.frame2)
        self.push_button2_3.setGeometry(220, 95, 93, 29)
        self.push_button2_3.setText('自定义拼接')
        self.push_button2_3.setFont(self.font_9)
        self.push_button2_3.clicked.connect(self.show_dialog)
        # -- 移动其它控件
        self.menubar.setParent(self.frame2)  # 设置菜单栏依赖于窗口2
        self.setCentralWidget(self.frame2)
        self.frame2.setVisible(True)

    def show_frame3(self):
        self.frame3 = QWidget(self)
        super(QWidget, self.frame3).__init__()
        # --按钮1:格式转换
        push_button1 = QPushButton(self.frame3)
        push_button1.setGeometry(90, 0, 80, 24)
        push_button1.setFont(self.font_8)
        push_button1.setText('格式转换')
        push_button1.clicked.connect(self.show_frame1)

        # --按钮2:图片拼接
        push_button2 = QPushButton(self.frame3)
        push_button2.setGeometry(170, 0, 80, 24)
        push_button2.setFont(self.font_8)
        push_button2.setText('图片拼接')
        push_button2.clicked.connect(self.show_frame2)  # 连接件显示窗口2
        # -- 设置主窗口
        self.setCentralWidget(self.frame3)

        # -- 标签3:图片压缩
        button_label3 = QLabel(self.frame3)
        button_label3.setGeometry(250, 0, 80, 24)
        button_label3.setFont(self.font_8)
        button_label3.setText('图片压缩')
        button_label3.setAlignment(Qt.AlignCenter)
        # -- 标签3_1:文件夹路径
        label3_1 = QLabel(self.frame3)
        label3_1.setGeometry(15, 40, 80, 20)
        label3_1.setText('文件夹路径')
        label3_1.setFont(self.font_8)
        # -- 输入框3_1:文件夹路径
        self.line_edit3_1 = QLineEdit(self.frame3)
        self.line_edit3_1.setFont(self.font_8)
        self.line_edit3_1.setGeometry(90, 40, 220, 26)
        # 加入默认路径
        pdf_path = self.read_data_dict('pdf_path')
        if pdf_path is not None:
            dir1 = path.split(pdf_path)[0]
            self.pdf_dir2 = dir1 + '/单列长图'
            self.line_edit3_1.setText(self.pdf_dir2)
        # -- 标签3_2:宽度
        label3_2 = QLabel(self.frame3)
        label3_2.setGeometry(10, 80, 35, 20)
        label3_2.setText('宽度')
        label3_2.setFont(self.font_8)
        # -- 多选框3_1
        self.combo_box3_1 = QComboBox(self.frame3)
        self.combo_box3_1.setGeometry(45, 80, 60, 25)
        self.combo_box3_1.addItems(['普通', '720p', '1080p'])
        self.combo_box3_1.setFont(self.font_8)
        # -- 多选框3_2
        self.combo_box3_2 = QComboBox(self.frame3)
        self.combo_box3_2.setGeometry(155, 80, 50, 25)
        self.combo_box3_2.addItems(['jpg', 'png'])
        self.combo_box3_2.setFont(self.font_8)
        # -- 标签3_3
        label3_3 = QLabel(self.frame3)
        label3_3.setGeometry(120, 80, 40, 20)
        label3_3.setText('格式')
        label3_3.setFont(self.font_8)
        # -- 标签3_4
        label3_4 = QLabel(self.frame3)
        label3_4.setGeometry(220, 80, 51, 20)
        label3_4.setText('压缩比')
        label3_4.setFont(self.font_8)
        # -- 输入框3_2:压缩百分比
        self.line_edit3_2 = QLineEdit(self.frame3)
        self.line_edit3_2.setGeometry(265, 80, 25, 25)
        self.line_edit3_2.setFont(self.font_8)
        # -- 标签3_5
        label3_4 = QLabel(self.frame3)
        label3_4.setGeometry(295, 80, 14, 20)
        label3_4.setText('%')
        label3_4.setFont(self.font_8)
        # -- 按键3_1:自定义路径
        self.push_button3_1 = QPushButton(self.frame3)
        self.push_button3_1.setGeometry(10, 115, 93, 29)
        self.push_button3_1.setText('自定义路径')
        self.push_button3_1.setFont(self.font_9)
        # -- 按键3_2:一键压缩
        self.push_button3_2 = QPushButton(self.frame3)
        self.push_button3_2.setGeometry(115, 115, 93, 29)
        self.push_button3_2.setText('一键压缩')
        self.push_button3_2.setFont(self.font_9)
        # -- 按键3_3:退出软件
        self.push_button3_3 = QPushButton(self.frame3)
        self.push_button3_3.setGeometry(220, 115, 93, 29)
        self.push_button3_3.setText('我要退出')
        self.push_button3_3.setFont(self.font_9)
        # -- 设置其它依赖转移过来
        self.menubar.setParent(self.frame3)  # 设置菜单栏依赖于窗口3
        self.frame3.setVisible(True)

    def show_dialog(self):
        self.show_dialog1()

    def show_dialog1(self):
        if self.dialog2 is not None:
            self.dialog2.close()
        self.dialog1 = QDialog(self)
        self.dialog1.resize(340, 150)
        self.dialog1.setMinimumSize(340, 150)
        self.dialog1.setMaximumSize(340, 150)
        self.dialog1.setWindowIcon(QIcon('tools.png'))
        self.dialog1.setWindowTitle('自定义拼接')
        self.dialog1.setFont(self.font_8)

        # -- 设置标签1---
        label1 = QLabel(self.dialog1)
        label1.setGeometry(40, 10, 70, 29)
        label1.setText('单列拼接')
        label1.setAlignment(Qt.AlignCenter)
        # -- 设置按键2 ---
        push_button2 = QPushButton(self.dialog1)
        push_button2.setGeometry(40, 70, 70, 29)
        push_button2.setText('矩阵拼接')
        push_button2.clicked.connect(self.show_dialog2)

        # -- 标签2:拼接数量
        label2 = QLabel(self.dialog1)
        label2.setText('拼接数量')
        label2.setGeometry(150, 20, 51, 20)

        # -- 输入框:单列拼接数量
        self.dialog_line_edit1 = QLineEdit(self.dialog1)
        self.dialog_line_edit1.setGeometry(210, 20, 30, 20)
        self.dialog_push_button1 = QPushButton(self.dialog1)
        self.dialog_push_button1.setGeometry(150, 60, 93, 25)
        self.dialog_push_button1.setText('开始单列拼接')

    def show_dialog2(self):
        if self.dialog1 is not None:
            self.dialog1.close()  # 关闭会话1
        self.dialog2 = QDialog(self)
        self.dialog2.resize(340, 150)
        self.dialog2.setFont(self.font_8)
        self.dialog2.setMinimumSize(340, 150)
        self.dialog2.setMaximumSize(340, 150)
        self.dialog2.setWindowIcon(QIcon('tools.png'))
        self.dialog2.setWindowTitle('矩阵拼接')
        # -- 设置按键1---
        push_button1 = QPushButton(self.dialog2)
        push_button1.setGeometry(40, 10, 70, 29)
        push_button1.setText('单列拼接')
        push_button1.clicked.connect(self.show_dialog1)

        # -- 设置标签2---
        label1 = QLabel(self.dialog2)
        label1.setGeometry(40, 70, 70, 29)
        label1.setText('矩阵拼接')
        label1.setAlignment(Qt.AlignCenter)

        # -- 标签2:拼接列数
        label2 = QLabel(self.dialog2)
        label2.setText('拼接行数')
        label2.setGeometry(160, 20, 51, 20)
        # -- 标签3:拼接行数
        label3 = QLabel(self.dialog2)
        label3.setText('拼接列数')
        label3.setGeometry(160, 45, 51, 20)
        # -- 标签4:拼接行数
        label4 = QLabel(self.dialog2)
        label4.setText('拼接间隙')
        label4.setGeometry(160, 70, 51, 20)

        # -- 标签5:行数
        label4 = QLabel(self.dialog2)
        label4.setText('行')
        label4.setGeometry(260, 20, 41, 20)

        # -- 标签6:列数
        label4 = QLabel(self.dialog2)
        label4.setText('列')
        label4.setGeometry(260, 50, 41, 20)

        # -- 标签7:px像素
        label4 = QLabel(self.dialog2)
        label4.setText('px')
        label4.setGeometry(260, 70, 41, 20)

        # -- 输入框:拼接列数
        self.dialog_line_edit2 = QLineEdit(self.dialog2)
        self.dialog_line_edit2.setGeometry(220, 20, 30, 20)
        # -- 输入框:拼接行数
        self.dialog_line_edit3 = QLineEdit(self.dialog2)
        self.dialog_line_edit3.setGeometry(220, 45, 30, 20)
        # -- 输入框:拼接间隙
        self.dialog_line_edit4 = QLineEdit(self.dialog2)
        self.dialog_line_edit4.setGeometry(220, 70, 30, 20)

        self.dialog_push_button2 = QPushButton(self.dialog2)
        self.dialog_push_button2.setGeometry(160, 100, 93, 25)
        self.dialog_push_button2.setText('开始矩阵拼接')

    def notice_dialog(self):
        dialog = QDialog(self)
        dialog.resize(500, 450)
        dialog.setMinimumSize(340, 150)
        text = """\
<b>使用说明</b>:
主要功能有格式转换、图片拼接,图片压缩三项<br>
<b>格式转换</b>:目前只支持pdf转png<br>
<b>图片拼接</b>:<br>
1.支持自定义拼接路径。<br>
2.默认路径是你转成png图片后的路径。<br>
3.可以设置为一键拼接成一张长图。<br>
4.自定义拼接还可以按单列拼成长图,或者按矩阵进行拼接。<br>
5.单列拼接指的是按多张图拼接成一张图,比如15张图,<br>
  可以按5张图拼成一张长图,这样就获得了3张长图。<br>
6.矩阵拼接类似微信的九宫格,比如3行三列为一张长图,<br>
  中间可以设置10像素的间隙,然后可以获得多张这样的长图。<br>
7.矩阵拼接兼容单列拼接,即列为1,间隙为0时即为矩阵拼接。<br>
<b>图片压缩</b>:<br>
1.关于宽度<br>
  普通模式即自动压缩成1M以内,<br>
  720p和1080p则自动压缩图片为这个宽度<br>
2.关于格式<br>
  即压缩后图片的格式是jpg还是png<br>
3.关于压缩比<br>
  即压缩成jpg格式时,图片的质量百分比。
        """
        dialog.setWindowTitle('使用说明')
        label = QLabel(text, dialog)
        label.setFont(self.font_9)
        dialog.show()

    def update_dialog(self):
        """
        更新记录
        """
        dialog = QDialog(self)
        dialog.resize(500, 450)
        dialog.setMinimumSize(340, 150)
        text = """\
<b>V1.1版更新记录:</b><br>
1.增加窗口抽屉功能,将图片转换、图片拼接、图片压缩功能拆分。<br>
2.增加更多自定义功能,可以自定义图片文件夹来源,<br>
还可以自定义拼接方式了。<br>
3.优化了压缩图片算法的一个小bug,增加了压缩图片的最终格式自定义,<br>
可以选择压缩为jpg或者png。<br>
4.自定义拼接中,单列拼接与矩阵拼接多了一个翻转的过度动画。<br>
5.加入操作历史记录保留,自动保留上次的操作的方式<br>
注意,只会保留你的最后一次转图片、拼接图片、压缩图片的记录,<br>
选择文件的记录不在此列<br>
6.导出路径更改为与原pdf路径同级<br>
7.导出图片时自动删除上次导出的图片<br>
7.其他更新请阅读使用说明<br>
<br>
<b>V1.0版更新记录:</b><br>
1.使用PyQt5重构了界面<br>
2.增加了进度条,减少等待时间<br>
3.选择pdf文件时,默认上次的路径<br>
4.增加了二次确认操作<br>
5.使用多线程,提高了软件速度<br>
6.美化了GUI,变得好看了<br>
        """

        dialog.setWindowTitle('更新记录')
        label = QLabel(text, dialog)
        label.setFont(self.font_9)
        dialog.show()

    def feedback_dialog(self):
        """
        我要反馈
        """
        dialog = QDialog(self)
        dialog.resize(500, 50)
        dialog.setMinimumSize(340, 150)
        text = """\
qq群:<b>974759263</b><br>
        """

        dialog.setWindowTitle('我要反馈')
        label = QLabel(text, dialog)
        label.setFont(self.font_9)
        dialog.show()

    def about_dialog(self):
        dialog = QDialog(self)
        dialog.resize(500, 50)
        dialog.setMinimumSize(340, 150)
        text = """\
        版本号:<b>V1.1</b><br>
        编译日期:2020年6月3日<br>
                """
        dialog.setWindowTitle('关于')
        label = QLabel(text, dialog)
        label.setFont(self.font_9)
        dialog.show()

    # 公用读取字典
    @staticmethod
    def read_data_dict(key, data_path='./data.json'):
        """
        根据索引读取data.json的内容
        :param key: 索引
        :param data_path: json所在路径
        :return: data:读取到的值
        """
        with open(data_path, 'rt', encoding='utf-8') as f1:
            data_dict1 = json.load(f1)
        data = data_dict1.get(key, None)  # 没有内容则为None
        return data

    # 公用写入字典
    @staticmethod
    def write_data_dict(key, value2, data_path='./data.json'):
        """
        根据索引读取data.json的内容
        :param key: 写入键
        :return: value2:写入值
        :param data_path: json所在路径
        """
        f1 = open(data_path, 'rt', encoding='utf-8')
        data_dict1 = json.load(f1)
        f1.close()
        with open(data_path, 'wt', encoding='utf-8') as f2:
            data_dict1[key] = value2
            json.dump(data_dict1, f2)
예제 #4
0
class Ui_MainWindow(object):
    def text_inputChanged(self):
        self.timer_wait_to_refresh.start(1500)

    def refresh_output_when_timeout(self):
        self.timer_wait_to_refresh.stop()
        a_input = self.text_input.toPlainText()
        print('\ninputed data\n' + a_input)
        cmd = 'wbxml2xml'
        try:
            ishex = int(a_input[:5], 16)
            finput = open(dirScript + '/input_file', 'wb')
            a_input = "".join(a_input.split())
            a = [a_input[i:i + 2] for i in range(0, len(a_input), 2)]
            for aa in a:
                finput.write(binascii.unhexlify(aa))
            finput.close()
        except Exception as e:
            finput = open(dirScript + '/input_file', 'w')
            finput.writelines(a_input)
            finput.close()
            cmd = 'xml2wbxml'
        fullcmd = 'export PATH=/usr/local/bin:$PATH;' + cmd + ' -o ' + dirScript + '/output_file ' + dirScript + '/input_file'
        output = subprocess.getstatusoutput(fullcmd)
        self.label_parse_result.setText(cmd) if output[0] == 0 else self.label_parse_result.setText(cmd + " failed")
        if output[0] == 0:
            if cmd == "xml2wbxml":
                try:
                    with open(dirScript + '/output_file', "rb") as binary_file:
                        # Read the whole file at once
                        data = binary_file.read()
                        chs = ""
                        for ch in data:
                            chs += "{0:02x}".format(ch)
                        print('\nconverted wbxml\n' + chs)
                        self.text_output.setText(chs)
                except Exception as e:
                    print(str(e))
                    self.text_output.setText('Exception:\n' + str(e))
            else:
                try:
                    with open(dirScript + '/output_file', 'r') as xml_file:
                        data = xml_file.read()
                        print('\nconverted xml\n' + data)
                        self.text_output.setPlainText(data)
                except Exception as e:
                    print(str(e))
                    self.text_output.setText('Exception:\n' + str(e))
        else:
            self.text_output.setText(output[1])

    def setupUi(self, main_window):
        main_window.setObjectName("main_window")
        main_window.resize(1024, 600)
        # self.centralwidget = QtWidgets.QWidget(main_window)
        # self.centralwidget.setObjectName("centralwidget")
        # main_window.setCentralWidget(self.centralwidget)
        font = QFont('Roboto')
        font.setPointSize(16)

        fontmono = QFont('SF Mono')

        self.menubar = QMenuBar(main_window)
        if platform.uname().system == 'Darwin':
            self.menubar.setNativeMenuBar(True)
        self.menubar.setFont(font)
        self.menubar.setObjectName("menubar")
        main_window.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(main_window)
        self.statusbar.setObjectName("statusbar")
        main_window.setStatusBar(self.statusbar)

        self.subtitle = QHBoxLayout()
        self.label_input = QLabel()
        self.label_input.setFont(font)
        self.label_input.setAlignment(Qt.AlignCenter)
        self.label_input.setText("copy paste XML/WBXML here")

        self.label_parse_result = QLabel()
        self.label_parse_result.setFont(font)
        self.label_parse_result.setAlignment(Qt.AlignCenter)
        self.label_parse_result.setText("converted output")

        self.subtitle.addWidget(self.label_input)
        self.subtitle.addWidget(self.label_parse_result)

        self.text_input = QTextEdit()
        self.text_input.setAcceptRichText(False)
        self.text_input.setFont(fontmono)
        self.text_input.resize(450, 600)
        self.text_input.textChanged.connect(self.text_inputChanged)
        self.timer_wait_to_refresh = QTimer()
        self.timer_wait_to_refresh.setSingleShot(True)
        self.timer_wait_to_refresh.timeout.connect(self.refresh_output_when_timeout)

        self.text_output = QTextEdit()
        self.text_output.setFont(fontmono)
        self.text_output.resize(450, 600)
        self.text_output.setReadOnly(True)
        # self.text_output.setStyleSheet("background-color: gray")

        self.hbox = QHBoxLayout()
        # self.hbox.addStretch()
        self.hbox.addWidget(self.text_input)
        self.hbox.addWidget(self.text_output)
        # self.hbox.addStretch()

        self.vbox = QVBoxLayout()
        self.vbox.addLayout(self.subtitle)
        self.vbox.addLayout(self.hbox)

        self.mainWidget = QWidget()
        self.mainWidget.setLayout(self.vbox)
        main_window.setCentralWidget(self.mainWidget)

        main_window.setWindowTitle('JC WBXML Decoder')

        QtCore.QMetaObject.connectSlotsByName(main_window)