From: kyz Date: Wed, 20 Aug 2025 07:59:17 +0000 (+0800) Subject: 优化调试工具,增加图标并压缩exe文件大小 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=a527870c3b7f4e410ff754e3cd66354171bc2017;p=yn%2Fweldingcontroller.git 优化调试工具,增加图标并压缩exe文件大小 --- diff --git a/tools_v2/icon.png b/tools_v2/icon.png new file mode 100644 index 0000000..8cb6dba Binary files /dev/null and b/tools_v2/icon.png differ diff --git a/tools_v2/mk_exe.txt b/tools_v2/mk_exe.txt new file mode 100644 index 0000000..36f2915 --- /dev/null +++ b/tools_v2/mk_exe.txt @@ -0,0 +1,15 @@ +重新建立环境打包exe文件,以减小exe文件的大小 +1. 安装python虚拟环境 + python -m venv venv +2. 进入虚拟环境 + .\venv\Scripts\activate +3. 安装需要的包 + pip install pyserial numpy pyqtgraph pyqt5 crcmod intelhex pillow + pip install pyinstaller + pillow用于打包时把png文件转换到所需格式 +4. 安装upx用于压缩exe + wget https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-win64.zip + 解压zip文件到 d:\upx目录 +4. 执行打包指令, + pyinstaller.exe -F test.py -i icon.png --add-data "icon.png;." --upx-dir=D:\upx + 这里add-data将文件打包进资源区域,程序启动后标题栏图标将从资源区域中获取图标文件 diff --git a/tools_v2/test.py b/tools_v2/test.py index 1f1e325..35cc6ba 100644 --- a/tools_v2/test.py +++ b/tools_v2/test.py @@ -46,6 +46,13 @@ class App( QDialog, ui_welding.Ui_Dialog ): super().__init__() self.setupUi(self) self.setWindowTitle( u"焊接控制器调试工具 V1.0" ) + try: + # PyInstaller创建的临时文件夹,存储于_MEIPASS中 + base_path = sys._MEIPASS + except Exception: + base_path = os.path.abspath(".") + self.setWindowIcon(QIcon(os.path.join(base_path,"./icon.png"))) + self.trigger_rx_pkt.connect( self.on_rx_pkt ) self.trigger_ctrl_write.connect( self.on_ctrl_write_signal )