104 lines
4.0 KiB
Python
104 lines
4.0 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
#===================================== IMPORT =====================================
|
||
import os
|
||
import sys
|
||
import maya.cmds as cmds
|
||
|
||
def Qt():
|
||
try:
|
||
from PySide2 import QtCore, QtGui, QtWidgets
|
||
print("加载PySide2")
|
||
return QtCore, QtGui, QtWidgets
|
||
except ImportError as e:
|
||
print(f"PySide2加载失败: {str(e)}")
|
||
try:
|
||
from PySide import QtCore, QtGui
|
||
QtWidgets = QtGui
|
||
print("加载PySide")
|
||
return QtCore, QtGui, QtWidgets
|
||
except ImportError as e:
|
||
cmds.warning(f"PySide加载失败: {str(e)}")
|
||
try:
|
||
from PySide6 import QtCore, QtGui, QtWidgets
|
||
print("加载PySide6")
|
||
return QtCore, QtGui, QtWidgets
|
||
except ImportError as e:
|
||
cmds.warning(f"PySide加载失败: {str(e)}")
|
||
return None, None, None
|
||
|
||
QtCore, QtGui, QtWidgets = Qt()
|
||
|
||
#===================================== BASE VARIBLES =====================================
|
||
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"
|
||
|
||
#===================================== PATHS =====================================
|
||
# 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("\\", "/")
|
||
|
||
DNA_PATH = os.path.join(ROOT_PATH, "resources", "dna").replace("\\", "/")
|
||
DNA_IMG_PATH = os.path.join(ROOT_PATH, "resources", "img").replace("\\", "/")
|
||
|
||
#===================================== 4. PYTON_VERSION_PATH =====================================
|
||
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)
|
||
|
||
# 调整版本映射表
|
||
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
|
||
|
||
#===================================== FILES =====================================
|
||
# 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"
|
||
|
||
# 生成最终路径
|
||
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("\\", "/")
|
||
|
||
#===================================== TOOLS =====================================
|
||
# 新增工具路径
|
||
BUILDER_PATH = os.path.join(SCRIPTS_PATH, "builder").replace("\\", "/")
|
||
DNALIB_PATH = os.path.join(SCRIPTS_PATH, "dnalib").replace("\\", "/")
|
||
|
||
|
||
|
||
|
||
|
||
|