90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
import os
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
|
||
|
||
def _maybe_relaunch_with_py311():
|
||
"""Use Python 3.11 to match ui/lui.pyd ABI on Windows."""
|
||
if sys.version_info >= (3, 11):
|
||
return
|
||
if os.environ.get("EG_RELAUNCHED_PY311") == "1":
|
||
return
|
||
if os.name != "nt":
|
||
return
|
||
|
||
py_launcher = shutil.which("py")
|
||
if not py_launcher:
|
||
print(f"⚠ 当前解释器是 Python {sys.version.split()[0]},未找到 py launcher,无法自动切换到 3.11。")
|
||
return
|
||
|
||
try:
|
||
probe = subprocess.run(
|
||
[py_launcher, "-3.11", "-c", "import sys;print(sys.executable)"],
|
||
capture_output=True,
|
||
text=True,
|
||
check=False,
|
||
)
|
||
if probe.returncode != 0:
|
||
print("⚠ 未检测到可用的 Python 3.11,LUI 可能不可用。")
|
||
return
|
||
except Exception as e:
|
||
print(f"⚠ 检测 Python 3.11 失败: {e}")
|
||
return
|
||
|
||
os.environ["EG_RELAUNCHED_PY311"] = "1"
|
||
relaunch_cmd = [py_launcher, "-3.11", os.path.abspath(__file__), *sys.argv[1:]]
|
||
print(f"✓ 检测到 Python {sys.version.split()[0]},自动切换到 Python 3.11: {probe.stdout.strip()}")
|
||
os.execv(py_launcher, relaunch_cmd)
|
||
|
||
# 添加项目根目录到 Python 路径
|
||
project_root = os.path.dirname(os.path.abspath(__file__))
|
||
sys.path.insert(0, project_root)
|
||
third_party_path = os.path.join(project_root, "third_party")
|
||
if os.path.isdir(third_party_path):
|
||
sys.path.insert(0, third_party_path)
|
||
|
||
# 设置工作目录为项目根目录
|
||
os.chdir(project_root)
|
||
|
||
# 添加 RenderPipeline 到路径(注意路径名称应与实际目录一致)
|
||
render_pipeline_path = os.path.join(project_root, "RenderPipeline")
|
||
sys.path.insert(0, render_pipeline_path)
|
||
|
||
# 添加 RenderPipelineFile 路径
|
||
render_pipeline_file_path = os.path.join(project_root, "RenderPipelineFile")
|
||
sys.path.insert(0, render_pipeline_file_path)
|
||
|
||
# 添加 icons 目录到路径
|
||
icons_path = os.path.join(project_root, "icons")
|
||
sys.path.insert(0, icons_path)
|
||
|
||
# 现在可以导入并运行主程序
|
||
if __name__ == "__main__":
|
||
_maybe_relaunch_with_py311()
|
||
args = sys.argv[1:]
|
||
# args = "/home/tiger/桌面/Test1"
|
||
# args = "C:/Users/29381/Desktop/1"
|
||
print(f'Path is {args}')
|
||
# 将整个列表转换为字符串(包括方括号)
|
||
args_str = ''.join(args)
|
||
|
||
from main import MyWorld
|
||
if args:
|
||
# print(f"[DEBUG] 启动时传入项目路径: {args_str}")
|
||
# 创建应用实例
|
||
app = MyWorld()
|
||
# 如果传入了项目路径,尝试打开项目
|
||
if hasattr(app, 'project_manager'):
|
||
# print(f"[DEBUG] 尝试打开项目: {args_str}")
|
||
success = app.project_manager.openProject(args_str)
|
||
# print(f"[DEBUG] 项目打开结果: {success}")
|
||
else:
|
||
# print(f"[DEBUG] 项目管理器未初始化")
|
||
pass
|
||
app.run()
|
||
else:
|
||
# print(f"[DEBUG] 无项目路径,正常启动")
|
||
app = MyWorld()
|
||
app.run()
|