Update
This commit is contained in:
183
scripts/Main.py
183
scripts/Main.py
@@ -63,6 +63,12 @@ class MainWindow(QtWidgets.QWidget):
|
||||
self.setStyleSheet("")
|
||||
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
|
||||
# 设置窗口为独立窗口
|
||||
self.setWindowFlags(QtCore.Qt.Window)
|
||||
|
||||
# 设置窗口位置为屏幕中央
|
||||
self.center_window()
|
||||
|
||||
# 设置窗口图标
|
||||
if os.path.exists(TOOL_ICON):
|
||||
self.setWindowIcon(QtGui.QIcon(TOOL_ICON))
|
||||
@@ -98,50 +104,90 @@ class MainWindow(QtWidgets.QWidget):
|
||||
#========================================= WIDGET =======================================
|
||||
def create_widgets(self):
|
||||
"""创建UI控件"""
|
||||
# 主标签页控件
|
||||
self.main_tab_widget = QtWidgets.QTabWidget()
|
||||
self.main_tab_widget.setObjectName("mainTabWidget")
|
||||
# 创建工具栏区域
|
||||
self.toolbar_widget = QtWidgets.QWidget()
|
||||
self.toolbar_widget.setObjectName("toolbarWidget")
|
||||
self.toolbar_widget.setMaximumHeight(80) # 限制工具栏高度
|
||||
|
||||
# 创建各个标签页
|
||||
self.toolbar_tab = QtWidgets.QWidget()
|
||||
self.definition_tab = QtWidgets.QWidget()
|
||||
self.geometry_tab = QtWidgets.QWidget()
|
||||
self.rigging_tab = QtWidgets.QWidget()
|
||||
self.behaviour_tab = QtWidgets.QWidget()
|
||||
# 创建功能区域切换按钮组
|
||||
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.main_tab_widget.addTab(self.toolbar_tab, LANG.get("toolbar", "工具栏"))
|
||||
self.main_tab_widget.addTab(self.definition_tab, LANG.get("definition", "定义"))
|
||||
self.main_tab_widget.addTab(self.geometry_tab, LANG.get("geometry", "几何体"))
|
||||
self.main_tab_widget.addTab(self.rigging_tab, LANG.get("rigging", "绑定"))
|
||||
self.main_tab_widget.addTab(self.behaviour_tab, LANG.get("behaviour", "行为"))
|
||||
# 设置按钮样式和属性
|
||||
for key, button in self.function_buttons.items():
|
||||
button.setObjectName(f"{key}Button")
|
||||
button.setCheckable(True)
|
||||
button.setMinimumHeight(40)
|
||||
|
||||
# 默认选中几何体按钮
|
||||
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 =======================================
|
||||
def create_layouts(self):
|
||||
"""创建布局"""
|
||||
# 主布局
|
||||
main_layout = QtWidgets.QVBoxLayout(self)
|
||||
main_layout.setContentsMargins(5, 5, 5, 5)
|
||||
main_layout.setSpacing(5)
|
||||
main_layout.addWidget(self.main_tab_widget)
|
||||
main_layout.setContentsMargins(2, 2, 2, 2)
|
||||
main_layout.setSpacing(2)
|
||||
|
||||
# 设置各标签页的布局
|
||||
toolbar_layout = QtWidgets.QVBoxLayout(self.toolbar_tab)
|
||||
definition_layout = QtWidgets.QVBoxLayout(self.definition_tab)
|
||||
geometry_layout = QtWidgets.QVBoxLayout(self.geometry_tab)
|
||||
rigging_layout = QtWidgets.QVBoxLayout(self.rigging_tab)
|
||||
behaviour_layout = QtWidgets.QVBoxLayout(self.behaviour_tab)
|
||||
# 创建工具栏布局
|
||||
toolbar_layout = QtWidgets.QHBoxLayout(self.toolbar_widget)
|
||||
toolbar_layout.setContentsMargins(5, 5, 5, 5)
|
||||
toolbar_layout.setSpacing(5)
|
||||
|
||||
# 将各UI模块添加到对应的标签页布局中
|
||||
# 工具栏UI
|
||||
# 将工具栏UI添加到工具栏布局
|
||||
if hasattr(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'):
|
||||
definition_layout.addWidget(self.definition_ui.main_widget)
|
||||
|
||||
# 几何体UI
|
||||
if hasattr(self.geometry_ui, 'main_widget'):
|
||||
geometry_layout.addWidget(self.geometry_ui.main_widget)
|
||||
|
||||
@@ -152,49 +198,68 @@ class MainWindow(QtWidgets.QWidget):
|
||||
# 行为UI
|
||||
if hasattr(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 =====================================
|
||||
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):
|
||||
"""标签页切换事件处理"""
|
||||
tab_name = self.main_tab_widget.tabText(index)
|
||||
print(f"切换到标签页: {tab_name}")
|
||||
def switch_function_panel(self, index):
|
||||
"""切换功能面板"""
|
||||
# 切换堆栈页面
|
||||
self.function_stack.setCurrentIndex(index)
|
||||
|
||||
# 更新按钮状态
|
||||
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):
|
||||
"""重置所有分割器的宽度,确保左右栏宽度均等"""
|
||||
# 延迟执行,确保UI完全加载
|
||||
QtCore.QTimer.singleShot(50, self._do_reset_splitters)
|
||||
QtCore.QTimer.singleShot(200, self._do_reset_splitters)
|
||||
|
||||
def _do_reset_splitters(self):
|
||||
"""实际执行分割器宽度重置的函数"""
|
||||
current_tab = self.main_tab_widget.currentWidget()
|
||||
if not current_tab:
|
||||
return
|
||||
# 重置定义面板分割器
|
||||
if hasattr(self.definition_ui, 'reset_splitter_sizes'):
|
||||
self.definition_ui.reset_splitter_sizes()
|
||||
|
||||
# 查找当前标签页中的所有水平分割器
|
||||
splitters = current_tab.findChildren(QtWidgets.QSplitter)
|
||||
for splitter in splitters:
|
||||
if splitter.orientation() == QtCore.Qt.Horizontal:
|
||||
# 获取分割器宽度
|
||||
width = splitter.width()
|
||||
# 计算每个部分应该的宽度
|
||||
count = splitter.count()
|
||||
if count > 0:
|
||||
part_width = width // count
|
||||
sizes = [part_width] * count
|
||||
# 设置分割器各部分的宽度
|
||||
splitter.setSizes(sizes)
|
||||
# 为每个子项设置相同的伸缩因子
|
||||
for i in range(count):
|
||||
splitter.setStretchFactor(i, 1)
|
||||
# 重置行为面板分割器
|
||||
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):
|
||||
"""将窗口居中显示在屏幕上"""
|
||||
# 获取屏幕几何信息
|
||||
desktop = QtWidgets.QApplication.desktop()
|
||||
screen_rect = desktop.availableGeometry(desktop.primaryScreen())
|
||||
|
||||
# 计算窗口居中位置
|
||||
window_rect = self.frameGeometry()
|
||||
center_point = screen_rect.center()
|
||||
window_rect.moveCenter(center_point)
|
||||
|
||||
# 移动窗口到居中位置
|
||||
self.move(window_rect.topLeft())
|
||||
|
||||
def main():
|
||||
"""主函数,创建并显示主窗口"""
|
||||
|
@@ -85,10 +85,12 @@ class BehaviourUI(ui_utils.BaseUI):
|
||||
创建行为系统UI控件
|
||||
包括按钮、标签、列表等
|
||||
"""
|
||||
# 标题标签
|
||||
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("behaviour_title", "行为"))
|
||||
# 标题标签 - 使用HTML格式化标题
|
||||
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"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
|
||||
|
||||
# 左侧面板
|
||||
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"].setSpacing(2)
|
||||
|
||||
|
@@ -79,10 +79,12 @@ class DefinitionUI(ui_utils.BaseUI):
|
||||
创建定义系统UI控件
|
||||
包括按钮、标签、列表等
|
||||
"""
|
||||
# 标题标签
|
||||
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("definition_title", "DNA定义"))
|
||||
# 标题标签 - 使用HTML格式化标题
|
||||
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"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
|
||||
|
||||
# 主分割器
|
||||
self.splitters["main_splitter"] = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
|
||||
|
@@ -84,10 +84,12 @@ class GeometryUI(ui_utils.BaseUI):
|
||||
创建几何模型UI控件
|
||||
包括按钮、标签、列表等
|
||||
"""
|
||||
# 标题标签
|
||||
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("geometry_title", "几何模型"))
|
||||
# 标题标签 - 使用HTML格式化标题
|
||||
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"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
|
||||
|
||||
# 左侧面板
|
||||
self.controls["left_panel"] = QtWidgets.QWidget()
|
||||
|
@@ -328,10 +328,12 @@ class RiggingUI(ui_utils.BaseUI):
|
||||
创建绑定系统UI控件
|
||||
包括按钮、标签、列表等
|
||||
"""
|
||||
# 标题标签
|
||||
self.controls["title_label"] = QtWidgets.QLabel(LANG.get("rigging_title", "骨骼绑定"))
|
||||
# 标题标签 - 使用HTML格式化标题
|
||||
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"].setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.controls["title_label"].setMaximumHeight(25) # 限制标题高度
|
||||
|
||||
# 左侧面板
|
||||
self.controls["left_panel"] = QtWidgets.QWidget()
|
||||
|
Reference in New Issue
Block a user