1、修改载入ui方式

2、增加pyinstaller打包
This commit is contained in:
halliday2023 2024-02-13 20:35:38 +08:00
parent fc17a0206b
commit b462565294
3 changed files with 89 additions and 24 deletions

66
DataCreating_Click.spec Normal file
View File

@ -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')

View File

@ -13,6 +13,6 @@ if __name__ == '__main__':
# print(QtWidgets.QStyleFactory.keys()) # print(QtWidgets.QStyleFactory.keys())
# print(app.style().name()) # print(app.style().name())
win = Window() win = Window()
win.show() win.ui.show()
sys.exit(app.exec()) sys.exit(app.exec())

View File

@ -1,5 +1,4 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import os
import sys import sys
import logging import logging
@ -8,18 +7,13 @@ from common import global_var
from pathlib import Path from pathlib import Path
from PySide6.QtUiTools import loadUiType from PySide6.QtUiTools import QUiLoader
from PySide6.QtCore import Slot,Signal,QThread,QObject,QEventLoop,QTimer from PySide6.QtCore import Signal,QThread,QObject,QEventLoop,QTimer
from PySide6.QtWidgets import QApplication from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QTextCursor from PySide6.QtGui import QTextCursor
# 声明全局变量 # 声明全局变量
global_var._init() 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 # 控制台重定向到GUI
class EmittingStr(QObject): class EmittingStr(QObject):
@ -51,16 +45,23 @@ class FileThread(QThread):
# GUI的主程序 # GUI的主程序
class Window(formType, baseType): class Window:
def __init__(self): def __init__(self):
super(Window, self).__init__() #载入ui
self.setupUi(self) 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() self.setup_thread()
# QTextBrowser输出设置限制条数为100 # QTextBrowser输出设置限制条数为100
self.Log_Output.document().setMaximumBlockCount(100) self.ui.Log_Output.document().setMaximumBlockCount(100)
self.Log_Output.ensureCursorVisible() self.ui.Log_Output.ensureCursorVisible()
# 将控制台输出重定向到QTextBrowser # 将控制台输出重定向到QTextBrowser
sys.stdout = EmittingStr() sys.stdout = EmittingStr()
sys.stdout.textWritten.connect(self.outputWritten) sys.stdout.textWritten.connect(self.outputWritten)
@ -76,18 +77,17 @@ class Window(formType, baseType):
# 输出到GUI信号处理函数 # 输出到GUI信号处理函数
def outputWritten(self, text): def outputWritten(self, text):
cursor = self.Log_Output.textCursor() cursor = self.ui.Log_Output.textCursor()
cursor.movePosition(QTextCursor.End) cursor.movePosition(QTextCursor.End)
cursor.insertText(text) cursor.insertText(text)
self.Log_Output.setTextCursor(cursor) self.ui.Log_Output.setTextCursor(cursor)
self.Log_Output.ensureCursorVisible() self.ui.Log_Output.ensureCursorVisible()
@Slot() #声明槽函数
def start(self): def start(self):
self.logger.info("点击了开始按钮") self.logger.info("点击了开始按钮")
# 输入框参数校验 # 输入框参数校验
num = self.tabWidget.currentIndex() num = self.ui.tabWidget.currentIndex()
if num == 0: if num == 0:
self.check_file_input() self.check_file_input()
else: else:
@ -98,22 +98,21 @@ class Window(formType, baseType):
else: else:
self.start_run_db() self.start_run_db()
# 按钮置灰 # 按钮置灰
self.startButton.setEnabled(False) self.ui.startButton.setEnabled(False)
@Slot()
def stop(self): def stop(self):
self.logger.info("点击了停止按钮") self.logger.info("点击了停止按钮")
num = self.tabWidget.currentIndex() num = self.ui.tabWidget.currentIndex()
if num == 0: if num == 0:
self.stop_run_file() self.stop_run_file()
else: else:
self.stop_run_db() self.stop_run_db()
# 按钮恢复 # 按钮恢复
# self.startButton.isEnabled() 获取按钮的状态 # self.startButton.isEnabled() 获取按钮的状态
self.startButton.setEnabled(True) self.ui.startButton.setEnabled(True)
@Slot()
def conntest(self): def conntest(self):
self.logger.info("点击了测试连接按钮") self.logger.info("点击了测试连接按钮")
self.check_db_input() self.check_db_input()