This commit is contained in:
2025-05-08 23:57:22 +08:00
parent 24acc2a6f1
commit 7094a5886a
18 changed files with 442 additions and 583 deletions

View File

@@ -6,8 +6,8 @@ UI Utilities Module for Plugin
UI工具模块 - 提供UI相关的通用函数
"""
#========================================= IMPORT =========================================
from Qt import QtWidgets, QtCore, QtGui
from Qt.QtCompat import wrapInstance
from scripts.ui.Qt import QtWidgets, QtCore, QtGui
from scripts.ui.Qt.QtCompat import wrapInstance
from maya import OpenMayaUI as omui
import maya.cmds as cmds
import maya.mel as mel
@@ -47,16 +47,15 @@ TOOL_HEIGHT = config.TOOL_HEIGHT
#========================================= LOCATION =======================================
from scripts.ui import localization
LANG = localization.LANG
TEXT = localization.TEXT
#============================================ UI BASE ==========================================
class BaseUI(object):
class BaseUI(QtWidgets.QWidget):
"""
UI基类
所有UI面板的基类提供通用的UI功能
"""
def __init__(self):
"""初始化UI基类"""
def __init__(self, parent=None):
super().__init__(parent)
# 初始化字典
self.controls = {}
self.layouts = {}
@@ -64,7 +63,6 @@ class BaseUI(object):
self.splitters = {}
self.inputs = {}
self.labels = {}
# 创建主控件
self.main_widget = None
@@ -82,10 +80,23 @@ class BaseUI(object):
def update_language(self):
"""
新所有UI文本到当前语言
递归刷新所有UI控件文本,支持多语言切换
"""
if self.main_widget:
update_ui_texts(self.main_widget)
from scripts.ui import localization
# 批量刷新注册字典中的控件
for group in [self.controls, self.labels, self.buttons, getattr(self, 'inputs', {}), getattr(self, 'splitters', {})]:
for key, widget in group.items():
# QLabel/QPushButton/QCheckBox/QRadioButton等
if hasattr(widget, 'setText'):
widget.setText(TEXT(key, widget.text() if hasattr(widget, 'text') else ""))
# QLineEdit等
elif hasattr(widget, 'setPlaceholderText'):
widget.setPlaceholderText(TEXT(key, widget.placeholderText() if hasattr(widget, 'placeholderText') else ""))
# 递归刷新所有自定义子UI即BaseUI子类
for child in self.findChildren(QtWidgets.QWidget):
if child is not self and hasattr(child, 'update_language') and callable(child.update_language):
child.update_language()
#============================================ UI HELPERS ==========================================
def connect_ui_signals(ui_instance, signal_mapping):
@@ -268,7 +279,7 @@ def update_ui_texts(widget):
for lang in ["zh_CN", "en_US"]:
for key, text in localization.LANG.get(lang, {}).items():
if text == current_text:
widget.setText(localization.get_text(key, current_text))
widget.setText(TEXT(key, current_text))
break
# 更新按钮文本和工具提示
@@ -279,7 +290,7 @@ def update_ui_texts(widget):
for lang in ["zh_CN", "en_US"]:
for key, text in localization.LANG.get(lang, {}).items():
if text == current_text:
widget.setText(localization.get_text(key, current_text))
widget.setText(TEXT(key, current_text))
break
# 更新工具提示
@@ -288,7 +299,7 @@ def update_ui_texts(widget):
for lang in ["zh_CN", "en_US"]:
for key, text in localization.LANG.get(lang, {}).items():
if text == current_tip:
widget.setToolTip(localization.get_text(key, current_tip))
widget.setToolTip(TEXT(key, current_tip))
break
# 递归处理所有子控件