修复不根心的问题

This commit is contained in:
Robofish 2025-12-29 21:16:17 +08:00
parent 8f4636ab5a
commit 3e246f1de6
30 changed files with 34 additions and 29 deletions

View File

@ -9,9 +9,6 @@ OutputBaseFilename=MRobotInstaller
[Files]
Source: "dist\MRobot.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "assets\logo\*"; DestDir: "{app}\assets\logo"; Flags: ignoreversion recursesubdirs
Source: "assets\User_code\*"; DestDir: "{app}\assets\User_code"; Flags: ignoreversion recursesubdirs
Source: "assets\mech_lib\*"; DestDir: "{app}\assets\mech_lib"; Flags: ignoreversion recursesubdirs
Source: "assets\logo\M.ico"; DestDir: "{app}\assets\logo"; Flags: ignoreversion
[Icons]
Name: "{group}\MRobot"; Filename: "{app}\MRobot.exe"; IconFilename: "{app}\assets\logo\M.ico"

View File

@ -86,5 +86,5 @@
使用以下命令构建可执行文件:
```bash
pyinstaller MRobot.py --onefile --windowed --add-data "assets;assets" --add-data "app;app" --add-data "app/tools;app/tools"
pyinstaller MRobot.py --onefile --windowed --add-data "assets/logo;assets/logo" --add-data "app;app" --add-data "app/tools;app/tools"
```

Binary file not shown.

Binary file not shown.

View File

@ -5,10 +5,20 @@ import sys
import os
def resource_path(relative_path):
"""获取资源文件的绝对路径,兼容打包和开发环境"""
if hasattr(sys, '_MEIPASS'):
# PyInstaller 打包后的临时目录
return os.path.join(sys._MEIPASS, relative_path)
"""获取资源文件的绝对路径,兼容打包和开发环境
对于 logo 文件使用打包的临时目录只有 logo 被打包
对于其他资源使用可执行文件所在目录
"""
if getattr(sys, 'frozen', False):
# 打包环境
if 'logo' in relative_path:
# logo 文件使用打包的临时目录
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
# 其他资源使用可执行文件所在目录
exe_dir = os.path.dirname(sys.executable)
return os.path.join(exe_dir, relative_path)
# 开发环境
return os.path.join(os.path.abspath("."), relative_path)
class HomeInterface(QWidget):

Binary file not shown.

View File

@ -97,29 +97,19 @@ class CodeGenerator:
assets_dir = ""
if getattr(sys, 'frozen', False):
# 打包后的环境
print("检测到打包环境")
# 打包后的环境 - 始终使用可执行文件所在目录
# 这样可以使用安装目录下的文件,而不是打包进去的文件
exe_dir = os.path.dirname(sys.executable)
assets_dir = os.path.join(exe_dir, "assets")
print(f"打包环境:使用可执行文件目录: {assets_dir}")
# 优先使用sys._MEIPASSPyInstaller的临时解包目录
if hasattr(sys, '_MEIPASS'):
base_path = getattr(sys, '_MEIPASS')
assets_dir = os.path.join(base_path, "assets")
print(f"使用PyInstaller临时目录: {assets_dir}")
else:
# 后备方案:使用可执行文件所在目录
exe_dir = os.path.dirname(sys.executable)
assets_dir = os.path.join(exe_dir, "assets")
print(f"使用可执行文件目录: {assets_dir}")
# 如果都不存在,尝试其他可能的位置
# 如果assets目录不存在创建它
if not os.path.exists(assets_dir):
# 尝试从当前工作目录查找
cwd_assets = os.path.join(os.getcwd(), "assets")
if os.path.exists(cwd_assets):
assets_dir = cwd_assets
print(f"从工作目录找到assets: {assets_dir}")
else:
print(f"警告无法找到assets目录使用默认路径: {assets_dir}")
try:
os.makedirs(assets_dir, exist_ok=True)
print(f"创建assets目录: {assets_dir}")
except Exception as e:
print(f"创建assets目录失败: {e}")
else:
# 开发环境
current_dir = os.path.dirname(os.path.abspath(__file__))

View File

@ -0,0 +1,8 @@
{
"id": "7751771f-1363-4606-b292-2db511004bae",
"name": "admin",
"description": "默认管理账户",
"categories": [],
"created_at": "2025-12-29T20:48:32.536465",
"updated_at": "2025-12-29T20:48:32.536472"
}