This commit is contained in:
2025-05-05 21:32:48 +08:00
parent 2278302ac1
commit e28ad4340f
5 changed files with 141 additions and 68 deletions

View File

@@ -63,6 +63,12 @@ class MainWindow(QtWidgets.QWidget):
self.setStyleSheet("") self.setStyleSheet("")
self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
# 设置窗口为独立窗口
self.setWindowFlags(QtCore.Qt.Window)
# 设置窗口位置为屏幕中央
self.center_window()
# 设置窗口图标 # 设置窗口图标
if os.path.exists(TOOL_ICON): if os.path.exists(TOOL_ICON):
self.setWindowIcon(QtGui.QIcon(TOOL_ICON)) self.setWindowIcon(QtGui.QIcon(TOOL_ICON))
@@ -98,50 +104,90 @@ class MainWindow(QtWidgets.QWidget):
#========================================= WIDGET ======================================= #========================================= WIDGET =======================================
def create_widgets(self): def create_widgets(self):
"""创建UI控件""" """创建UI控件"""
# 主标签页控件 # 创建工具栏区域
self.main_tab_widget = QtWidgets.QTabWidget() self.toolbar_widget = QtWidgets.QWidget()
self.main_tab_widget.setObjectName("mainTabWidget") self.toolbar_widget.setObjectName("toolbarWidget")
self.toolbar_widget.setMaximumHeight(80) # 限制工具栏高度
# 创建各个标签页 # 创建功能区域切换按钮组
self.toolbar_tab = QtWidgets.QWidget() self.function_buttons = {}
self.definition_tab = QtWidgets.QWidget() self.function_buttons["geometry"] = QtWidgets.QPushButton(LANG.get("geometry", "几何体"))
self.geometry_tab = QtWidgets.QWidget() self.function_buttons["rigging"] = QtWidgets.QPushButton(LANG.get("rigging", "绑定"))
self.rigging_tab = QtWidgets.QWidget() self.function_buttons["behaviour"] = QtWidgets.QPushButton(LANG.get("behaviour", "行为"))
self.behaviour_tab = QtWidgets.QWidget() self.function_buttons["definition"] = QtWidgets.QPushButton(LANG.get("definition", "定义"))
# 设置标签页名称 # 设置按钮样式和属性
self.main_tab_widget.addTab(self.toolbar_tab, LANG.get("toolbar", "工具栏")) for key, button in self.function_buttons.items():
self.main_tab_widget.addTab(self.definition_tab, LANG.get("definition", "定义")) button.setObjectName(f"{key}Button")
self.main_tab_widget.addTab(self.geometry_tab, LANG.get("geometry", "几何体")) button.setCheckable(True)
self.main_tab_widget.addTab(self.rigging_tab, LANG.get("rigging", "绑定")) button.setMinimumHeight(40)
self.main_tab_widget.addTab(self.behaviour_tab, LANG.get("behaviour", "行为"))
# 默认选中几何体按钮
self.function_buttons["geometry"].setChecked(True)
# 创建功能面板堆栈
self.function_stack = QtWidgets.QStackedWidget()
self.function_stack.setObjectName("functionStack")
# 创建各个功能面板
self.geometry_panel = QtWidgets.QWidget()
self.rigging_panel = QtWidgets.QWidget()
self.behaviour_panel = QtWidgets.QWidget()
self.definition_panel = QtWidgets.QWidget()
# 将功能面板添加到堆栈中
self.function_stack.addWidget(self.geometry_panel)
self.function_stack.addWidget(self.rigging_panel)
self.function_stack.addWidget(self.behaviour_panel)
self.function_stack.addWidget(self.definition_panel)
#========================================= LAYOUT ======================================= #========================================= LAYOUT =======================================
def create_layouts(self): def create_layouts(self):
"""创建布局""" """创建布局"""
# 主布局 # 主布局
main_layout = QtWidgets.QVBoxLayout(self) main_layout = QtWidgets.QVBoxLayout(self)
main_layout.setContentsMargins(5, 5, 5, 5) main_layout.setContentsMargins(2, 2, 2, 2)
main_layout.setSpacing(5) main_layout.setSpacing(2)
main_layout.addWidget(self.main_tab_widget)
# 设置各标签页的布局 # 创建工具栏布局
toolbar_layout = QtWidgets.QVBoxLayout(self.toolbar_tab) toolbar_layout = QtWidgets.QHBoxLayout(self.toolbar_widget)
definition_layout = QtWidgets.QVBoxLayout(self.definition_tab) toolbar_layout.setContentsMargins(5, 5, 5, 5)
geometry_layout = QtWidgets.QVBoxLayout(self.geometry_tab) toolbar_layout.setSpacing(5)
rigging_layout = QtWidgets.QVBoxLayout(self.rigging_tab)
behaviour_layout = QtWidgets.QVBoxLayout(self.behaviour_tab)
# 将各UI模块添加到对应的标签页布局 # 将工具栏UI添加到工具栏布局
# 工具栏UI
if hasattr(self.toolbar_ui, 'main_widget'): if hasattr(self.toolbar_ui, 'main_widget'):
toolbar_layout.addWidget(self.toolbar_ui.main_widget) toolbar_layout.addWidget(self.toolbar_ui.main_widget)
# 定义UI # 创建功能按钮布局
function_buttons_layout = QtWidgets.QHBoxLayout()
function_buttons_layout.setContentsMargins(0, 0, 0, 0)
function_buttons_layout.setSpacing(2)
# 添加功能按钮
for key, button in self.function_buttons.items():
function_buttons_layout.addWidget(button)
# 创建各功能面板的布局
definition_layout = QtWidgets.QVBoxLayout(self.definition_panel)
definition_layout.setContentsMargins(0, 0, 0, 0)
definition_layout.setSpacing(0)
geometry_layout = QtWidgets.QVBoxLayout(self.geometry_panel)
geometry_layout.setContentsMargins(0, 0, 0, 0)
geometry_layout.setSpacing(0)
rigging_layout = QtWidgets.QVBoxLayout(self.rigging_panel)
rigging_layout.setContentsMargins(0, 0, 0, 0)
rigging_layout.setSpacing(0)
behaviour_layout = QtWidgets.QVBoxLayout(self.behaviour_panel)
behaviour_layout.setContentsMargins(0, 0, 0, 0)
behaviour_layout.setSpacing(0)
# 将各UI模块添加到对应的功能面板布局中
if hasattr(self.definition_ui, 'main_widget'): if hasattr(self.definition_ui, 'main_widget'):
definition_layout.addWidget(self.definition_ui.main_widget) definition_layout.addWidget(self.definition_ui.main_widget)
# 几何体UI
if hasattr(self.geometry_ui, 'main_widget'): if hasattr(self.geometry_ui, 'main_widget'):
geometry_layout.addWidget(self.geometry_ui.main_widget) geometry_layout.addWidget(self.geometry_ui.main_widget)
@@ -153,48 +199,67 @@ class MainWindow(QtWidgets.QWidget):
if hasattr(self.behaviour_ui, 'main_widget'): if hasattr(self.behaviour_ui, 'main_widget'):
behaviour_layout.addWidget(self.behaviour_ui.main_widget) behaviour_layout.addWidget(self.behaviour_ui.main_widget)
# 将各组件添加到主布局
main_layout.addWidget(self.toolbar_widget)
main_layout.addLayout(function_buttons_layout)
main_layout.addWidget(self.function_stack, 1) # 给功能面板堆栈设置伸缩因子,使其占据剩余空间
#======================================= CONNECTION ===================================== #======================================= CONNECTION =====================================
def create_connections(self): def create_connections(self):
"""连接信号和槽""" """连接信号和槽"""
# 标签页切换信号 # 功能按钮点击信号
self.main_tab_widget.currentChanged.connect(self.tab_changed) self.function_buttons["definition"].clicked.connect(lambda: self.switch_function_panel(0))
self.function_buttons["geometry"].clicked.connect(lambda: self.switch_function_panel(1))
self.function_buttons["rigging"].clicked.connect(lambda: self.switch_function_panel(2))
self.function_buttons["behaviour"].clicked.connect(lambda: self.switch_function_panel(3))
def tab_changed(self, index): def switch_function_panel(self, index):
"""标签页切换事件处理""" """切换功能面板"""
tab_name = self.main_tab_widget.tabText(index) # 切换堆栈页面
print(f"切换到标签页: {tab_name}") self.function_stack.setCurrentIndex(index)
# 更新按钮状态
for i, (key, button) in enumerate(self.function_buttons.items()):
button.setChecked(i == index)
# 调整分割器宽度 # 调整分割器宽度
self.reset_splitters() self.reset_splitters()
# 打印当前面板信息
panel_names = ["几何体", "绑定", "行为", "定义"]
print(f"切换到功能面板: {panel_names[index]}")
def reset_splitters(self): def reset_splitters(self):
"""重置所有分割器的宽度,确保左右栏宽度均等""" """重置所有分割器的宽度,确保左右栏宽度均等"""
# 延迟执行确保UI完全加载 # 重置定义面板分割器
QtCore.QTimer.singleShot(50, self._do_reset_splitters) if hasattr(self.definition_ui, 'reset_splitter_sizes'):
QtCore.QTimer.singleShot(200, self._do_reset_splitters) self.definition_ui.reset_splitter_sizes()
def _do_reset_splitters(self): # 重置行为面板分割器
"""实际执行分割器宽度重置的函数""" if hasattr(self.behaviour_ui, 'reset_splitter_sizes'):
current_tab = self.main_tab_widget.currentWidget() self.behaviour_ui.reset_splitter_sizes()
if not current_tab:
return
# 查找当前标签页中的所有水平分割器 # 重置绑定面板分割器
splitters = current_tab.findChildren(QtWidgets.QSplitter) if hasattr(self.rigging_ui, 'reset_splitter_sizes'):
for splitter in splitters: self.rigging_ui.reset_splitter_sizes()
if splitter.orientation() == QtCore.Qt.Horizontal:
# 获取分割器宽度 # 重置几何面板分割器
width = splitter.width() if hasattr(self.geometry_ui, 'reset_splitter_sizes'):
# 计算每个部分应该的宽度 self.geometry_ui.reset_splitter_sizes()
count = splitter.count()
if count > 0: def center_window(self):
part_width = width // count """将窗口居中显示在屏幕上"""
sizes = [part_width] * count # 获取屏幕几何信息
# 设置分割器各部分的宽度 desktop = QtWidgets.QApplication.desktop()
splitter.setSizes(sizes) screen_rect = desktop.availableGeometry(desktop.primaryScreen())
# 为每个子项设置相同的伸缩因子
for i in range(count): # 计算窗口居中位置
splitter.setStretchFactor(i, 1) window_rect = self.frameGeometry()
center_point = screen_rect.center()
window_rect.moveCenter(center_point)
# 移动窗口到居中位置
self.move(window_rect.topLeft())
def main(): def main():
"""主函数,创建并显示主窗口""" """主函数,创建并显示主窗口"""

View File

@@ -85,10 +85,12 @@ class BehaviourUI(ui_utils.BaseUI):
创建行为系统UI控件 创建行为系统UI控件
包括按钮、标签、列表等 包括按钮、标签、列表等
""" """
# 标题标签 # 标题标签 - 使用HTML格式化标题
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("behaviour_title", "行为")) title_text = f"<h3 style='margin:0;padding:5px;'>{LANG.get('behaviour_title', '行为')}</h4>"
self.controls["title_label"] = QtWidgets.QLabel(title_text)
self.controls["title_label"].setObjectName("behaviourTitleLabel") self.controls["title_label"].setObjectName("behaviourTitleLabel")
self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter) self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter)
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
# 左侧面板 # 左侧面板
self.controls["left_panel"] = QtWidgets.QWidget() self.controls["left_panel"] = QtWidgets.QWidget()
@@ -254,7 +256,7 @@ class BehaviourUI(ui_utils.BaseUI):
安排控件的位置和尺寸 安排控件的位置和尺寸
""" """
# 主布局 # 主布局
self.layouts["main_layout"] = QtWidgets.QVBoxLayout(self) self.layouts["main_layout"] = QtWidgets.QVBoxLayout(self.main_widget)
self.layouts["main_layout"].setContentsMargins(2, 2, 2, 2) self.layouts["main_layout"].setContentsMargins(2, 2, 2, 2)
self.layouts["main_layout"].setSpacing(2) self.layouts["main_layout"].setSpacing(2)

View File

@@ -79,10 +79,12 @@ class DefinitionUI(ui_utils.BaseUI):
创建定义系统UI控件 创建定义系统UI控件
包括按钮、标签、列表等 包括按钮、标签、列表等
""" """
# 标题标签 # 标题标签 - 使用HTML格式化标题
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("definition_title", "DNA定义")) title_text = f"<h3 style='margin:0;padding:5px;'>{LANG.get('definition_title', 'DNA定义')}</h4>"
self.controls["title_label"] = QtWidgets.QLabel(title_text)
self.controls["title_label"].setObjectName("definitionTitleLabel") self.controls["title_label"].setObjectName("definitionTitleLabel")
self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter) self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter)
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
# 主分割器 # 主分割器
self.splitters["main_splitter"] = QtWidgets.QSplitter(QtCore.Qt.Horizontal) self.splitters["main_splitter"] = QtWidgets.QSplitter(QtCore.Qt.Horizontal)

View File

@@ -84,10 +84,12 @@ class GeometryUI(ui_utils.BaseUI):
创建几何模型UI控件 创建几何模型UI控件
包括按钮、标签、列表等 包括按钮、标签、列表等
""" """
# 标题标签 # 标题标签 - 使用HTML格式化标题
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("geometry_title", "几何模型")) title_text = f"<h3 style='margin:0;padding:5px;'>{LANG.get('geometry_title', '几何模型')}</h4>"
self.controls["title_label"] = QtWidgets.QLabel(title_text)
self.controls["title_label"].setObjectName("geometryTitleLabel") self.controls["title_label"].setObjectName("geometryTitleLabel")
self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter) self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter)
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
# 左侧面板 # 左侧面板
self.controls["left_panel"] = QtWidgets.QWidget() self.controls["left_panel"] = QtWidgets.QWidget()

View File

@@ -328,10 +328,12 @@ class RiggingUI(ui_utils.BaseUI):
创建绑定系统UI控件 创建绑定系统UI控件
包括按钮、标签、列表等 包括按钮、标签、列表等
""" """
# 标题标签 # 标题标签 - 使用HTML格式化标题
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("rigging_title", "骨骼绑定")) title_text = f"<h3 style='margin:0;padding:5px;'>{LANG.get('rigging_title', '骨骼绑定')}</h4>"
self.controls["title_label"] = QtWidgets.QLabel(title_text)
self.controls["title_label"].setObjectName("riggingTitleLabel") self.controls["title_label"].setObjectName("riggingTitleLabel")
self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter) self.controls["title_label"].setAlignment(QtCore.Qt.AlignCenter)
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
# 左侧面板 # 左侧面板
self.controls["left_panel"] = QtWidgets.QWidget() self.controls["left_panel"] = QtWidgets.QWidget()