From b4625652947e832dc4c0dc296295d1ffcc200d50 Mon Sep 17 00:00:00 2001 From: halliday2023 Date: Tue, 13 Feb 2024 20:35:38 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E8=BD=BD=E5=85=A5u?= =?UTF-8?q?i=E6=96=B9=E5=BC=8F=202=E3=80=81=E5=A2=9E=E5=8A=A0pyinstaller?= =?UTF-8?q?=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataCreating_Click.spec | 66 +++++++++++++++++++++++++++++++++++++++ bin/DataCreating_Click.py | 2 +- bin/GUIWindows.py | 45 +++++++++++++------------- 3 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 DataCreating_Click.spec diff --git a/DataCreating_Click.spec b/DataCreating_Click.spec new file mode 100644 index 0000000..1226348 --- /dev/null +++ b/DataCreating_Click.spec @@ -0,0 +1,66 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis(['bin\\DataCreating_Click.py'], + pathex=['E:\\git-code\\dataCreatingGUI'], + binaries=[], + datas=[], + hiddenimports=['PySide6.QtXml'], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) + + + + +#######!!!注意点1:加载自己的资源文件##################### +def extra_datas(mydir): + def rec_glob(p, files): + import os + import glob + for d in glob.glob(p): + if os.path.isfile(d): + files.append(d) + rec_glob("%s/*" % d, files) + files = [] + rec_glob("%s/*" % mydir, files) + extra_datas = [] + for f in files: + extra_datas.append((f, f, 'DATA')) + + return extra_datas + +# append the 'Resources' dir +a.datas += extra_datas('etc') ###这里是自己的资源文件夹 +a.datas += extra_datas('ui') ###这里是自己的资源文件夹 +################################################ + +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) + + +exe = EXE(pyz, + a.scripts, + [], + exclude_binaries=True, ###!!!注意点3:这里是True + name='dataCreatingGUI', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=False) + + +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + name='dataCreatingGUI') \ No newline at end of file diff --git a/bin/DataCreating_Click.py b/bin/DataCreating_Click.py index 317a65e..8ddb6d5 100644 --- a/bin/DataCreating_Click.py +++ b/bin/DataCreating_Click.py @@ -13,6 +13,6 @@ if __name__ == '__main__': # print(QtWidgets.QStyleFactory.keys()) # print(app.style().name()) win = Window() - win.show() + win.ui.show() sys.exit(app.exec()) diff --git a/bin/GUIWindows.py b/bin/GUIWindows.py index bb34762..a618206 100644 --- a/bin/GUIWindows.py +++ b/bin/GUIWindows.py @@ -1,5 +1,4 @@ # -*- coding:utf-8 -*- -import os import sys import logging @@ -8,18 +7,13 @@ from common import global_var from pathlib import Path -from PySide6.QtUiTools import loadUiType -from PySide6.QtCore import Slot,Signal,QThread,QObject,QEventLoop,QTimer +from PySide6.QtUiTools import QUiLoader +from PySide6.QtCore import Signal,QThread,QObject,QEventLoop,QTimer from PySide6.QtWidgets import QApplication from PySide6.QtGui import QTextCursor # 声明全局变量 global_var._init() -# 定义公共路径 -path = Path(__file__) -ui_file_patch = path.parent.parent / "ui" / "ui_main.ui" -# 从文件中加载UI定义 -formType, baseType = loadUiType(str(ui_file_patch)) # 控制台重定向到GUI class EmittingStr(QObject): @@ -51,16 +45,23 @@ class FileThread(QThread): # GUI的主程序 -class Window(formType, baseType): +class Window: def __init__(self): - super(Window, self).__init__() - self.setupUi(self) + #载入ui + path = Path(__file__) + ui_file_patch = path.parent.parent / "ui" / "ui_main.ui" + self.ui = QUiLoader().load(str(ui_file_patch)) + #指定按钮和槽函数 + self.ui.startButton.clicked.connect(self.start) + self.ui.stopButton.clicked.connect(self.stop) + self.ui.conn_Button.clicked.connect(self.conntest) + self.setup_thread() # QTextBrowser输出设置,限制条数为100 - self.Log_Output.document().setMaximumBlockCount(100) - self.Log_Output.ensureCursorVisible() + self.ui.Log_Output.document().setMaximumBlockCount(100) + self.ui.Log_Output.ensureCursorVisible() # 将控制台输出重定向到QTextBrowser sys.stdout = EmittingStr() sys.stdout.textWritten.connect(self.outputWritten) @@ -76,18 +77,17 @@ class Window(formType, baseType): # 输出到GUI,信号处理函数 def outputWritten(self, text): - cursor = self.Log_Output.textCursor() + cursor = self.ui.Log_Output.textCursor() cursor.movePosition(QTextCursor.End) cursor.insertText(text) - self.Log_Output.setTextCursor(cursor) - self.Log_Output.ensureCursorVisible() + self.ui.Log_Output.setTextCursor(cursor) + self.ui.Log_Output.ensureCursorVisible() - @Slot() #声明槽函数 def start(self): self.logger.info("点击了开始按钮") # 输入框参数校验 - num = self.tabWidget.currentIndex() + num = self.ui.tabWidget.currentIndex() if num == 0: self.check_file_input() else: @@ -98,22 +98,21 @@ class Window(formType, baseType): else: self.start_run_db() # 按钮置灰 - self.startButton.setEnabled(False) + self.ui.startButton.setEnabled(False) - @Slot() def stop(self): self.logger.info("点击了停止按钮") - num = self.tabWidget.currentIndex() + num = self.ui.tabWidget.currentIndex() if num == 0: self.stop_run_file() else: self.stop_run_db() # 按钮恢复 # self.startButton.isEnabled() 获取按钮的状态 - self.startButton.setEnabled(True) + self.ui.startButton.setEnabled(True) + - @Slot() def conntest(self): self.logger.info("点击了测试连接按钮") self.check_db_input()