From 5f7c424a350a470eace8b7073b23fdbbad1e5036 Mon Sep 17 00:00:00 2001 From: Jeffreytsai1004 Date: Thu, 6 Feb 2025 04:46:41 +0800 Subject: [PATCH] Update --- Install.py | 189 ++++++++++++++++----------------- scripts/MetaFusion.py | 52 ++++----- scripts/ui/adjust.py | 37 +++++-- scripts/ui/define.py | 36 +++++-- scripts/ui/menu.py | 25 ++++- scripts/ui/models.py | 36 +++++-- scripts/ui/rigging.py | 53 +++++---- scripts/ui/widgets.py | 123 ++++++--------------- scripts/utils/adjust_utils.py | 11 +- scripts/utils/define_utils.py | 28 ++++- scripts/utils/install_check.py | 57 ---------- scripts/utils/menu_utils.py | 9 +- scripts/utils/model_utils.py | 14 ++- scripts/utils/rigging_utils.py | 11 +- 14 files changed, 340 insertions(+), 341 deletions(-) delete mode 100644 scripts/utils/install_check.py diff --git a/Install.py b/Install.py index 53aa307..d04549f 100644 --- a/Install.py +++ b/Install.py @@ -2,13 +2,14 @@ # -*- coding: utf-8 -*- #===================================== 1. Module Imports ===================================== -# Standard library imports -import os -import sys -import webbrowser -import maya.mel as mel -import maya.cmds as cmds import maya.OpenMayaUI as omui +import maya.cmds as cmds +import maya.mel as mel +import webbrowser +import sys +import os + +from scripts.config import data try: from PySide2 import QtCore, QtGui, QtWidgets @@ -29,36 +30,24 @@ except ImportError: QtCore = QtGui = QtWidgets = None wrapInstance = None -from scripts.config.data import ( - TOOL_NAME, TOOL_VERSION, TOOL_AUTHOR, TOOL_LANG, - TOOL_WSCL_NAME, TOOL_HELP_URL, TOOL_PATH, SCRIPTS_PATH, - ICONS_PATH, STYLES_PATH, DNA_FILE_PATH, DNA_IMG_PATH, - PLUGIN_PATH, PYDNA_PATH, DNACALIB_PATH, BUILDER_PATH, - DNALIB_PATH, UI_PATH, UTILS_PATH, TOOL_MAIN_SCRIPT, - TOOL_STYLE_FILE, TOOL_ICON, TOOL_COMMAND_ICON, - TOOL_MOD_FILENAME -) - -def get_script_path(): - try: - maya_script = mel.eval('getenv("MAYA_SCRIPT_PATH")') - if maya_script: - paths = maya_script.split(os.pathsep) - for path in paths: - install_path = os.path.join(path, "Install.py") - if os.path.exists(install_path): - return os.path.dirname(install_path) - except: - pass +# def get_script_path(): +# try: +# maya_script = mel.eval('getenv("MAYA_SCRIPT_PATH")') +# if maya_script: +# paths = maya_script.split(os.pathsep) +# for path in paths: +# install_path = os.path.join(path, "Install.py") +# if os.path.exists(install_path): +# return os.path.dirname(install_path) +# except: +# pass - try: - return os.path.dirname(os.path.abspath(__file__)) - except: - return os.getcwd() +# try: +# return os.path.dirname(os.path.abspath(__file__)) +# except: +# return os.getcwd() -TOOL_PATH = get_script_path() -if TOOL_PATH not in sys.path: - sys.path.insert(0, TOOL_PATH) +TOOL_PATH = data.TOOL_PATH #===================================== 3. Utility Functions ===================================== @@ -98,14 +87,14 @@ class InstallDialog(QtWidgets.QDialog): self.setup_ui() def load_stylesheet(self): - with open(TOOL_STYLE_FILE, 'r', encoding='utf-8') as f: + with open(data.TOOL_STYLE_FILE, 'r', encoding='utf-8') as f: style = f.read() self.setStyleSheet(style) - print(f"已加载样式文件: {TOOL_STYLE_FILE}") + print(f"已加载样式文件: {data.TOOL_STYLE_FILE}") def setup_ui(self): """Initialize and setup UI components""" - self.setWindowTitle(f"{TOOL_NAME} Installation") + self.setWindowTitle(f"{data.TOOL_NAME} Installation") self.setFixedSize(220, 120) self.setup_window_icon() self.create_widgets() @@ -114,16 +103,16 @@ class InstallDialog(QtWidgets.QDialog): def setup_window_icon(self): """Setup window icon if available""" - if os.path.exists(TOOL_ICON): - self.setWindowIcon(QtGui.QIcon(TOOL_ICON)) + if os.path.exists(data.TOOL_ICON): + self.setWindowIcon(QtGui.QIcon(data.TOOL_ICON)) else: - print(f"Warning: Icon file not found: {TOOL_ICON}") + print(f"Warning: Icon file not found: {data.TOOL_ICON}") #----------------- 5.1 UI Methods ----------------- def create_widgets(self): - self.new_shelf_toggle = QtWidgets.QCheckBox(f"{TOOL_NAME} Installation") - self.install_button = SetButton("Install " + TOOL_NAME) - self.uninstall_button = SetButton("Uninstall " + TOOL_NAME) + self.new_shelf_toggle = QtWidgets.QCheckBox(f"{data.TOOL_NAME} Installation") + self.install_button = SetButton("Install " + data.TOOL_NAME) + self.uninstall_button = SetButton("Uninstall " + data.TOOL_NAME) def create_layouts(self): main_layout = QtWidgets.QVBoxLayout(self) @@ -133,7 +122,7 @@ class InstallDialog(QtWidgets.QDialog): header_layout = QtWidgets.QHBoxLayout() header_layout.setSpacing(5) - welcome_label = QtWidgets.QLabel("Welcome to " + TOOL_NAME + "!") + welcome_label = QtWidgets.QLabel("Welcome to " + data.TOOL_NAME + "!") welcome_label.setStyleSheet("font-size: 11px; padding: 0px; margin: 0px;") header_layout.addWidget(welcome_label) header_layout.addStretch() @@ -179,7 +168,7 @@ class InstallDialog(QtWidgets.QDialog): #----------------- 5.3 Utility Methods ----------------- def open_help_url(self): - webbrowser.open(TOOL_HELP_URL) + webbrowser.open(data.TOOL_HELP_URL) QtWidgets.QApplication.restoreOverrideCursor() def get_script_path(): @@ -202,7 +191,7 @@ class InstallDialog(QtWidgets.QDialog): msg_box = self.create_styled_message_box( "Confirm Installation", - f"Are you sure you want to install {TOOL_NAME}?" + f"Are you sure you want to install {data.TOOL_NAME}?" ) if msg_box.exec_() == QtWidgets.QMessageBox.Yes: try: @@ -217,7 +206,7 @@ class InstallDialog(QtWidgets.QDialog): """Handle uninstall request""" msg_box = self.create_styled_message_box( "Confirm Uninstallation", - f"Are you sure you want to uninstall {TOOL_NAME}?" + f"Are you sure you want to uninstall {data.TOOL_NAME}?" ) if msg_box.exec_() == QtWidgets.QMessageBox.Yes: @@ -234,10 +223,10 @@ class InstallDialog(QtWidgets.QDialog): def create_mod_file(self): """Create or update the .mod file for Maya""" modules_dir = get_maya_modules_dir() - mod_content = f"""+ {TOOL_NAME} {TOOL_VERSION} {TOOL_PATH} - scripts: {SCRIPTS_PATH} + mod_content = f"""+ {data.TOOL_NAME} {data.TOOL_VERSION} {data.TOOL_PATH} + scripts: {data.SCRIPTS_PATH} """ - mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME) + mod_file_path = os.path.join(modules_dir, data.TOOL_MOD_FILENAME) self._write_mod_file(mod_file_path, mod_content) def _write_mod_file(self, file_path, content): @@ -253,37 +242,37 @@ class InstallDialog(QtWidgets.QDialog): def uninstall_mod_file(self): modules_dir = get_maya_modules_dir() - mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME) + mod_file_path = os.path.join(modules_dir, data.TOOL_MOD_FILENAME) if os.path.exists(mod_file_path): try: os.remove(mod_file_path) - print(f"{TOOL_NAME}.mod file deleted") + print(f"{data.TOOL_NAME}.mod file deleted") except Exception as e: - print(f"Error deleting {TOOL_NAME}.mod file: {e}") + print(f"Error deleting {data.TOOL_NAME}.mod file: {e}") def clean_existing_buttons(self): - if cmds.shelfLayout(TOOL_NAME, exists=True): - buttons = cmds.shelfLayout(TOOL_NAME, query=True, childArray=True) or [] + if cmds.shelfLayout(data.TOOL_NAME, exists=True): + buttons = cmds.shelfLayout(data.TOOL_NAME, query=True, childArray=True) or [] for btn in buttons: if cmds.shelfButton(btn, query=True, exists=True): label = cmds.shelfButton(btn, query=True, label=True) - if label == TOOL_NAME: + if label == data.TOOL_NAME: cmds.deleteUI(btn) - print(f"Deleted existing {TOOL_NAME} button: {btn}") + print(f"Deleted existing {data.TOOL_NAME} button: {btn}") def install_tool(self): """Install the tool to Maya""" - if not os.path.exists(SCRIPTS_PATH): - print(f"Error: Scripts path does not exist: {SCRIPTS_PATH}") + if not os.path.exists(data.SCRIPTS_PATH): + print(f"Error: Scripts path does not exist: {data.SCRIPTS_PATH}") return - if not os.path.exists(TOOL_MAIN_SCRIPT): - print(f"Error: Main script file not found: {TOOL_MAIN_SCRIPT}") + if not os.path.exists(data.TOOL_MAIN_SCRIPT): + print(f"Error: Main script file not found: {data.TOOL_MAIN_SCRIPT}") return # Add scripts path to Python path - if SCRIPTS_PATH not in sys.path: - sys.path.insert(0, SCRIPTS_PATH) + if data.SCRIPTS_PATH not in sys.path: + sys.path.insert(0, data.SCRIPTS_PATH) # Create shelf and button self._create_shelf_button() @@ -291,10 +280,10 @@ class InstallDialog(QtWidgets.QDialog): # Switch to the newly created shelf try: - cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=TOOL_NAME) - print(f"Switched to {TOOL_NAME} shelf") + cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=data.TOOL_NAME) + print(f"Switched to {data.TOOL_NAME} shelf") except Exception as e: - print(f"Error switching to {TOOL_NAME} shelf: {e}") + print(f"Error switching to {data.TOOL_NAME} shelf: {e}") self._show_install_success_message() @@ -303,24 +292,24 @@ class InstallDialog(QtWidgets.QDialog): shelf_layout = mel.eval('$tmpVar=$gShelfTopLevel') # Create shelf if not exists - if not cmds.shelfLayout(TOOL_NAME, exists=True): - cmds.shelfLayout(TOOL_NAME, parent=shelf_layout) + if not cmds.shelfLayout(data.TOOL_NAME, exists=True): + cmds.shelfLayout(data.TOOL_NAME, parent=shelf_layout) # Clean existing buttons self.clean_existing_buttons() # Create new button - icon_path = TOOL_ICON if os.path.exists(TOOL_ICON) else TOOL_COMMAND_ICON + icon_path = data.TOOL_ICON if os.path.exists(data.TOOL_ICON) else data.TOOL_COMMAND_ICON command = self._get_shelf_button_command() cmds.shelfButton( - parent=TOOL_NAME, + parent=data.TOOL_NAME, image1=icon_path, - label=TOOL_NAME, + label=data.TOOL_NAME, command=command, sourceType="python", - annotation=f"{TOOL_NAME} {TOOL_VERSION}", + annotation=f"{data.TOOL_NAME} {data.TOOL_VERSION}", noDefaultPopup=True, style="iconOnly" ) @@ -330,40 +319,40 @@ class InstallDialog(QtWidgets.QDialog): return f""" import sys import os -TOOL_PATH = r'{TOOL_PATH}' +TOOL_PATH = r'{data.TOOL_PATH}' if TOOL_PATH not in sys.path: sys.path.insert(0, TOOL_PATH) -SCRIPTS_PATH = r'{SCRIPTS_PATH}' +SCRIPTS_PATH = r'{data.SCRIPTS_PATH}' if SCRIPTS_PATH not in sys.path: sys.path.insert(0, SCRIPTS_PATH) os.chdir(SCRIPTS_PATH) try: - import {TOOL_NAME} - {TOOL_NAME}.show() + import MetaFusion + MetaFusion.show() except ImportError as e: - print("Error importing {TOOL_NAME}:", str(e)) - print("Scripts path:", {SCRIPTS_PATH}) + print("Error importing MetaFusion:", str(e)) + print(f"Scripts path: {data.SCRIPTS_PATH}") print("sys.path:", sys.path) - print("Contents of Scripts folder:", os.listdir({SCRIPTS_PATH})) + print(f"Contents of Scripts folder: {os.listdir(data.SCRIPTS_PATH)}") """ def uninstall_tool(self): """Uninstall the tool from Maya""" - window_name = f"{TOOL_NAME}Window" - dock_name = f"{TOOL_NAME}WindowDock" - shelf_file = f"shelf_{TOOL_NAME}.mel" + window_name = f"{data.TOOL_NAME}Window" + dock_name = f"{data.TOOL_NAME}WindowDock" + shelf_file = f"shelf_{data.TOOL_NAME}.mel" if cmds.window(window_name, exists=True): try: cmds.deleteUI(window_name) except Exception as e: - print(f"Error closing {TOOL_NAME} window: {e}") + print(f"Error closing {data.TOOL_NAME} window: {e}") if cmds.dockControl(dock_name, exists=True): try: cmds.deleteUI(dock_name) except Exception as e: - print(f"Error closing docked {TOOL_NAME} window: {e}") + print(f"Error closing docked {data.TOOL_NAME} window: {e}") self.uninstall_mod_file() @@ -371,17 +360,17 @@ except ImportError as e: current_shelf = cmds.shelfTabLayout("ShelfLayout", query=True, selectTab=True) # Delete Shelves and Buttons - if cmds.shelfLayout(TOOL_NAME, exists=True): + if cmds.shelfLayout(data.TOOL_NAME, exists=True): try: - cmds.deleteUI(TOOL_NAME, layout=True) + cmds.deleteUI(data.TOOL_NAME, layout=True) except Exception as e: - print(f"Error deleting {TOOL_NAME} shelf: {e}") + print(f"Error deleting {data.TOOL_NAME} shelf: {e}") self._clean_all_shelf_buttons() # Remove from Python path - if SCRIPTS_PATH in sys.path: - sys.path.remove(SCRIPTS_PATH) + if data.SCRIPTS_PATH in sys.path: + sys.path.remove(data.SCRIPTS_PATH) # Deleting Shelf Files shelf_path = os.path.join( @@ -389,7 +378,7 @@ except ImportError as e: cmds.about(version=True), "prefs", "shelves", - f"shelf_{TOOL_NAME}.mel" + f"shelf_{data.TOOL_NAME}.mel" ) if os.path.exists(shelf_path): @@ -399,7 +388,7 @@ except ImportError as e: print(f"Error deleting shelf file: {e}") # If the current tool shelf is a deleted tool shelf, switch to another tool shelf - if current_shelf == TOOL_NAME: + if current_shelf == data.TOOL_NAME: shelves = cmds.shelfTabLayout("ShelfLayout", query=True, childArray=True) if shelves and len(shelves) > 0: cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=shelves[0]) @@ -413,34 +402,34 @@ except ImportError as e: shelf_buttons = cmds.shelfLayout(shelf, query=True, childArray=True) or [] for btn in shelf_buttons: if cmds.shelfButton(btn, query=True, exists=True): - if cmds.shelfButton(btn, query=True, label=True) == TOOL_NAME: + if cmds.shelfButton(btn, query=True, label=True) == data.TOOL_NAME: cmds.deleteUI(btn) def _show_uninstall_success_message(self): """Show uninstallation success message""" msg_box = QtWidgets.QMessageBox() msg_box.setWindowTitle("Uninstallation Successful") - msg_box.setText(f"{TOOL_NAME} has been successfully uninstalled!") + msg_box.setText(f"{data.TOOL_NAME} has been successfully uninstalled!") msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok) - msg_box.setWindowIcon(QtGui.QIcon(TOOL_ICON)) + msg_box.setWindowIcon(QtGui.QIcon(data.TOOL_ICON)) msg_box.setStyleSheet(self.styleSheet()) msg_box.exec_() def _show_install_success_message(self): msg_box = QtWidgets.QMessageBox() msg_box.setWindowTitle("Installation Successful") - msg_box.setText(f"{TOOL_NAME} has been successfully installed!") + msg_box.setText(f"{data.TOOL_NAME} has been successfully installed!") msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok) - msg_box.setWindowIcon(QtGui.QIcon(TOOL_ICON)) + msg_box.setWindowIcon(QtGui.QIcon(data.TOOL_ICON)) msg_box.setStyleSheet(self.styleSheet()) msg_box.exec_() def _validate_paths(self): """Validate all required paths exist""" paths = { - "Root": TOOL_PATH, - "Scripts": SCRIPTS_PATH, - "Icons": ICONS_PATH + "Root": data.TOOL_PATH, + "Scripts": data.SCRIPTS_PATH, + "Icons": data.ICONS_PATH } for name, path in paths.items(): @@ -463,7 +452,7 @@ except ImportError as e: def _load_mel_shelf(self): """Load mel shelf file with error handling""" try: - mel.eval(f'loadNewShelf "shelf_{TOOL_NAME}.mel"') + mel.eval(f'loadNewShelf "shelf_{data.TOOL_NAME}.mel"') except Exception as e: self._log(f"Error loading shelf file: {e}", error=True) diff --git a/scripts/MetaFusion.py b/scripts/MetaFusion.py index 3509624..9b1f1ad 100644 --- a/scripts/MetaFusion.py +++ b/scripts/MetaFusion.py @@ -1,18 +1,17 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import os -import sys -import maya.cmds as cmds +#===================================== 1. Module Imports ===================================== import maya.OpenMayaUI as omui -import traceback - -import os -import sys -import webbrowser +import maya.cmds as cmds import maya.mel as mel -import maya.cmds as cmds -import maya.OpenMayaUI as omui +import webbrowser +import traceback +import sys +import os + +from scripts.config import data + try: from PySide2 import QtCore, QtGui, QtWidgets from shiboken2 import wrapInstance @@ -32,16 +31,6 @@ except ImportError: QtCore = QtGui = QtWidgets = None wrapInstance = None -from scripts.config.data import ( - TOOL_NAME, TOOL_VERSION, TOOL_AUTHOR, TOOL_LANG, - TOOL_WSCL_NAME, TOOL_HELP_URL, TOOL_PATH, SCRIPTS_PATH, - ICONS_PATH, STYLES_PATH, DNA_FILE_PATH, DNA_IMG_PATH, - PLUGIN_PATH, PYDNA_PATH, DNACALIB_PATH, BUILDER_PATH, - DNALIB_PATH, UI_PATH, UTILS_PATH, TOOL_MAIN_SCRIPT, - TOOL_STYLE_FILE, TOOL_ICON, TOOL_COMMAND_ICON, - TOOL_MOD_FILENAME -) - # 导入UI模块 from scripts.ui.menu import MenuManager from scripts.ui.models import ModelTab @@ -49,6 +38,7 @@ from scripts.ui.rigging import RigTab from scripts.ui.adjust import AdjustTab from scripts.ui.define import DefineTab +#===================================== 2. Main Window Class ===================================== class MainWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) @@ -61,16 +51,16 @@ class MainWindow(QtWidgets.QMainWindow): def setup_paths(self): """配置系统路径""" - if PLUGIN_PATH not in sys.path: - sys.path.insert(0, PLUGIN_PATH) + if data.PLUGIN_PATH not in sys.path: + sys.path.insert(0, data.PLUGIN_PATH) # 添加PyDNA路径 - pydna_bin = os.path.join(PYDNA_PATH, "bin") + pydna_bin = os.path.join(data.PYDNA_PATH, "bin") os.environ["PATH"] = f"{pydna_bin}{os.pathsep}{os.environ['PATH']}" def init_ui(self): """初始化UI框架""" - self.setWindowTitle(f"{TOOL_NAME} {TOOL_VERSION}") + self.setWindowTitle(f"{data.TOOL_NAME} {data.TOOL_VERSION}") self.setMinimumSize(1200, 800) # 主窗口布局 @@ -87,8 +77,8 @@ class MainWindow(QtWidgets.QMainWindow): def load_styles(self): """加载样式表""" - if os.path.exists(TOOL_STYLE_FILE): - with open(TOOL_STYLE_FILE, "r", encoding="utf-8") as f: + if os.path.exists(data.TOOL_STYLE_FILE): + with open(data.TOOL_STYLE_FILE, "r", encoding="utf-8") as f: self.setStyleSheet(f.read()) def create_tab_widget(self): @@ -122,12 +112,12 @@ def dock_to_maya(): """嵌入Maya Dock面板""" global main_window try: - if cmds.workspaceControl(TOOL_WSCL_NAME, exists=True): - cmds.deleteUI(TOOL_WSCL_NAME) + if cmds.workspaceControl(data.TOOL_WSCL_NAME, exists=True): + cmds.deleteUI(data.TOOL_WSCL_NAME) dock_control = cmds.workspaceControl( - TOOL_WSCL_NAME, - label=TOOL_NAME, + data.TOOL_WSCL_NAME, + label=data.TOOL_NAME, tabToControl=["AttributeEditor", -1], initialWidth=1400, minimumWidth=1000, @@ -157,7 +147,7 @@ def show(): try: if main_window: main_window.close() - cmds.deleteUI(TOOL_WSCL_NAME) + cmds.deleteUI(data.TOOL_WSCL_NAME) except: pass diff --git a/scripts/ui/adjust.py b/scripts/ui/adjust.py index d16e969..e28b81e 100644 --- a/scripts/ui/adjust.py +++ b/scripts/ui/adjust.py @@ -1,11 +1,34 @@ -import os -from scripts.config import data -from scripts.ui.widgets import ( - BaseWidget, BlendShapeList, BlendShapeControls, - BlendShapeTools, IconButton, SliderWithValue -) -QtCore, QtGui, QtWidgets = data.Qt() +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +from scripts.ui.widgets import (BaseWidget, BlendShapeList, BlendShapeControls, BlendShapeTools, IconButton, SliderWithValue) + +try: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: + try: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: + try: + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") + except ImportError as e: + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None + +#===================================== 2. Adjust Tab Class ===================================== class AdjustTab(BaseWidget): """调整标签页""" def __init__(self, parent=None): diff --git a/scripts/ui/define.py b/scripts/ui/define.py index c1c8f04..8e66c78 100644 --- a/scripts/ui/define.py +++ b/scripts/ui/define.py @@ -1,10 +1,34 @@ -import os -from scripts.config import data -from scripts.ui.widgets import ( - BaseWidget, IconButton, SearchLineEdit -) -QtCore, QtGui, QtWidgets = data.Qt() +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +from scripts.ui.widgets import ( BaseWidget, IconButton, SearchLineEdit) + +try: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: + try: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: + try: + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") + except ImportError as e: + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None + +#===================================== 2. Define Tab Class ===================================== class DefineTab(BaseWidget): """定义标签页""" def __init__(self, parent=None): diff --git a/scripts/ui/menu.py b/scripts/ui/menu.py index b003813..2f458fe 100644 --- a/scripts/ui/menu.py +++ b/scripts/ui/menu.py @@ -1,8 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#===================================== 1. Module Imports ===================================== import os from scripts.config import data from scripts.utils import menu_utils -QtCore, QtGui, QtWidgets = data.Qt() +try: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: + try: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: + try: + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") + except ImportError as e: + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None + +#===================================== 2. Menu Manager Class ===================================== class MenuManager: """菜单管理器""" def __init__(self, parent): diff --git a/scripts/ui/models.py b/scripts/ui/models.py index 08d33e3..918e7ed 100644 --- a/scripts/ui/models.py +++ b/scripts/ui/models.py @@ -1,10 +1,34 @@ -import os -from scripts.config import data -from scripts.ui.widgets import ( - BaseWidget, LODGroup, IconButton, SearchLineEdit -) -QtCore, QtGui, QtWidgets = data.Qt() +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +from scripts.ui.widgets import (BaseWidget, LODGroup, IconButton, SearchLineEdit) + +try: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: + try: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: + try: + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") + except ImportError as e: + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None + +#===================================== 2. Model Tab Class ===================================== class ModelTab(BaseWidget): """模型标签页""" def __init__(self, parent=None): diff --git a/scripts/ui/rigging.py b/scripts/ui/rigging.py index f7b05af..0f5e4cd 100644 --- a/scripts/ui/rigging.py +++ b/scripts/ui/rigging.py @@ -1,39 +1,34 @@ -import os -import sys +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#===================================== 1. Module Imports ===================================== import maya.cmds as cmds -from scripts.ui.widgets import ( - BaseWidget, DNABrowser, DescriptionWidget, IconButton, SearchLineEdit -) -try: - from PySide import QtCore, QtGui, QtWidgets - print(f"从PySide加载Qt") -except ImportError as e: - try: - from PySide2 import QtCore, QtGui, QtWidgets - print(f"从PySide2加载Qt") - except ImportError as e: - try: - from PySide6 import QtCore, QtGui, QtWidgets - print(f"从PySide6加载Qt") - except ImportError as e: - print(f"PySide6加载失败: {str(e)}") +import maya.mel as mel +import sys +import os + +from scripts.ui.widgets import (BaseWidget, DNABrowser, DescriptionWidget, IconButton, SearchLineEdit) try: - from shiboken import wrapInstance - print(f"从shiboken加载wrapInstance") -except ImportError as e: - cmds.warning(f"shiboken加载失败: {str(e)}") + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: try: - from shiboken2 import wrapInstance - print(f"从shiboken2加载wrapInstance") - except ImportError as e: - cmds.warning(f"shiboken2加载失败: {str(e)}") + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: try: - from shiboken6 import wrapInstance - print(f"从shiboken6加载wrapInstance") + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") except ImportError as e: - cmds.warning(f"shiboken6加载失败: {str(e)}") + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None +#===================================== 2. Rigging Tab Class ===================================== class RigTab(BaseWidget): """绑定标签页""" def __init__(self, parent=None): diff --git a/scripts/ui/widgets.py b/scripts/ui/widgets.py index a45d809..514dec6 100644 --- a/scripts/ui/widgets.py +++ b/scripts/ui/widgets.py @@ -1,97 +1,34 @@ -import os -import sys +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#===================================== 1. Module Imports ===================================== import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +from scripts.config import data try: - from PySide import QtCore, QtGui, QtWidgets - print(f"从PySide加载Qt") -except ImportError as e: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: try: - from PySide2 import QtCore, QtGui, QtWidgets - print(f"从PySide2加载Qt") - except ImportError as e: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: try: - from PySide6 import QtCore, QtGui, QtWidgets - print(f"从PySide6加载Qt") + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") except ImportError as e: - print(f"PySide6加载失败: {str(e)}") - -try: - from shiboken import wrapInstance - print(f"从shiboken加载wrapInstance") -except ImportError as e: - cmds.warning(f"shiboken加载失败: {str(e)}") - try: - from shiboken2 import wrapInstance - print(f"从shiboken2加载wrapInstance") - except ImportError as e: - cmds.warning(f"shiboken2加载失败: {str(e)}") - try: - from shiboken6 import wrapInstance - print(f"从shiboken6加载wrapInstance") - except ImportError as e: - cmds.warning(f"shiboken6加载失败: {str(e)}") - -from scripts.config.data import ( - ROOT_PATH, - TOOL_NAME, - TOOL_VERSION, - TOOL_AUTHOR, - TOOL_LANG, - TOOL_WSCL_NAME, - TOOL_HELP_URL, - SCRIPTS_PATH, - ICONS_PATH, - STYLES_PATH, - DNA_FILE_PATH, - DNA_IMG_PATH, - PLUGIN_PATH, - PYDNA_PATH, - DNACALIB_PATH, - BUILDER_PATH, - DNALIB_PATH, - UI_PATH, - UTILS_PATH, - TOOL_MAIN_SCRIPT, - TOOL_STYLE_FILE, - TOOL_ICON, - TOOL_COMMAND_ICON, - TOOL_MOD_FILENAME, - STYLE_FILE -) - -if {ROOT_PATH, - SCRIPTS_PATH, - ICONS_PATH, - STYLES_PATH, - DNA_FILE_PATH, - DNA_IMG_PATH, - PLUGIN_PATH, - PYDNA_PATH, - DNACALIB_PATH, - BUILDER_PATH, - DNALIB_PATH, - UI_PATH, - UTILS_PATH -} not in sys.path: - for path in [ - ROOT_PATH, - SCRIPTS_PATH, - ICONS_PATH, - STYLES_PATH, - DNA_FILE_PATH, - DNA_IMG_PATH, - PLUGIN_PATH, - PYDNA_PATH, - DNACALIB_PATH, - BUILDER_PATH, - DNALIB_PATH, - UI_PATH, - UTILS_PATH - ]: - if path not in sys.path: - sys.path.append(path) + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None +#===================================== 2. Base Widget Class ===================================== class BaseWidget(QtWidgets.QWidget): """基础控件类""" def __init__(self, parent=None): @@ -122,7 +59,7 @@ class LoadButton(QtWidgets.QPushButton): def setup_ui(self, text, icon_name): if text: self.setText(text) - icon_path = os.path.join(ICONS_PATH, icon_name) + icon_path = os.path.join(data.ICONS_PATH, icon_name) if os.path.exists(icon_path): self.setIcon(QtGui.QIcon(icon_path)) self.setFixedSize(25, 25) @@ -238,7 +175,7 @@ class IconButton(QtWidgets.QPushButton): def setup_ui(self, icon_name, tooltip): if icon_name: - icon_path = os.path.join(ICONS_PATH, icon_name) + icon_path = os.path.join(data.ICONS_PATH, icon_name) if os.path.exists(icon_path): self.setIcon(QtGui.QIcon(icon_path)) if tooltip: @@ -335,8 +272,8 @@ class DNABrowser(QtWidgets.QWidget): self.model.clear() # 从DNA目录加载文件 - dna_path = DNA_FILE_PATH - img_path = DNA_IMG_PATH + dna_path = data.DNA_FILE_PATH + img_path = data.DNA_IMG_PATH if os.path.exists(dna_path): for file in os.listdir(dna_path): @@ -907,10 +844,10 @@ class ExpressionPreviewWidget(QtWidgets.QWidget): """切换播放状态""" if checked: self.play_timer.start(33) # ~30fps - self.play_btn.setIcon(QtGui.QIcon(os.path.join(ICONS_PATH, "pause.png"))) + self.play_btn.setIcon(QtGui.QIcon(os.path.join(data.ICONS_PATH, "pause.png"))) else: self.play_timer.stop() - self.play_btn.setIcon(QtGui.QIcon(os.path.join(ICONS_PATH, "play.png"))) + self.play_btn.setIcon(QtGui.QIcon(os.path.join(data.ICONS_PATH, "play.png"))) def update_time(self): """更新时间""" diff --git a/scripts/utils/adjust_utils.py b/scripts/utils/adjust_utils.py index 3ea219c..a00e4f0 100644 --- a/scripts/utils/adjust_utils.py +++ b/scripts/utils/adjust_utils.py @@ -1,6 +1,13 @@ -import maya.cmds as cmds -from scripts.config import data +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +#===================================== 2. BlendShape Manager Class ===================================== class BlendShapeManager: """BlendShape管理器""" def __init__(self): diff --git a/scripts/utils/define_utils.py b/scripts/utils/define_utils.py index 5ab97b3..3d19c2f 100644 --- a/scripts/utils/define_utils.py +++ b/scripts/utils/define_utils.py @@ -1,8 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys import os import json -import maya.cmds as cmds from scripts.config import data +try: + from PySide2 import QtCore, QtGui, QtWidgets + from shiboken2 import wrapInstance + print("从PySide2加载Qt和shiboken2") +except ImportError: + try: + from PySide6 import QtCore, QtGui, QtWidgets + from shiboken6 import wrapInstance + print("从PySide6加载Qt和shiboken6") + except ImportError: + try: + from PySide import QtCore, QtGui, QtWidgets + from shiboken import wrapInstance + print("从PySide加载Qt和shiboken") + except ImportError as e: + print(f"Qt加载失败: {str(e)}") + QtCore = QtGui = QtWidgets = None + wrapInstance = None + +#===================================== 2. DNA Definition Class ===================================== class DNADefinition: """DNA定义类""" def __init__(self): diff --git a/scripts/utils/install_check.py b/scripts/utils/install_check.py deleted file mode 100644 index 79c9ae8..0000000 --- a/scripts/utils/install_check.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -import maya.cmds as cmds - -def check_installation(): - """检查插件安装状态""" - # 获取当前插件路径 - plugin_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - - issues = [] - - # 检查mod文件 - maya_mod_path = os.path.join(os.getenv('MAYA_APP_DIR'), 'modules') - mod_file = os.path.join(maya_mod_path, 'MetaFusion.mod') - if not os.path.exists(mod_file): - issues.append("缺少mod文件") - else: - # 验证mod文件内容 - with open(mod_file, 'r') as f: - content = f.read() - if plugin_path not in content: - issues.append("mod文件路径不正确") - - # 检查必要目录 - required_dirs = [ - 'ui', - 'utils', - 'config', - 'resources/icons' - ] - for dir_path in required_dirs: - if not os.path.exists(os.path.join(plugin_path, dir_path)): - issues.append(f"缺少必要目录: {dir_path}") - - # 检查必要文件 - required_files = [ - 'MetaFusion.py', - 'ui/__init__.py', - 'ui/menu.py', - 'ui/models.py', - 'ui/rigging.py', - 'ui/define.py', - 'utils/adjust_utils.py', - 'utils/define_utils.py', - 'config/data.py' - ] - for file_path in required_files: - if not os.path.exists(os.path.join(plugin_path, file_path)): - issues.append(f"缺少必要文件: {file_path}") - - # 检查插件加载 - if not cmds.pluginInfo('MetaFusion', q=True, loaded=True): - try: - cmds.loadPlugin('MetaFusion') - except: - issues.append("插件无法加载") - - return issues \ No newline at end of file diff --git a/scripts/utils/menu_utils.py b/scripts/utils/menu_utils.py index 3f03628..933041d 100644 --- a/scripts/utils/menu_utils.py +++ b/scripts/utils/menu_utils.py @@ -1,8 +1,15 @@ -import os +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#===================================== 1. Module Imports ===================================== import maya.cmds as cmds +import maya.mel as mel +import sys +import os from scripts.config import data from scripts.utils import model_utils, rigging_utils, adjust_utils, define_utils +#===================================== 2. Menu Utils ===================================== def load_dna(): """打开DNA文件""" file_path = cmds.fileDialog2( diff --git a/scripts/utils/model_utils.py b/scripts/utils/model_utils.py index 62aefff..c87a484 100644 --- a/scripts/utils/model_utils.py +++ b/scripts/utils/model_utils.py @@ -1,9 +1,13 @@ -import os -import maya.cmds as cmds -from scripts.config import data -import maya.mel as mel +#!/usr/bin/env python +# -*- coding: utf-8 -*- -# LOD模型加载功能 +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +#===================================== 2. Model Utils ===================================== def load_model(lod_index, model_type, file_path): """加载模型 Args: diff --git a/scripts/utils/rigging_utils.py b/scripts/utils/rigging_utils.py index c5caf9e..25fd11e 100644 --- a/scripts/utils/rigging_utils.py +++ b/scripts/utils/rigging_utils.py @@ -1,6 +1,13 @@ -import maya.cmds as cmds -from scripts.config import data +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#===================================== 1. Module Imports ===================================== +import maya.cmds as cmds +import maya.mel as mel +import sys +import os + +#===================================== 2. Rigging Utils ===================================== def export_settings(): """导出设置""" print("导出设置功能待实现")