#!/usr/bin/env python # -*- coding: utf-8 -*- """ Toolbar UI Module for Plugin 工具栏UI模块 - 负责显示工具栏界面和基础操作 基本功能: - 加载预设 - 保存预设 - 导入DNA - 导出DNA - 创建RL4节点(用于切换DNA编辑的状态) - 删除RL4节点(用于切换DNA编辑的状态) """ #========================================= IMPORT ========================================= from Qt import QtWidgets, QtCore, QtGui from Qt.QtCompat import wrapInstance from maya import OpenMayaUI as omui import maya.cmds as cmds import maya.mel as mel import maya.utils as utils import webbrowser import subprocess import importlib import traceback import locale import sys import os from scripts.ui import ui_utils from scripts.utils import utils_toolbar #========================================== CONFIG ======================================== import config TOOL_NAME = config.TOOL_NAME TOOL_VERSION = config.TOOL_VERSION TOOL_AUTHOR = config.TOOL_AUTHOR TOOL_YEAR = config.TOOL_YEAR TOOL_MOD_FILENAME = config.TOOL_MOD_FILENAME TOOL_LANG = config.TOOL_LANG TOOL_WSCL_NAME = config.TOOL_WSCL_NAME TOOL_HELP_URL = config.TOOL_HELP_URL TOOL_PATH = config.TOOL_PATH SCRIPTS_PATH = config.SCRIPTS_PATH TOOL_MAIN_SCRIPT = config.TOOL_MAIN_SCRIPT UI_PATH = config.UI_PATH STYLE_FILE = config.STYLE_FILE ICONS_PATH = config.ICONS_PATH TOOL_ICON = config.TOOL_ICON ASSETS_PATH = config.ASSETS_PATH DNA_FILE_PATH = config.DNA_FILE_PATH DNA_IMG_PATH = config.DNA_IMG_PATH TOOL_COMMAND_ICON = config.TOOL_COMMAND_ICON #========================================= LOCATION ======================================= from scripts.ui import localization LANG = localization.LANG class ToolbarUI(ui_utils.BaseUI): """ 工具栏UI类 - 负责显示工具栏界面和基础操作 继承自BaseUI类,实现工具栏相关的UI功能 """ #========================================== INIT ======================================== def __init__(self): """ 初始化工具栏UI 创建主控件和布局,并连接信号和槽 """ super(ToolbarUI, self).__init__() # 创建主控件 self.main_widget = QtWidgets.QWidget() self.main_widget.setObjectName("toolbarMainWidget") # 初始化UI self.create_widgets() self.create_layouts() self.create_connections() #========================================= WIDGET ======================================= def create_widgets(self): """ 创建工具栏UI控件 包括按钮、标签、输入框等 """ # 创建顶部工具栏 self.controls["toolbar_frame"] = QtWidgets.QFrame() self.controls["toolbar_frame"].setObjectName("toolbarFrame") self.controls["toolbar_frame"].setFrameShape(QtWidgets.QFrame.StyledPanel) self.controls["toolbar_frame"].setFrameShadow(QtWidgets.QFrame.Raised) # 创建工具栏按钮 # 第一行按钮 self.buttons["new_file"] = self._create_tool_button("新建文件", ":/icons/new_file.png") self.buttons["open_file"] = self._create_tool_button("打开文件", ":/icons/open_file.png") self.buttons["link_file"] = self._create_tool_button("链接文件", ":/icons/link_file.png") self.buttons["unlink_file"] = self._create_tool_button("取消链接", ":/icons/unlink_file.png") self.buttons["import_file"] = self._create_tool_button("导入文件", ":/icons/import_file.png") self.buttons["export_file"] = self._create_tool_button("导出文件", ":/icons/export_file.png") self.buttons["save_file"] = self._create_tool_button("保存文件", ":/icons/save_file.png") self.buttons["user_info"] = self._create_tool_button("用户信息", ":/icons/user_info.png") self.buttons["help"] = self._create_tool_button("帮助", ":/icons/help.png") self.buttons["settings"] = self._create_tool_button("设置", ":/icons/settings.png") self.buttons["print"] = self._create_tool_button("打印", ":/icons/print.png") # 第二行按钮和下拉框 self.buttons["model_view"] = self._create_tool_button("模型视图", ":/icons/model_view.png", checkable=True) self.buttons["model_view"].setChecked(True) self.buttons["definition_view"] = self._create_tool_button("定义视图", ":/icons/definition_view.png", checkable=True) self.buttons["table_view"] = self._create_tool_button("表格视图", ":/icons/table_view.png", checkable=True) self.buttons["define_view"] = self._create_tool_button("自定义视图", ":/icons/define_view.png", checkable=True) # 下拉框 self.controls["model_combo"] = QtWidgets.QComboBox() self.controls["model_combo"].setObjectName("modelCombo") self.controls["model_combo"].addItem("MetaHuman") self.controls["model_combo"].setMinimumWidth(120) # 帮助按钮 self.buttons["help_button"] = QtWidgets.QPushButton() self.buttons["help_button"].setIcon(QtGui.QIcon(":/icons/question.png")) self.buttons["help_button"].setObjectName("helpButton") self.buttons["help_button"].setFixedSize(24, 24) self.buttons["help_button"].setToolTip(LANG.get("help_tooltip", "帮助")) def _create_tool_button(self, tooltip, icon_path, checkable=False): """ 创建工具栏按钮 """ button = QtWidgets.QPushButton() button.setToolTip(LANG.get(tooltip, tooltip)) # 尝试设置图标,如果图标文件不存在则使用文字 if os.path.exists(icon_path.replace(":/icons/", f"{ICONS_PATH}/")): button.setIcon(QtGui.QIcon(icon_path)) else: button.setText(LANG.get(tooltip, tooltip)) button.setObjectName(f"{tooltip.replace(' ', '_').lower()}_button") button.setFixedSize(32, 32) button.setCheckable(checkable) return button #========================================= LAYOUT ======================================= def create_layouts(self): """ 创建工具栏UI布局 组织控件的排列和层次结构 """ # 主布局 self.layouts["main_layout"] = QtWidgets.QVBoxLayout(self.main_widget) self.layouts["main_layout"].setContentsMargins(0, 0, 0, 0) self.layouts["main_layout"].setSpacing(0) # 添加工具栏框架 self.layouts["main_layout"].addWidget(self.controls["toolbar_frame"]) # 工具栏框架布局 self.layouts["toolbar_layout"] = QtWidgets.QVBoxLayout(self.controls["toolbar_frame"]) self.layouts["toolbar_layout"].setContentsMargins(5, 5, 5, 5) self.layouts["toolbar_layout"].setSpacing(2) # 第一行按钮布局 self.layouts["toolbar_row1"] = QtWidgets.QHBoxLayout() self.layouts["toolbar_row1"].setSpacing(2) self.layouts["toolbar_row1"].addWidget(self.buttons["new_file"]) self.layouts["toolbar_row1"].addWidget(self.buttons["open_file"]) self.layouts["toolbar_row1"].addWidget(self.buttons["link_file"]) self.layouts["toolbar_row1"].addWidget(self.buttons["unlink_file"]) self.layouts["toolbar_row1"].addWidget(self._create_separator()) self.layouts["toolbar_row1"].addWidget(self.buttons["import_file"]) self.layouts["toolbar_row1"].addWidget(self.buttons["export_file"]) self.layouts["toolbar_row1"].addWidget(self.buttons["save_file"]) self.layouts["toolbar_row1"].addWidget(self._create_separator()) self.layouts["toolbar_row1"].addWidget(self.buttons["user_info"]) self.layouts["toolbar_row1"].addWidget(self.buttons["help"]) self.layouts["toolbar_row1"].addWidget(self.buttons["settings"]) self.layouts["toolbar_row1"].addWidget(self.buttons["print"]) self.layouts["toolbar_row1"].addStretch() # 第二行按钮布局 self.layouts["toolbar_row2"] = QtWidgets.QHBoxLayout() self.layouts["toolbar_row2"].setSpacing(2) self.layouts["toolbar_row2"].addWidget(self.buttons["model_view"]) self.layouts["toolbar_row2"].addWidget(self.buttons["definition_view"]) self.layouts["toolbar_row2"].addWidget(self.buttons["table_view"]) self.layouts["toolbar_row2"].addWidget(self.buttons["define_view"]) self.layouts["toolbar_row2"].addWidget(self._create_separator()) self.layouts["toolbar_row2"].addWidget(self.controls["model_combo"]) self.layouts["toolbar_row2"].addStretch() self.layouts["toolbar_row2"].addWidget(self.buttons["help_button"]) # 添加行到工具栏布局 self.layouts["toolbar_layout"].addLayout(self.layouts["toolbar_row1"]) self.layouts["toolbar_layout"].addLayout(self.layouts["toolbar_row2"]) def _create_separator(self): """ 创建分隔线 """ separator = QtWidgets.QFrame() separator.setFrameShape(QtWidgets.QFrame.VLine) separator.setFrameShadow(QtWidgets.QFrame.Sunken) separator.setFixedWidth(2) separator.setFixedHeight(24) return separator #======================================= CONNECTION ===================================== def create_connections(self): """ 连接信号和槽 设置UI控件的交互行为 """ # 第一行按钮连接 self.buttons["new_file"].clicked.connect(utils_toolbar.new_file) self.buttons["open_file"].clicked.connect(utils_toolbar.open_file) self.buttons["link_file"].clicked.connect(utils_toolbar.link_file) self.buttons["unlink_file"].clicked.connect(utils_toolbar.unlink_file) self.buttons["import_file"].clicked.connect(utils_toolbar.import_file) self.buttons["export_file"].clicked.connect(utils_toolbar.export_file) self.buttons["save_file"].clicked.connect(utils_toolbar.save_file) self.buttons["user_info"].clicked.connect(utils_toolbar.show_user_info) self.buttons["help"].clicked.connect(utils_toolbar.show_help) self.buttons["settings"].clicked.connect(utils_toolbar.show_settings) self.buttons["print"].clicked.connect(utils_toolbar.print_file) # 第二行按钮连接 self.buttons["model_view"].clicked.connect(lambda: utils_toolbar.change_view("model")) self.buttons["definition_view"].clicked.connect(lambda: utils_toolbar.change_view("definition")) self.buttons["table_view"].clicked.connect(lambda: utils_toolbar.change_view("table")) self.buttons["define_view"].clicked.connect(lambda: utils_toolbar.change_view("define")) # 下拉框连接 self.controls["model_combo"].currentIndexChanged.connect(utils_toolbar.model_changed) # 帮助按钮连接 self.buttons["help_button"].clicked.connect(utils_toolbar.show_help)