MetaFusion/config/data.py

104 lines
4.0 KiB
Python
Raw Normal View History

2025-02-03 22:58:41 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2025-02-05 02:38:32 +08:00
#===================================== IMPORT =====================================
2025-02-03 22:58:41 +08:00
import os
import sys
import maya.cmds as cmds
2025-02-05 01:52:29 +08:00
def Qt():
try:
from PySide2 import QtCore, QtGui, QtWidgets
2025-02-05 02:10:47 +08:00
print("加载PySide2")
2025-02-05 01:52:29 +08:00
return QtCore, QtGui, QtWidgets
except ImportError as e:
print(f"PySide2加载失败: {str(e)}")
try:
from PySide import QtCore, QtGui
QtWidgets = QtGui
2025-02-05 02:10:47 +08:00
print("加载PySide")
2025-02-05 01:52:29 +08:00
return QtCore, QtGui, QtWidgets
except ImportError as e:
cmds.warning(f"PySide加载失败: {str(e)}")
try:
from PySide6 import QtCore, QtGui, QtWidgets
2025-02-05 02:10:47 +08:00
print("加载PySide6")
2025-02-05 01:52:29 +08:00
return QtCore, QtGui, QtWidgets
except ImportError as e:
cmds.warning(f"PySide加载失败: {str(e)}")
return None, None, None
QtCore, QtGui, QtWidgets = Qt()
2025-02-05 02:38:32 +08:00
#===================================== BASE VARIBLES =====================================
2025-02-03 22:58:41 +08:00
try:
ROOT_PATH = os.path.dirname(INSTALL_PATH).replace("\\", "/")
except NameError:
# __file__ 在 config 中,所以返回上一级目录即项目根目录
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace("\\", "/")
TOOL_NAME = "MetaFusion"
TOOL_VERSION = "Beta v1.0.0"
TOOL_AUTHOR = "Virtuos"
TOOL_LANG = 'en_US'
TOOL_WSCL_NAME = f"{TOOL_NAME}WorkSpaceControl"
TOOL_HELP_URL = f"https://gitea.cgnico.com/CGNICO/{TOOL_NAME}/wiki"
2025-02-05 02:38:32 +08:00
#===================================== PATHS =====================================
2025-02-03 22:58:41 +08:00
# PATHS
SCRIPTS_PATH = os.path.join(ROOT_PATH, "scripts").replace("\\", "/")
ICONS_PATH = os.path.join(ROOT_PATH, "resources", "icons").replace("\\", "/")
STYLES_PATH = os.path.join(ROOT_PATH, "resources", "styles").replace("\\", "/")
2025-02-04 20:30:42 +08:00
DNA_PATH = os.path.join(ROOT_PATH, "resources", "dna").replace("\\", "/")
DNA_IMG_PATH = os.path.join(ROOT_PATH, "resources", "img").replace("\\", "/")
2025-02-05 02:38:32 +08:00
#===================================== 4. PYTON_VERSION_PATH =====================================
2025-02-05 01:52:29 +08:00
SYSTEM_OS = "Windows" if cmds.about(os=True).lower().startswith("win") else "Linux"
MAYA_VERSION = str(int(cmds.about(version=True).split(".")[0])) # 直接获取最新版本
# 必须先定义PYTHON_VERSION
PYTHON_VERSION = sys.version
# 去掉小数点比如3.10.8 → 3108
PYTHON_VERSION = PYTHON_VERSION.replace(".", "")
# 获取主版本号和次版本号
major_version = int(PYTHON_VERSION[0])
minor_version = int(PYTHON_VERSION[1:3]) if len(PYTHON_VERSION) > 1 else None
# 创建版本元组
version_tuple = (major_version,) if minor_version is None else (major_version, minor_version)
2025-02-03 22:58:41 +08:00
2025-02-05 01:52:29 +08:00
# 调整版本映射表
PYTHON_VERSION_MAP = {
(3,): "python3", # 所有Python3主版本
(3, 9): "python397", # 3.9.x → python397
(3, 10): "python3108", # 3.10.x → python3108
(3, 11): "python311" # 3.11.x → python311
}
# 按照映射表获取PYTHON_VERSION_DIR
PYTHON_VERSION_DIR = PYTHON_VERSION_MAP.get(version_tuple, "python3") # 如果找不到对应版本,默认使用 python3
2025-02-03 22:58:41 +08:00
2025-02-05 02:38:32 +08:00
#===================================== FILES =====================================
2025-02-03 22:58:41 +08:00
# FILES
TOOL_MAIN_SCRIPT = os.path.join(SCRIPTS_PATH, f"{TOOL_NAME}.py").replace("\\", "/")
TOOL_STYLE_FILE = os.path.join(STYLES_PATH, "style.qss").replace("\\", "/")
TOOL_ICON = os.path.join(ICONS_PATH, f"{TOOL_NAME}Logo.png").replace("\\", "/")
TOOL_COMMAND_ICON = os.path.join(ICONS_PATH, "CommandButton.png").replace("\\", "/")
TOOL_MOD_FILENAME = f"{TOOL_NAME}.mod"
2025-02-05 01:52:29 +08:00
# 生成最终路径
PLUGIN_PATH = os.path.join(ROOT_PATH, "plugins", SYSTEM_OS, MAYA_VERSION).replace("\\", "/")
PYDNA_PATH = os.path.join(ROOT_PATH, "plugins", SYSTEM_OS, "pydna", PYTHON_VERSION_DIR).replace("\\", "/")
2025-02-05 02:38:32 +08:00
#===================================== TOOLS =====================================
2025-02-05 01:52:29 +08:00
# 新增工具路径
BUILDER_PATH = os.path.join(SCRIPTS_PATH, "builder").replace("\\", "/")
DNALIB_PATH = os.path.join(SCRIPTS_PATH, "dnalib").replace("\\", "/")
2025-02-03 22:58:41 +08:00