优化调试工具,增加图标并压缩exe文件大小
authorkyz <kongyuzhong@google.com>
Wed, 20 Aug 2025 07:59:17 +0000 (15:59 +0800)
committerkyz <kongyuzhong@google.com>
Wed, 20 Aug 2025 07:59:17 +0000 (15:59 +0800)
tools_v2/icon.png [new file with mode: 0644]
tools_v2/mk_exe.txt [new file with mode: 0644]
tools_v2/test.py

diff --git a/tools_v2/icon.png b/tools_v2/icon.png
new file mode 100644 (file)
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 (file)
index 0000000..36f2915
--- /dev/null
@@ -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将文件打包进资源区域,程序启动后标题栏图标将从资源区域中获取图标文件
index 1f1e325d7e4fd3d6274a20b2381791a1a3fe5362..35cc6ba18ec31077503300ce49275bc02843aabc 100644 (file)
@@ -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 )