Update
This commit is contained in:
@@ -39,10 +39,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
|
||||
TOOL_HEIGHT = config.TOOL_HEIGHT
|
||||
# Localization
|
||||
from scripts.ui import localization
|
||||
LANG = localization.LANG
|
||||
|
||||
# 添加全局变量记录当前语言
|
||||
current_language = "zh_CN" # 默认使用中文
|
||||
TEXT = localization.TEXT
|
||||
|
||||
#========================================== FUNCTIONS ========================================
|
||||
|
||||
@@ -57,7 +54,7 @@ def save_dna():
|
||||
fileFilter="DNA Files (*.dna);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=0,
|
||||
caption=LANG.get("save_dna", "保存DNA文件")
|
||||
caption=TEXT("save_dna", "保存DNA文件")
|
||||
)
|
||||
|
||||
if file_path and len(file_path) > 0:
|
||||
@@ -77,7 +74,7 @@ def open_dna():
|
||||
fileFilter="DNA Files (*.dna);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1,
|
||||
caption=LANG.get("open_dna", "打开DNA文件")
|
||||
caption=TEXT("open_dna", "打开DNA文件")
|
||||
)
|
||||
|
||||
if file_path and len(file_path) > 0:
|
||||
@@ -123,7 +120,7 @@ def import_skin():
|
||||
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1,
|
||||
caption=LANG.get("import_skin", "导入蒙皮")
|
||||
caption=TEXT("import_skin", "导入蒙皮")
|
||||
)
|
||||
|
||||
if file_path and len(file_path) > 0:
|
||||
@@ -143,7 +140,7 @@ def export_skin():
|
||||
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=0,
|
||||
caption=LANG.get("export_skin", "导出蒙皮")
|
||||
caption=TEXT("export_skin", "导出蒙皮")
|
||||
)
|
||||
|
||||
if file_path and len(file_path) > 0:
|
||||
@@ -174,8 +171,8 @@ def show_help():
|
||||
try:
|
||||
# 打开帮助文档或显示帮助对话框
|
||||
help_dialog = QtWidgets.QMessageBox()
|
||||
help_dialog.setWindowTitle(LANG.get("help_title", "帮助"))
|
||||
help_dialog.setText(LANG.get("help_message", "该插件是一个用于自定义MetaHuman的Maya插件。\n\n详细信息请参考文档。"))
|
||||
help_dialog.setWindowTitle(TEXT("help_title", "帮助"))
|
||||
help_dialog.setText(TEXT("help_message", "该插件是一个用于自定义MetaHuman的Maya插件。\n\n详细信息请参考文档。"))
|
||||
help_dialog.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
||||
help_dialog.exec_()
|
||||
except Exception as e:
|
||||
@@ -302,10 +299,10 @@ def show_help():
|
||||
webbrowser.open(config.TOOL_HELP_URL)
|
||||
else:
|
||||
cmds.confirmDialog(
|
||||
title=LANG.get("help", "帮助"),
|
||||
message=LANG.get("help_not_available", "帮助文档暂不可用"),
|
||||
button=[LANG.get("ok", "确定")],
|
||||
defaultButton=LANG.get("ok", "确定")
|
||||
title=TEXT("help", "帮助"),
|
||||
message=TEXT("help_not_available", "帮助文档暂不可用"),
|
||||
button=[TEXT("ok", "确定")],
|
||||
defaultButton=TEXT("ok", "确定")
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"显示帮助信息时出错: {e}")
|
||||
@@ -360,15 +357,12 @@ def toggle_language():
|
||||
"""
|
||||
from scripts.ui import localization
|
||||
import config
|
||||
from ui.Qt import QtWidgets
|
||||
|
||||
from scripts.ui.Qt import QtWidgets
|
||||
|
||||
# 使用localization模块来切换语言
|
||||
new_language = localization.switch_language()
|
||||
|
||||
# 更新配置
|
||||
config.TOOL_LANG = new_language
|
||||
|
||||
# 尝试更新已有窗口的语言,而不重启窗口
|
||||
|
||||
try:
|
||||
# 查找主窗口
|
||||
main_window = None
|
||||
@@ -376,37 +370,33 @@ def toggle_language():
|
||||
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
|
||||
main_window = widget
|
||||
break
|
||||
|
||||
|
||||
if main_window:
|
||||
# 更新主窗口标题
|
||||
main_window.setWindowTitle(f"{config.TOOL_NAME} {config.TOOL_VERSION}")
|
||||
|
||||
# 获取各个UI实例并更新语言
|
||||
from scripts.ui import geometry, rigging, behaviour, definition, toolbar
|
||||
|
||||
# 更新各个模块的UI
|
||||
if hasattr(geometry, 'GeometryUI') and geometry.GeometryUI.get_instance():
|
||||
geometry.GeometryUI.get_instance().update_language()
|
||||
|
||||
if hasattr(rigging, 'RiggingUI') and rigging.RiggingUI.get_instance():
|
||||
rigging.RiggingUI.get_instance().update_language()
|
||||
|
||||
if hasattr(behaviour, 'BehaviourUI') and behaviour.BehaviourUI.get_instance():
|
||||
behaviour.BehaviourUI.get_instance().update_language()
|
||||
|
||||
if hasattr(definition, 'DefinitionUI') and definition.DefinitionUI.get_instance():
|
||||
definition.DefinitionUI.get_instance().update_language()
|
||||
|
||||
# 更新工具栏
|
||||
if hasattr(toolbar, 'ToolbarUI') and hasattr(main_window, 'toolbar_ui'):
|
||||
main_window.toolbar_ui.update_language()
|
||||
|
||||
# 遍历主窗口的所有子控件,批量动态更新语言
|
||||
for child in main_window.findChildren(QtWidgets.QWidget):
|
||||
# 只要有update_language方法就调用
|
||||
if hasattr(child, 'update_language') and callable(child.update_language):
|
||||
try:
|
||||
child.update_language()
|
||||
except Exception as e:
|
||||
print(f"更新语言失败: {child}: {e}")
|
||||
|
||||
# 更新功能按钮文字
|
||||
if hasattr(main_window, 'function_buttons'):
|
||||
for key, button in main_window.function_buttons.items():
|
||||
button.setText(localization.get_text(key))
|
||||
button.setText(localization.TEXT(key))
|
||||
|
||||
print(f"语言已切换到: {new_language}")
|
||||
|
||||
# 切换语言后强制重载主窗口,保证所有UI和控件100%刷新
|
||||
from scripts.Main import main
|
||||
for widget in QtWidgets.QApplication.allWidgets():
|
||||
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
|
||||
widget.close()
|
||||
main()
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"动态更新语言失败,将重启窗口: {e}")
|
||||
|
Reference in New Issue
Block a user