Update
This commit is contained in:
parent
d5bbe481f7
commit
df54452607
170
Install.py
170
Install.py
@ -30,13 +30,49 @@ except ImportError:
|
|||||||
QtCore = QtGui = QtWidgets = None
|
QtCore = QtGui = QtWidgets = None
|
||||||
wrapInstance = None
|
wrapInstance = None
|
||||||
|
|
||||||
|
TOOL_NAME = data.TOOL_NAME
|
||||||
|
TOOL_ICON = data.TOOL_ICON
|
||||||
|
TOOL_COMMAND_ICON = data.TOOL_COMMAND_ICON
|
||||||
|
TOOL_VERSION = data.TOOL_VERSION
|
||||||
|
TOOL_AUTHOR = data.TOOL_AUTHOR
|
||||||
|
TOOL_LANG = data.TOOL_LANG
|
||||||
|
TOOL_WSCL_NAME = data.TOOL_WSCL_NAME
|
||||||
|
TOOL_YEAR = data.TOOL_YEAR
|
||||||
|
TOOL_MOD_FILENAME = data.TOOL_MOD_FILENAME
|
||||||
|
SYSTEM_OS = data.SYSTEM_OS
|
||||||
|
TOOL_PATH = data.TOOL_PATH
|
||||||
ROOT_DIR = data.TOOL_PATH
|
ROOT_DIR = data.TOOL_PATH
|
||||||
|
ICONS_PATH = data.ICONS_PATH
|
||||||
|
SCRIPTS_PATH = data.SCRIPTS_PATH
|
||||||
|
TOOL_STYLE_FILE = data.TOOL_STYLE_FILE
|
||||||
MAYA_VERSION = data.MAYA_VERSION
|
MAYA_VERSION = data.MAYA_VERSION
|
||||||
|
PYTHON_VERSION_DIR = data.PYTHON_VERSION_DIR
|
||||||
|
TOOL_HELP_URL = data.TOOL_HELP_URL
|
||||||
|
PLUGIN_PATH = data.PLUGIN_PATH
|
||||||
PYDNA_PATH = data.PYDNA_PATH
|
PYDNA_PATH = data.PYDNA_PATH
|
||||||
print(f"ROOT_DIR: {ROOT_DIR}")
|
TOOL_MAIN_SCRIPT = data.TOOL_MAIN_SCRIPT
|
||||||
|
|
||||||
|
print(f"TOOL_NAME: {TOOL_NAME}")
|
||||||
|
print(f"TOOL_VERSION: {TOOL_VERSION}")
|
||||||
|
print(f"TOOL_AUTHOR: {TOOL_AUTHOR}")
|
||||||
|
print(f"TOOL_LANG: {TOOL_LANG}")
|
||||||
|
print(f"TOOL_WSCL_NAME: {TOOL_WSCL_NAME}")
|
||||||
|
print(f"TOOL_YEAR: {TOOL_YEAR}")
|
||||||
|
print(f"TOOL_MOD_FILENAME: {TOOL_MOD_FILENAME}")
|
||||||
|
print(f"TOOL_HELP_URL: {TOOL_HELP_URL}")
|
||||||
|
|
||||||
|
print(f"SYSTEM_OS: {SYSTEM_OS}")
|
||||||
print(f"MAYA_VERSION: {MAYA_VERSION}")
|
print(f"MAYA_VERSION: {MAYA_VERSION}")
|
||||||
|
print(f"PYTHON: {PYTHON_VERSION_DIR}")
|
||||||
|
print(f"TOOL_PATH: {TOOL_PATH}")
|
||||||
|
|
||||||
|
print(f"ROOT_DIR: {ROOT_DIR}")
|
||||||
|
print(f"SCRIPTS_PATH: {SCRIPTS_PATH}")
|
||||||
|
print(f"TOOL_STYLE_FILE: {TOOL_STYLE_FILE}")
|
||||||
|
print(f"PLUGIN_PATH: {PLUGIN_PATH}")
|
||||||
print(f"PYDNA_PATH: {PYDNA_PATH}")
|
print(f"PYDNA_PATH: {PYDNA_PATH}")
|
||||||
|
|
||||||
|
|
||||||
#===================================== 3. Utility Functions =====================================
|
#===================================== 3. Utility Functions =====================================
|
||||||
def maya_main_window():
|
def maya_main_window():
|
||||||
"""获取Maya主窗口"""
|
"""获取Maya主窗口"""
|
||||||
@ -74,13 +110,13 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
|
|
||||||
def load_stylesheet(self):
|
def load_stylesheet(self):
|
||||||
with open(data.TOOL_STYLE_FILE, 'r', encoding='utf-8') as f:
|
with open(TOOL_STYLE_FILE, 'r', encoding='utf-8') as f:
|
||||||
style = f.read()
|
style = f.read()
|
||||||
self.setStyleSheet(style)
|
self.setStyleSheet(style)
|
||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
"""Initialize and setup UI components"""
|
"""Initialize and setup UI components"""
|
||||||
self.setWindowTitle(f"{data.TOOL_NAME} Installation")
|
self.setWindowTitle(f"{TOOL_NAME} Installation")
|
||||||
self.setFixedSize(220, 120)
|
self.setFixedSize(220, 120)
|
||||||
self.setup_window_icon()
|
self.setup_window_icon()
|
||||||
self.create_widgets()
|
self.create_widgets()
|
||||||
@ -89,16 +125,16 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
def setup_window_icon(self):
|
def setup_window_icon(self):
|
||||||
"""Setup window icon if available"""
|
"""Setup window icon if available"""
|
||||||
if os.path.exists(data.TOOL_ICON):
|
if os.path.exists(TOOL_ICON):
|
||||||
self.setWindowIcon(QtGui.QIcon(data.TOOL_ICON))
|
self.setWindowIcon(QtGui.QIcon(TOOL_ICON))
|
||||||
else:
|
else:
|
||||||
print(f"Warning: Icon file not found: {data.TOOL_ICON}")
|
print(f"Warning: Icon file not found: {TOOL_ICON}")
|
||||||
|
|
||||||
#----------------- 5.1 UI Methods -----------------
|
#----------------- 5.1 UI Methods -----------------
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
self.new_shelf_toggle = QtWidgets.QCheckBox(f"{data.TOOL_NAME} Installation")
|
self.new_shelf_toggle = QtWidgets.QCheckBox(f"{TOOL_NAME} Installation")
|
||||||
self.install_button = SetButton("Install " + data.TOOL_NAME)
|
self.install_button = SetButton("Install " + TOOL_NAME)
|
||||||
self.uninstall_button = SetButton("Uninstall " + data.TOOL_NAME)
|
self.uninstall_button = SetButton("Uninstall " + TOOL_NAME)
|
||||||
|
|
||||||
def create_layouts(self):
|
def create_layouts(self):
|
||||||
main_layout = QtWidgets.QVBoxLayout(self)
|
main_layout = QtWidgets.QVBoxLayout(self)
|
||||||
@ -108,7 +144,7 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
header_layout = QtWidgets.QHBoxLayout()
|
header_layout = QtWidgets.QHBoxLayout()
|
||||||
header_layout.setSpacing(5)
|
header_layout.setSpacing(5)
|
||||||
|
|
||||||
welcome_label = QtWidgets.QLabel("Welcome to " + data.TOOL_NAME + "!")
|
welcome_label = QtWidgets.QLabel("Welcome to " + TOOL_NAME + "!")
|
||||||
welcome_label.setStyleSheet("font-size: 11px; padding: 0px; margin: 0px;")
|
welcome_label.setStyleSheet("font-size: 11px; padding: 0px; margin: 0px;")
|
||||||
header_layout.addWidget(welcome_label)
|
header_layout.addWidget(welcome_label)
|
||||||
header_layout.addStretch()
|
header_layout.addStretch()
|
||||||
@ -154,7 +190,7 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
#----------------- 5.3 Utility Methods -----------------
|
#----------------- 5.3 Utility Methods -----------------
|
||||||
def open_help_url(self):
|
def open_help_url(self):
|
||||||
webbrowser.open(data.TOOL_HELP_URL)
|
webbrowser.open(TOOL_HELP_URL)
|
||||||
QtWidgets.QApplication.restoreOverrideCursor()
|
QtWidgets.QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
def get_script_path():
|
def get_script_path():
|
||||||
@ -177,7 +213,7 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
msg_box = self.create_styled_message_box(
|
msg_box = self.create_styled_message_box(
|
||||||
"Confirm Installation",
|
"Confirm Installation",
|
||||||
f"Are you sure you want to install {data.TOOL_NAME}?"
|
f"Are you sure you want to install {TOOL_NAME}?"
|
||||||
)
|
)
|
||||||
if msg_box.exec_() == QtWidgets.QMessageBox.Yes:
|
if msg_box.exec_() == QtWidgets.QMessageBox.Yes:
|
||||||
try:
|
try:
|
||||||
@ -192,7 +228,7 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
"""Handle uninstall request"""
|
"""Handle uninstall request"""
|
||||||
msg_box = self.create_styled_message_box(
|
msg_box = self.create_styled_message_box(
|
||||||
"Confirm Uninstallation",
|
"Confirm Uninstallation",
|
||||||
f"Are you sure you want to uninstall {data.TOOL_NAME}?"
|
f"Are you sure you want to uninstall {TOOL_NAME}?"
|
||||||
)
|
)
|
||||||
|
|
||||||
if msg_box.exec_() == QtWidgets.QMessageBox.Yes:
|
if msg_box.exec_() == QtWidgets.QMessageBox.Yes:
|
||||||
@ -209,15 +245,15 @@ class InstallDialog(QtWidgets.QDialog):
|
|||||||
def create_mod_file(self):
|
def create_mod_file(self):
|
||||||
"""Create or update the .mod file for Maya"""
|
"""Create or update the .mod file for Maya"""
|
||||||
modules_dir = get_maya_modules_dir()
|
modules_dir = get_maya_modules_dir()
|
||||||
mod_content = f"""+ {data.TOOL_NAME} {data.TOOL_VERSION} {data.TOOL_PATH}
|
mod_content = f"""+ {TOOL_NAME} {TOOL_VERSION} {TOOL_PATH}
|
||||||
scripts: {data.SCRIPTS_PATH}
|
scripts: {SCRIPTS_PATH}
|
||||||
plug-ins: plugins/{data.SYSTEM_OS}/{data.MAYA_VERSION}
|
plug-ins: plugins/{SYSTEM_OS}/{MAYA_VERSION}
|
||||||
XBMLANGPATH+:=resources/icons
|
XBMLANGPATH+:=resources/icons
|
||||||
PYTHONPATH+:=plugins/{data.SYSTEM_OS}/{data.MAYA_VERSION}
|
PYTHONPATH+:=plugins/{SYSTEM_OS}/{MAYA_VERSION}
|
||||||
PYTHONPATH+:=plugins/{data.SYSTEM_OS}/{data.MAYA_VERSION}/pydna/{data.PYTHON_VERSION_DIR}
|
PYTHONPATH+:=plugins/{SYSTEM_OS}/{MAYA_VERSION}/pydna/{PYTHON_VERSION_DIR}
|
||||||
TOOL_PATH+:={data.TOOL_PATH}
|
TOOL_PATH+:={TOOL_PATH}
|
||||||
"""
|
"""
|
||||||
mod_file_path = os.path.join(modules_dir, data.TOOL_MOD_FILENAME)
|
mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME)
|
||||||
self._write_mod_file(mod_file_path, mod_content)
|
self._write_mod_file(mod_file_path, mod_content)
|
||||||
|
|
||||||
def _write_mod_file(self, file_path, content):
|
def _write_mod_file(self, file_path, content):
|
||||||
@ -233,37 +269,37 @@ TOOL_PATH+:={data.TOOL_PATH}
|
|||||||
|
|
||||||
def uninstall_mod_file(self):
|
def uninstall_mod_file(self):
|
||||||
modules_dir = get_maya_modules_dir()
|
modules_dir = get_maya_modules_dir()
|
||||||
mod_file_path = os.path.join(modules_dir, data.TOOL_MOD_FILENAME)
|
mod_file_path = os.path.join(modules_dir, TOOL_MOD_FILENAME)
|
||||||
if os.path.exists(mod_file_path):
|
if os.path.exists(mod_file_path):
|
||||||
try:
|
try:
|
||||||
os.remove(mod_file_path)
|
os.remove(mod_file_path)
|
||||||
print(f"{data.TOOL_NAME}.mod file deleted")
|
print(f"{TOOL_NAME}.mod file deleted")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error deleting {data.TOOL_NAME}.mod file: {e}")
|
print(f"Error deleting {TOOL_NAME}.mod file: {e}")
|
||||||
|
|
||||||
def clean_existing_buttons(self):
|
def clean_existing_buttons(self):
|
||||||
if cmds.shelfLayout(data.TOOL_NAME, exists=True):
|
if cmds.shelfLayout(TOOL_NAME, exists=True):
|
||||||
buttons = cmds.shelfLayout(data.TOOL_NAME, query=True, childArray=True) or []
|
buttons = cmds.shelfLayout(TOOL_NAME, query=True, childArray=True) or []
|
||||||
for btn in buttons:
|
for btn in buttons:
|
||||||
if cmds.shelfButton(btn, query=True, exists=True):
|
if cmds.shelfButton(btn, query=True, exists=True):
|
||||||
label = cmds.shelfButton(btn, query=True, label=True)
|
label = cmds.shelfButton(btn, query=True, label=True)
|
||||||
if label == data.TOOL_NAME:
|
if label == TOOL_NAME:
|
||||||
cmds.deleteUI(btn)
|
cmds.deleteUI(btn)
|
||||||
print(f"Deleted existing {data.TOOL_NAME} button: {btn}")
|
print(f"Deleted existing {TOOL_NAME} button: {btn}")
|
||||||
|
|
||||||
def install_tool(self):
|
def install_tool(self):
|
||||||
"""Install the tool to Maya"""
|
"""Install the tool to Maya"""
|
||||||
if not os.path.exists(data.SCRIPTS_PATH):
|
if not os.path.exists(SCRIPTS_PATH):
|
||||||
print(f"Error: Scripts path does not exist: {data.SCRIPTS_PATH}")
|
print(f"Error: Scripts path does not exist: {SCRIPTS_PATH}")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not os.path.exists(data.TOOL_MAIN_SCRIPT):
|
if not os.path.exists(TOOL_MAIN_SCRIPT):
|
||||||
print(f"Error: Main script file not found: {data.TOOL_MAIN_SCRIPT}")
|
print(f"Error: Main script file not found: {TOOL_MAIN_SCRIPT}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Add scripts path to Python path
|
# Add scripts path to Python path
|
||||||
if data.SCRIPTS_PATH not in sys.path:
|
if SCRIPTS_PATH not in sys.path:
|
||||||
sys.path.insert(0, data.SCRIPTS_PATH)
|
sys.path.insert(0, SCRIPTS_PATH)
|
||||||
|
|
||||||
# Create shelf and button
|
# Create shelf and button
|
||||||
self._create_shelf_button()
|
self._create_shelf_button()
|
||||||
@ -271,10 +307,10 @@ TOOL_PATH+:={data.TOOL_PATH}
|
|||||||
|
|
||||||
# Switch to the newly created shelf
|
# Switch to the newly created shelf
|
||||||
try:
|
try:
|
||||||
cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=data.TOOL_NAME)
|
cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=TOOL_NAME)
|
||||||
print(f"Switched to {data.TOOL_NAME} shelf")
|
print(f"Switched to {TOOL_NAME} shelf")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error switching to {data.TOOL_NAME} shelf: {e}")
|
print(f"Error switching to {TOOL_NAME} shelf: {e}")
|
||||||
|
|
||||||
self._show_install_success_message()
|
self._show_install_success_message()
|
||||||
|
|
||||||
@ -283,24 +319,24 @@ TOOL_PATH+:={data.TOOL_PATH}
|
|||||||
shelf_layout = mel.eval('$tmpVar=$gShelfTopLevel')
|
shelf_layout = mel.eval('$tmpVar=$gShelfTopLevel')
|
||||||
|
|
||||||
# Create shelf if not exists
|
# Create shelf if not exists
|
||||||
if not cmds.shelfLayout(data.TOOL_NAME, exists=True):
|
if not cmds.shelfLayout(TOOL_NAME, exists=True):
|
||||||
cmds.shelfLayout(data.TOOL_NAME, parent=shelf_layout)
|
cmds.shelfLayout(TOOL_NAME, parent=shelf_layout)
|
||||||
|
|
||||||
# Clean existing buttons
|
# Clean existing buttons
|
||||||
self.clean_existing_buttons()
|
self.clean_existing_buttons()
|
||||||
|
|
||||||
# Create new button
|
# Create new button
|
||||||
icon_path = data.TOOL_ICON if os.path.exists(data.TOOL_ICON) else data.TOOL_COMMAND_ICON
|
icon_path = TOOL_ICON if os.path.exists(TOOL_ICON) else TOOL_COMMAND_ICON
|
||||||
|
|
||||||
command = self._get_shelf_button_command()
|
command = self._get_shelf_button_command()
|
||||||
|
|
||||||
cmds.shelfButton(
|
cmds.shelfButton(
|
||||||
parent=data.TOOL_NAME,
|
parent=TOOL_NAME,
|
||||||
image1=icon_path,
|
image1=icon_path,
|
||||||
label=data.TOOL_NAME,
|
label=TOOL_NAME,
|
||||||
command=command,
|
command=command,
|
||||||
sourceType="python",
|
sourceType="python",
|
||||||
annotation=f"{data.TOOL_NAME} {data.TOOL_VERSION}",
|
annotation=f"{TOOL_NAME} {TOOL_VERSION}",
|
||||||
noDefaultPopup=True,
|
noDefaultPopup=True,
|
||||||
style="iconOnly"
|
style="iconOnly"
|
||||||
)
|
)
|
||||||
@ -310,10 +346,10 @@ TOOL_PATH+:={data.TOOL_PATH}
|
|||||||
return f"""
|
return f"""
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
TOOL_PATH = r'{data.TOOL_PATH}'
|
TOOL_PATH = r'{TOOL_PATH}'
|
||||||
if TOOL_PATH not in sys.path:
|
if TOOL_PATH not in sys.path:
|
||||||
sys.path.insert(0, TOOL_PATH)
|
sys.path.insert(0, TOOL_PATH)
|
||||||
SCRIPTS_PATH = r'{data.SCRIPTS_PATH}'
|
SCRIPTS_PATH = r'{SCRIPTS_PATH}'
|
||||||
if SCRIPTS_PATH not in sys.path:
|
if SCRIPTS_PATH not in sys.path:
|
||||||
sys.path.insert(0, SCRIPTS_PATH)
|
sys.path.insert(0, SCRIPTS_PATH)
|
||||||
os.chdir(SCRIPTS_PATH)
|
os.chdir(SCRIPTS_PATH)
|
||||||
@ -322,28 +358,28 @@ try:
|
|||||||
MetaFusion.show()
|
MetaFusion.show()
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print("Error importing MetaFusion:", str(e))
|
print("Error importing MetaFusion:", str(e))
|
||||||
print(f"Scripts path: {data.SCRIPTS_PATH}")
|
print(f"Scripts path: {SCRIPTS_PATH}")
|
||||||
print("sys.path:", sys.path)
|
print("sys.path:", sys.path)
|
||||||
print(f"Contents of Scripts folder: {os.listdir(data.SCRIPTS_PATH)}")
|
print(f"Contents of Scripts folder: {os.listdir(SCRIPTS_PATH)}")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def uninstall_tool(self):
|
def uninstall_tool(self):
|
||||||
"""Uninstall the tool from Maya"""
|
"""Uninstall the tool from Maya"""
|
||||||
window_name = f"{data.TOOL_NAME}Window"
|
window_name = f"{TOOL_NAME}Window"
|
||||||
dock_name = f"{data.TOOL_NAME}WindowDock"
|
dock_name = f"{TOOL_NAME}WindowDock"
|
||||||
shelf_file = f"shelf_{data.TOOL_NAME}.mel"
|
shelf_file = f"shelf_{TOOL_NAME}.mel"
|
||||||
|
|
||||||
if cmds.window(window_name, exists=True):
|
if cmds.window(window_name, exists=True):
|
||||||
try:
|
try:
|
||||||
cmds.deleteUI(window_name)
|
cmds.deleteUI(window_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error closing {data.TOOL_NAME} window: {e}")
|
print(f"Error closing {TOOL_NAME} window: {e}")
|
||||||
|
|
||||||
if cmds.dockControl(dock_name, exists=True):
|
if cmds.dockControl(dock_name, exists=True):
|
||||||
try:
|
try:
|
||||||
cmds.deleteUI(dock_name)
|
cmds.deleteUI(dock_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error closing docked {data.TOOL_NAME} window: {e}")
|
print(f"Error closing docked {TOOL_NAME} window: {e}")
|
||||||
|
|
||||||
self.uninstall_mod_file()
|
self.uninstall_mod_file()
|
||||||
|
|
||||||
@ -351,17 +387,17 @@ except ImportError as e:
|
|||||||
current_shelf = cmds.shelfTabLayout("ShelfLayout", query=True, selectTab=True)
|
current_shelf = cmds.shelfTabLayout("ShelfLayout", query=True, selectTab=True)
|
||||||
|
|
||||||
# Delete Shelves and Buttons
|
# Delete Shelves and Buttons
|
||||||
if cmds.shelfLayout(data.TOOL_NAME, exists=True):
|
if cmds.shelfLayout(TOOL_NAME, exists=True):
|
||||||
try:
|
try:
|
||||||
cmds.deleteUI(data.TOOL_NAME, layout=True)
|
cmds.deleteUI(TOOL_NAME, layout=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error deleting {data.TOOL_NAME} shelf: {e}")
|
print(f"Error deleting {TOOL_NAME} shelf: {e}")
|
||||||
|
|
||||||
self._clean_all_shelf_buttons()
|
self._clean_all_shelf_buttons()
|
||||||
|
|
||||||
# Remove from Python path
|
# Remove from Python path
|
||||||
if data.SCRIPTS_PATH in sys.path:
|
if SCRIPTS_PATH in sys.path:
|
||||||
sys.path.remove(data.SCRIPTS_PATH)
|
sys.path.remove(SCRIPTS_PATH)
|
||||||
|
|
||||||
# Deleting Shelf Files
|
# Deleting Shelf Files
|
||||||
shelf_path = os.path.join(
|
shelf_path = os.path.join(
|
||||||
@ -369,7 +405,7 @@ except ImportError as e:
|
|||||||
cmds.about(version=True),
|
cmds.about(version=True),
|
||||||
"prefs",
|
"prefs",
|
||||||
"shelves",
|
"shelves",
|
||||||
f"shelf_{data.TOOL_NAME}.mel"
|
f"shelf_{TOOL_NAME}.mel"
|
||||||
)
|
)
|
||||||
|
|
||||||
if os.path.exists(shelf_path):
|
if os.path.exists(shelf_path):
|
||||||
@ -379,7 +415,7 @@ except ImportError as e:
|
|||||||
print(f"Error deleting shelf file: {e}")
|
print(f"Error deleting shelf file: {e}")
|
||||||
|
|
||||||
# If the current tool shelf is a deleted tool shelf, switch to another tool shelf
|
# If the current tool shelf is a deleted tool shelf, switch to another tool shelf
|
||||||
if current_shelf == data.TOOL_NAME:
|
if current_shelf == TOOL_NAME:
|
||||||
shelves = cmds.shelfTabLayout("ShelfLayout", query=True, childArray=True)
|
shelves = cmds.shelfTabLayout("ShelfLayout", query=True, childArray=True)
|
||||||
if shelves and len(shelves) > 0:
|
if shelves and len(shelves) > 0:
|
||||||
cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=shelves[0])
|
cmds.shelfTabLayout("ShelfLayout", edit=True, selectTab=shelves[0])
|
||||||
@ -393,34 +429,34 @@ except ImportError as e:
|
|||||||
shelf_buttons = cmds.shelfLayout(shelf, query=True, childArray=True) or []
|
shelf_buttons = cmds.shelfLayout(shelf, query=True, childArray=True) or []
|
||||||
for btn in shelf_buttons:
|
for btn in shelf_buttons:
|
||||||
if cmds.shelfButton(btn, query=True, exists=True):
|
if cmds.shelfButton(btn, query=True, exists=True):
|
||||||
if cmds.shelfButton(btn, query=True, label=True) == data.TOOL_NAME:
|
if cmds.shelfButton(btn, query=True, label=True) == TOOL_NAME:
|
||||||
cmds.deleteUI(btn)
|
cmds.deleteUI(btn)
|
||||||
|
|
||||||
def _show_uninstall_success_message(self):
|
def _show_uninstall_success_message(self):
|
||||||
"""Show uninstallation success message"""
|
"""Show uninstallation success message"""
|
||||||
msg_box = QtWidgets.QMessageBox(self)
|
msg_box = QtWidgets.QMessageBox(self)
|
||||||
msg_box.setWindowTitle("Uninstallation Successful")
|
msg_box.setWindowTitle("Uninstallation Successful")
|
||||||
msg_box.setText(f"{data.TOOL_NAME} has been successfully uninstalled!")
|
msg_box.setText(f"{TOOL_NAME} has been successfully uninstalled!")
|
||||||
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
||||||
msg_box.setWindowIcon(QtGui.QIcon(data.TOOL_ICON))
|
msg_box.setWindowIcon(QtGui.QIcon(TOOL_ICON))
|
||||||
msg_box.setStyleSheet(self.styleSheet())
|
msg_box.setStyleSheet(self.styleSheet())
|
||||||
msg_box.exec_()
|
msg_box.exec_()
|
||||||
|
|
||||||
def _show_install_success_message(self):
|
def _show_install_success_message(self):
|
||||||
msg_box = QtWidgets.QMessageBox(self)
|
msg_box = QtWidgets.QMessageBox(self)
|
||||||
msg_box.setWindowTitle("Installation Successful")
|
msg_box.setWindowTitle("Installation Successful")
|
||||||
msg_box.setText(f"{data.TOOL_NAME} has been successfully installed!")
|
msg_box.setText(f"{TOOL_NAME} has been successfully installed!")
|
||||||
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
||||||
msg_box.setWindowIcon(QtGui.QIcon(data.TOOL_ICON))
|
msg_box.setWindowIcon(QtGui.QIcon(TOOL_ICON))
|
||||||
msg_box.setStyleSheet(self.styleSheet())
|
msg_box.setStyleSheet(self.styleSheet())
|
||||||
msg_box.exec_()
|
msg_box.exec_()
|
||||||
|
|
||||||
def _validate_paths(self):
|
def _validate_paths(self):
|
||||||
"""Validate all required paths exist"""
|
"""Validate all required paths exist"""
|
||||||
paths = {
|
paths = {
|
||||||
"Root": data.TOOL_PATH,
|
"Root": TOOL_PATH,
|
||||||
"Scripts": data.SCRIPTS_PATH,
|
"Scripts": SCRIPTS_PATH,
|
||||||
"Icons": data.ICONS_PATH
|
"Icons": ICONS_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, path in paths.items():
|
for name, path in paths.items():
|
||||||
@ -443,7 +479,7 @@ except ImportError as e:
|
|||||||
def _load_mel_shelf(self):
|
def _load_mel_shelf(self):
|
||||||
"""Load mel shelf file with error handling"""
|
"""Load mel shelf file with error handling"""
|
||||||
try:
|
try:
|
||||||
mel.eval(f'loadNewShelf "shelf_{data.TOOL_NAME}.mel"')
|
mel.eval(f'loadNewShelf "shelf_{TOOL_NAME}.mel"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"Error loading shelf file: {e}", error=True)
|
self._log(f"Error loading shelf file: {e}", error=True)
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ try:
|
|||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(f"无法导入dna模块: {e}")
|
print(f"无法导入dna模块: {e}")
|
||||||
print(f"PYDNA_PATH: {PYDNA_PATH}")
|
print(f"PYDNA_PATH: {PYDNA_PATH}")
|
||||||
print(f"sys.path: {sys.path}")
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# 现在导入其他模块
|
# 现在导入其他模块
|
||||||
|
@ -38,21 +38,21 @@ SYSTEM_OS = str("Windows" if cmds.about(os=True).lower().startswith("win") else
|
|||||||
MAYA_VERSION = str(int(cmds.about(version=True).split('.')[0]))
|
MAYA_VERSION = str(int(cmds.about(version=True).split('.')[0]))
|
||||||
|
|
||||||
# PYTHON_VERSION
|
# PYTHON_VERSION
|
||||||
PYTHON_VERSION = str(sys.version.replace(".", ""))
|
PYTHON_VERSION = str(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
|
||||||
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)
|
|
||||||
|
|
||||||
# 版本映射表
|
def get_python_version():
|
||||||
PYTHON_VERSION_MAP = {
|
"""获取Python版本目录名称"""
|
||||||
(3,): "python3", # 所有Python3主版本
|
version = sys.version_info
|
||||||
(3, 9): "python397", # 3.9.x → python397
|
if version.major == 3:
|
||||||
(3, 10): "python3108", # 3.10.x → python3108
|
if version.minor == 9 and version.micro == 7:
|
||||||
(3, 11): "python311" # 3.11.x → python311
|
return "python397"
|
||||||
}
|
elif version.minor == 10 and version.micro == 8:
|
||||||
|
return "python3108"
|
||||||
|
elif version.minor == 11:
|
||||||
|
return "python311"
|
||||||
|
return "python3"
|
||||||
|
|
||||||
# 获取Python版本目录
|
PYTHON_VERSION_DIR = get_python_version()
|
||||||
PYTHON_VERSION_DIR = str(PYTHON_VERSION_MAP.get(version_tuple, "python397"))
|
|
||||||
|
|
||||||
# PATHS
|
# PATHS
|
||||||
PLUGIN_PATH = str(os.path.join(TOOL_PATH, "plugins", SYSTEM_OS, MAYA_VERSION).replace("\\", "/"))
|
PLUGIN_PATH = str(os.path.join(TOOL_PATH, "plugins", SYSTEM_OS, MAYA_VERSION).replace("\\", "/"))
|
||||||
|
Loading…
Reference in New Issue
Block a user