Update
This commit is contained in:
@@ -12,185 +12,165 @@ Toolbar UI Module for Plugin
|
||||
- 创建RL4节点(用于切换DNA编辑的状态)
|
||||
- 删除RL4节点(用于切换DNA编辑的状态)
|
||||
"""
|
||||
|
||||
#===================================== IMPORT MODULES =====================================
|
||||
#========================================= 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
|
||||
|
||||
#===================================== IMPORT FUNCTIONS ===================================
|
||||
from scripts.utils import utils_toolbar as utils_toolbar
|
||||
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
|
||||
|
||||
#========================================== WIDGETS ==========================================
|
||||
# 全局变量存储UI控件
|
||||
toolbar_buttons = {}
|
||||
status_label = None
|
||||
|
||||
# 按钮图标和提示文本映射
|
||||
button_configs = {
|
||||
"open_file": {"icon": "open.png", "tooltip": "打开文件"},
|
||||
"save_file": {"icon": "save.png", "tooltip": "保存文件"},
|
||||
"save_as": {"icon": "save_new.png", "tooltip": "另存为"},
|
||||
"load_preset": {"icon": "import_preset.png", "tooltip": "加载预设"},
|
||||
"save_preset": {"icon": "export_preset.png", "tooltip": "导出预设"},
|
||||
"import_dna": {"icon": "import_dna.png", "tooltip": "导入DNA"},
|
||||
"export_dna": {"icon": "export_dna.png", "tooltip": "导出DNA"},
|
||||
"create_rl4": {"icon": "create_rl4_node.png", "tooltip": "创建RL4节点"},
|
||||
"delete_rl4": {"icon": "delete_rl4_node.png", "tooltip": "删除RL4节点"}
|
||||
}
|
||||
|
||||
def widgets():
|
||||
class ToolbarUI(ui_utils.BaseUI):
|
||||
"""
|
||||
创建工具栏UI控件
|
||||
工具栏UI类 - 负责显示工具栏界面和基础操作
|
||||
继承自BaseUI类,实现工具栏相关的UI功能
|
||||
"""
|
||||
global toolbar_buttons, status_label
|
||||
|
||||
# 创建按钮的辅助函数
|
||||
def create_icon_button(button_id, size=24):
|
||||
config = button_configs[button_id]
|
||||
button = QtWidgets.QPushButton()
|
||||
button.setToolTip(config["tooltip"]) # 设置提示文本
|
||||
button.setFixedSize(size, size) # 设置固定大小
|
||||
# 设置样式类名
|
||||
button.setObjectName("ToolbarIconButton")
|
||||
#========================================== INIT ========================================
|
||||
def __init__(self):
|
||||
"""
|
||||
初始化工具栏UI
|
||||
创建主控件和布局,并连接信号和槽
|
||||
"""
|
||||
super(ToolbarUI, self).__init__()
|
||||
|
||||
# 设置图标
|
||||
icon_path = os.path.abspath(os.path.join(ICONS_PATH, config["icon"]))
|
||||
if os.path.exists(icon_path):
|
||||
icon = QtGui.QIcon(icon_path)
|
||||
if not icon.isNull():
|
||||
button.setIcon(icon)
|
||||
button.setIconSize(QtCore.QSize(size-4, size-4)) # 图标尺寸稍小于按钮
|
||||
print(f"成功设置按钮图标 {button_id}: {icon_path}")
|
||||
else:
|
||||
print(f"图标加载失败 {button_id}: {icon_path}")
|
||||
else:
|
||||
print(f"警告: 图标文件未找到 {button_id}: {icon_path}")
|
||||
|
||||
return button
|
||||
|
||||
# 创建所有按钮
|
||||
# 文件操作按钮
|
||||
toolbar_buttons["open_file"] = create_icon_button("open_file")
|
||||
toolbar_buttons["save_file"] = create_icon_button("save_file")
|
||||
toolbar_buttons["save_as"] = create_icon_button("save_as")
|
||||
|
||||
# 预设操作按钮
|
||||
toolbar_buttons["load_preset"] = create_icon_button("load_preset")
|
||||
toolbar_buttons["save_preset"] = create_icon_button("save_preset")
|
||||
|
||||
# DNA操作按钮
|
||||
toolbar_buttons["import_dna"] = create_icon_button("import_dna")
|
||||
toolbar_buttons["export_dna"] = create_icon_button("export_dna")
|
||||
|
||||
# RL4节点操作按钮
|
||||
toolbar_buttons["create_rl4"] = create_icon_button("create_rl4")
|
||||
toolbar_buttons["delete_rl4"] = create_icon_button("delete_rl4")
|
||||
|
||||
# 移除DNA下拉菜单
|
||||
|
||||
# 状态标签
|
||||
status_label = QtWidgets.QLabel("就绪")
|
||||
status_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
||||
status_label.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||
status_label.setObjectName("StatusLabel")
|
||||
# status_label.setStyleSheet("""
|
||||
# QLabel {
|
||||
# color: #CCCCCC;
|
||||
# padding-right: 5px;
|
||||
# font-size: 9pt;
|
||||
# }
|
||||
# """)
|
||||
# 创建主控件
|
||||
self.main_widget = QtWidgets.QWidget()
|
||||
self.main_widget.setObjectName("toolbarMainWidget")
|
||||
|
||||
# 初始化UI
|
||||
self.create_widgets()
|
||||
self.create_layouts()
|
||||
self.create_connections()
|
||||
|
||||
#========================================== LAYOUTS ==========================================
|
||||
def layouts(parent_frame=None):
|
||||
"""
|
||||
创建工具栏UI布局
|
||||
|
||||
Args:
|
||||
parent_frame: 父容器控件,由Main.py传入
|
||||
"""
|
||||
# 获取父容器(在Main.py中创建的toolbar_frame)
|
||||
if not parent_frame:
|
||||
parent_frame = ui_utils.get_parent_widget("toolbar_frame")
|
||||
if not parent_frame:
|
||||
print("无法获取父容器,布局创建失败")
|
||||
return
|
||||
|
||||
# 创建主布局
|
||||
main_layout = parent_frame.layout()
|
||||
if not main_layout:
|
||||
print("父容器没有布局,布局创建失败")
|
||||
return
|
||||
|
||||
# 创建工具栏布局
|
||||
toolbar_layout = QtWidgets.QHBoxLayout()
|
||||
toolbar_layout.setContentsMargins(2, 2, 2, 2)
|
||||
toolbar_layout.setSpacing(2) # 减小按钮之间的间距
|
||||
toolbar_layout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint) # 设置布局约束为默认,允许自适应
|
||||
|
||||
# 创建分隔符样式
|
||||
def create_separator():
|
||||
separator = QtWidgets.QFrame()
|
||||
separator.setFrameShape(QtWidgets.QFrame.VLine)
|
||||
separator.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
separator.setObjectName("ToolbarSeparator")
|
||||
return separator
|
||||
|
||||
# 添加文件操作按钮
|
||||
toolbar_layout.addWidget(toolbar_buttons["open_file"])
|
||||
toolbar_layout.addWidget(toolbar_buttons["save_file"])
|
||||
toolbar_layout.addWidget(toolbar_buttons["save_as"])
|
||||
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
||||
|
||||
# 添加预设操作按钮
|
||||
toolbar_layout.addWidget(toolbar_buttons["load_preset"])
|
||||
toolbar_layout.addWidget(toolbar_buttons["save_preset"])
|
||||
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
||||
|
||||
# 添加DNA操作按钮
|
||||
toolbar_layout.addWidget(toolbar_buttons["import_dna"])
|
||||
toolbar_layout.addWidget(toolbar_buttons["export_dna"])
|
||||
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
||||
|
||||
# 添加RL4节点操作按钮
|
||||
toolbar_layout.addWidget(toolbar_buttons["create_rl4"])
|
||||
toolbar_layout.addWidget(toolbar_buttons["delete_rl4"])
|
||||
toolbar_layout.addStretch()
|
||||
toolbar_layout.addWidget(status_label)
|
||||
|
||||
# 添加到主布局
|
||||
main_layout.addLayout(toolbar_layout)
|
||||
#========================================= WIDGET =======================================
|
||||
def create_widgets(self):
|
||||
"""
|
||||
创建工具栏UI控件
|
||||
包括按钮、标签、输入框等
|
||||
"""
|
||||
# 标题标签
|
||||
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("toolbar_title", "工具栏"))
|
||||
self.controls["title_label"].setObjectName("toolbarTitleLabel")
|
||||
self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
|
||||
# 预设组
|
||||
self.controls["preset_group"] = QtWidgets.QGroupBox(LANG.get("preset_group", "预设"))
|
||||
self.controls["preset_group"].setObjectName("presetGroup")
|
||||
|
||||
# 预设标签和下拉框
|
||||
self.controls["preset_label"] = QtWidgets.QLabel(LANG.get("preset", "预设:"))
|
||||
self.controls["preset_combo"] = QtWidgets.QComboBox()
|
||||
self.controls["preset_combo"].setObjectName("presetCombo")
|
||||
|
||||
# 预设按钮
|
||||
self.buttons["load_preset"] = QtWidgets.QPushButton(LANG.get("load_preset", "加载预设"))
|
||||
self.buttons["save_preset"] = QtWidgets.QPushButton(LANG.get("save_preset", "保存预设"))
|
||||
|
||||
# DNA操作组
|
||||
self.controls["dna_group"] = QtWidgets.QGroupBox(LANG.get("dna_operations", "DNA操作"))
|
||||
self.controls["dna_group"].setObjectName("dnaGroup")
|
||||
|
||||
# DNA操作按钮
|
||||
self.buttons["import_dna"] = QtWidgets.QPushButton(LANG.get("import_dna", "导入DNA"))
|
||||
self.buttons["export_dna"] = QtWidgets.QPushButton(LANG.get("export_dna", "导出DNA"))
|
||||
self.buttons["create_rl4"] = QtWidgets.QPushButton(LANG.get("create_rl4", "创建RL4节点"))
|
||||
self.buttons["delete_rl4"] = QtWidgets.QPushButton(LANG.get("delete_rl4", "删除RL4节点"))
|
||||
|
||||
#========================================== CONNECTIONS ==========================================
|
||||
def connections():
|
||||
"""
|
||||
连接工具栏UI信号和槽
|
||||
"""
|
||||
# 文件操作按钮连接
|
||||
toolbar_buttons["open_file"].clicked.connect(lambda: print("打开文件功能待实现"))
|
||||
toolbar_buttons["save_file"].clicked.connect(lambda: print("保存文件功能待实现"))
|
||||
toolbar_buttons["save_as"].clicked.connect(lambda: print("另存为功能待实现"))
|
||||
|
||||
# 预设操作按钮连接
|
||||
toolbar_buttons["load_preset"].clicked.connect(lambda: print("加载预设功能待实现"))
|
||||
toolbar_buttons["save_preset"].clicked.connect(lambda: print("导出预设功能待实现"))
|
||||
|
||||
# DNA操作按钮连接
|
||||
toolbar_buttons["import_dna"].clicked.connect(lambda: print("导入DNA功能待实现"))
|
||||
toolbar_buttons["export_dna"].clicked.connect(lambda: print("导出DNA功能待实现"))
|
||||
|
||||
# RL4节点操作按钮连接
|
||||
toolbar_buttons["create_rl4"].clicked.connect(lambda: print("创建RL4节点功能待实现"))
|
||||
toolbar_buttons["delete_rl4"].clicked.connect(lambda: print("删除RL4节点功能待实现"))
|
||||
#========================================= LAYOUT =======================================
|
||||
def create_layouts(self):
|
||||
"""
|
||||
创建工具栏UI布局
|
||||
组织控件的排列和层次结构
|
||||
"""
|
||||
# 主布局
|
||||
self.layouts["main_layout"] = QtWidgets.QVBoxLayout(self.main_widget)
|
||||
self.layouts["main_layout"].setContentsMargins(5, 5, 5, 5)
|
||||
self.layouts["main_layout"].setSpacing(5)
|
||||
|
||||
# 添加标题标签
|
||||
self.layouts["main_layout"].addWidget(self.controls["title_label"])
|
||||
|
||||
# 预设组布局
|
||||
self.layouts["preset_layout"] = QtWidgets.QVBoxLayout(self.controls["preset_group"])
|
||||
|
||||
# 预设选择布局
|
||||
self.layouts["preset_select_layout"] = QtWidgets.QHBoxLayout()
|
||||
self.layouts["preset_select_layout"].addWidget(self.controls["preset_label"])
|
||||
self.layouts["preset_select_layout"].addWidget(self.controls["preset_combo"])
|
||||
|
||||
# 预设按钮布局
|
||||
self.layouts["preset_buttons_layout"] = QtWidgets.QHBoxLayout()
|
||||
self.layouts["preset_buttons_layout"].addWidget(self.buttons["load_preset"])
|
||||
self.layouts["preset_buttons_layout"].addWidget(self.buttons["save_preset"])
|
||||
|
||||
# 添加到预设组布局
|
||||
self.layouts["preset_layout"].addLayout(self.layouts["preset_select_layout"])
|
||||
self.layouts["preset_layout"].addLayout(self.layouts["preset_buttons_layout"])
|
||||
|
||||
# DNA操作组布局
|
||||
self.layouts["dna_layout"] = QtWidgets.QVBoxLayout(self.controls["dna_group"])
|
||||
|
||||
# DNA操作按钮布局
|
||||
self.layouts["dna_buttons_layout"] = QtWidgets.QGridLayout()
|
||||
self.layouts["dna_buttons_layout"].addWidget(self.buttons["import_dna"], 0, 0)
|
||||
self.layouts["dna_buttons_layout"].addWidget(self.buttons["export_dna"], 0, 1)
|
||||
self.layouts["dna_buttons_layout"].addWidget(self.buttons["create_rl4"], 1, 0)
|
||||
self.layouts["dna_buttons_layout"].addWidget(self.buttons["delete_rl4"], 1, 1)
|
||||
|
||||
# 添加到DNA操作组布局
|
||||
self.layouts["dna_layout"].addLayout(self.layouts["dna_buttons_layout"])
|
||||
|
||||
# 添加组到主布局
|
||||
self.layouts["main_layout"].addWidget(self.controls["preset_group"])
|
||||
self.layouts["main_layout"].addWidget(self.controls["dna_group"])
|
||||
self.layouts["main_layout"].addStretch()
|
||||
|
||||
#===================================== PLACEHOLDER FUNCTION ===================================
|
||||
def toolbar_temp_function():
|
||||
return utils_toolbar.toolbar_temp_utils_function()
|
||||
#======================================= CONNECTION =====================================
|
||||
def create_connections(self):
|
||||
"""
|
||||
连接信号和槽
|
||||
设置UI控件的交互行为
|
||||
"""
|
||||
# 预设按钮连接
|
||||
self.buttons["load_preset"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
self.buttons["save_preset"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
|
||||
# DNA操作按钮连接
|
||||
self.buttons["import_dna"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
self.buttons["export_dna"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
self.buttons["create_rl4"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
self.buttons["delete_rl4"].clicked.connect(utils_toolbar.toolbar_temp_utils_function)
|
||||
|
Reference in New Issue
Block a user