This commit is contained in:
2025-05-08 00:39:41 +08:00
parent 1bc836fafa
commit 24acc2a6f1
17 changed files with 1464 additions and 1388 deletions

View File

@@ -41,6 +41,9 @@ TOOL_HEIGHT = config.TOOL_HEIGHT
from scripts.ui import localization
LANG = localization.LANG
# 添加全局变量记录当前语言
current_language = "zh_CN" # 默认使用中文
#========================================== FUNCTIONS ========================================
#========================================== DNA 功能 ========================================
@@ -348,4 +351,79 @@ def toolbar_temp_utils_function():
This function will be replaced with actual functionality in future updates
"""
print("Toolbar module initialized with placeholder function")
return True
return True
def toggle_language():
"""
切换界面语言
在英文和中文之间切换
"""
from scripts.ui import localization
import config
from ui.Qt import QtWidgets
# 使用localization模块来切换语言
new_language = localization.switch_language()
# 更新配置
config.TOOL_LANG = new_language
# 尝试更新已有窗口的语言,而不重启窗口
try:
# 查找主窗口
main_window = None
for widget in QtWidgets.QApplication.allWidgets():
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()
# 更新功能按钮文字
if hasattr(main_window, 'function_buttons'):
for key, button in main_window.function_buttons.items():
button.setText(localization.get_text(key))
print(f"语言已切换到: {new_language}")
return
except Exception as e:
print(f"动态更新语言失败,将重启窗口: {e}")
import traceback
traceback.print_exc()
# 如果动态更新失败,尝试关闭并重启窗口
try:
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()
except Exception as e:
print(f"切换语言时出错: {e}")
import traceback
traceback.print_exc()