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

@@ -32,6 +32,7 @@ from scripts.ui import definition
#========================================= LOCALIZATION =====================================
from scripts.ui import localization
LANG = localization.LANG
get_text = localization.get_text
#=========================================== CONFIG =========================================
import config
TOOL_NAME = config.TOOL_NAME
@@ -68,9 +69,6 @@ class MainWindow(QtWidgets.QWidget):
# 设置窗口为独立窗口
self.setWindowFlags(QtCore.Qt.Window)
# 设置窗口位置为屏幕中央
self.center_window()
# 设置窗口图标
if os.path.exists(TOOL_ICON):
self.setWindowIcon(QtGui.QIcon(TOOL_ICON))
@@ -109,14 +107,18 @@ class MainWindow(QtWidgets.QWidget):
# 创建工具栏区域
self.toolbar_widget = QtWidgets.QWidget()
self.toolbar_widget.setObjectName("toolbarWidget")
self.toolbar_widget.setMaximumHeight(80) # 限制工具栏高度
self.toolbar_widget.setMaximumHeight(80)
# 创建功能区域切换按钮组
self.function_buttons = {}
self.function_buttons["geometry"] = QtWidgets.QPushButton(LANG.get("geometry", "几何体"))
self.function_buttons["rigging"] = QtWidgets.QPushButton(LANG.get("rigging", "绑定"))
self.function_buttons["behaviour"] = QtWidgets.QPushButton(LANG.get("behaviour", "行为"))
self.function_buttons["definition"] = QtWidgets.QPushButton(LANG.get("definition", "定义"))
self.function_buttons["geometry"] = QtWidgets.QPushButton(get_text("geometry", "几何体"))
self.function_buttons["geometry"].setIcon(ui_utils.load_icon("meshes.png"))
self.function_buttons["rigging"] = QtWidgets.QPushButton(get_text("rigging", "绑定"))
self.function_buttons["rigging"].setIcon(ui_utils.load_icon("configuration.png"))
self.function_buttons["behaviour"] = QtWidgets.QPushButton(get_text("behaviour", "行为"))
self.function_buttons["behaviour"].setIcon(ui_utils.load_icon("behaviour.png"))
self.function_buttons["definition"] = QtWidgets.QPushButton(get_text("definition", "定义"))
self.function_buttons["definition"].setIcon(ui_utils.load_icon("definition.png"))
# 设置按钮样式和属性
for key, button in self.function_buttons.items():
@@ -223,65 +225,19 @@ class MainWindow(QtWidgets.QWidget):
# 更新按钮状态
for i, (key, button) in enumerate(self.function_buttons.items()):
button.setChecked(i == index)
# 调整分割器宽度
self.reset_splitters()
# 打印当前面板信息
panel_names = ["几何体", "绑定", "行为", "定义"]
print(f"切换到功能面板: {panel_names[index]}")
def reset_splitters(self):
"""重置所有分割器的宽度,确保左右栏宽度均等"""
# 重置定义面板分割器
if hasattr(self.definition_ui, 'reset_splitter_sizes'):
self.definition_ui.reset_splitter_sizes()
# 重置行为面板分割器
if hasattr(self.behaviour_ui, 'reset_splitter_sizes'):
self.behaviour_ui.reset_splitter_sizes()
# 重置绑定面板分割器
if hasattr(self.rigging_ui, 'reset_splitter_sizes'):
self.rigging_ui.reset_splitter_sizes()
# 重置几何面板分割器
if hasattr(self.geometry_ui, 'reset_splitter_sizes'):
self.geometry_ui.reset_splitter_sizes()
def center_window(self):
"""将窗口居中显示在屏幕上"""
# 获取屏幕几何信息 - 兼容PySide2和PySide6
try:
# 使用Qt.py兼容层方式获取屏幕信息
app = QtWidgets.QApplication.instance()
screen = app.primaryScreen() if hasattr(app, 'primaryScreen') else None
if screen:
screen_rect = screen.availableGeometry()
else:
# 尝试使用desktop方法PySide2兼容
if hasattr(QtWidgets.QApplication, 'desktop'):
desktop = QtWidgets.QApplication.desktop()
screen_rect = desktop.availableGeometry(desktop.primaryScreen())
else:
# 如果都失败,使用默认值
screen_rect = QtCore.QRect(0, 0, 1920, 1080)
except Exception as e:
print(f"获取屏幕信息时出错: {str(e)}")
# 使用默认值
screen_rect = QtCore.QRect(0, 0, 1920, 1080)
# 计算窗口居中位置
window_rect = self.frameGeometry()
center_point = screen_rect.center()
window_rect.moveCenter(center_point)
# 移动窗口到居中位置
self.move(window_rect.topLeft())
def main():
"""主函数,创建并显示主窗口"""
try:
# 应用当前语言设置
from scripts.ui import localization
config.TOOL_LANG = localization.get_current_language()
# 如果已存在窗口,则关闭
for widget in QtWidgets.QApplication.allWidgets():
if widget.objectName() == f"{TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):