|
|
|
@@ -23,54 +23,91 @@ import os
|
|
|
|
|
#===================================== IMPORT FUNCTIONS ===================================
|
|
|
|
|
from scripts.utils import utils_toolbar as utils_toolbar
|
|
|
|
|
from scripts.ui import ui_utils
|
|
|
|
|
import config
|
|
|
|
|
|
|
|
|
|
# 导入图标路径
|
|
|
|
|
ICONS_PATH = config.ICONS_PATH
|
|
|
|
|
|
|
|
|
|
#========================================== WIDGETS ==========================================
|
|
|
|
|
# 全局变量存储UI控件
|
|
|
|
|
toolbar_buttons = {}
|
|
|
|
|
dna_dropdown = None
|
|
|
|
|
status_label = None
|
|
|
|
|
|
|
|
|
|
# 按钮图标和提示文本映射
|
|
|
|
|
button_configs = {
|
|
|
|
|
"open_file": {"icon": "open.png", "tooltip": "打开文件"},
|
|
|
|
|
"save_file": {"icon": "save.png", "tooltip": "保存文件"},
|
|
|
|
|
"save_as": {"icon": "save_new.png", "tooltip": "另存为"},
|
|
|
|
|
"load_preset": {"icon": "import_preset.png", "tooltip": "加载预设"},
|
|
|
|
|
"save_preset": {"icon": "export_preset.png", "tooltip": "导出预设"},
|
|
|
|
|
"import_dna": {"icon": "import_dna.png", "tooltip": "导入DNA"},
|
|
|
|
|
"export_dna": {"icon": "export_dna.png", "tooltip": "导出DNA"},
|
|
|
|
|
"create_rl4": {"icon": "create_rl4_node.png", "tooltip": "创建RL4节点"},
|
|
|
|
|
"delete_rl4": {"icon": "delete_rl4_node.png", "tooltip": "删除RL4节点"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def widgets():
|
|
|
|
|
"""
|
|
|
|
|
创建工具栏UI控件
|
|
|
|
|
"""
|
|
|
|
|
global toolbar_buttons, dna_dropdown, status_label
|
|
|
|
|
global toolbar_buttons, status_label
|
|
|
|
|
|
|
|
|
|
# 工具栏按钮
|
|
|
|
|
toolbar_buttons["load_preset"] = QtWidgets.QPushButton("加载预设")
|
|
|
|
|
toolbar_buttons["load_preset"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["load_preset"].setMinimumWidth(80)
|
|
|
|
|
# 创建按钮的辅助函数
|
|
|
|
|
def create_icon_button(button_id, size=24):
|
|
|
|
|
config = button_configs[button_id]
|
|
|
|
|
button = QtWidgets.QPushButton()
|
|
|
|
|
button.setToolTip(config["tooltip"]) # 设置提示文本
|
|
|
|
|
button.setFixedSize(size, size) # 设置固定大小
|
|
|
|
|
# 设置样式类名
|
|
|
|
|
button.setObjectName("ToolbarIconButton")
|
|
|
|
|
|
|
|
|
|
# 设置图标
|
|
|
|
|
icon_path = os.path.abspath(os.path.join(ICONS_PATH, config["icon"]))
|
|
|
|
|
if os.path.exists(icon_path):
|
|
|
|
|
icon = QtGui.QIcon(icon_path)
|
|
|
|
|
if not icon.isNull():
|
|
|
|
|
button.setIcon(icon)
|
|
|
|
|
button.setIconSize(QtCore.QSize(size-4, size-4)) # 图标尺寸稍小于按钮
|
|
|
|
|
print(f"成功设置按钮图标 {button_id}: {icon_path}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"图标加载失败 {button_id}: {icon_path}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"警告: 图标文件未找到 {button_id}: {icon_path}")
|
|
|
|
|
|
|
|
|
|
return button
|
|
|
|
|
|
|
|
|
|
toolbar_buttons["save_preset"] = QtWidgets.QPushButton("保存预设")
|
|
|
|
|
toolbar_buttons["save_preset"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["save_preset"].setMinimumWidth(80)
|
|
|
|
|
# 创建所有按钮
|
|
|
|
|
# 文件操作按钮
|
|
|
|
|
toolbar_buttons["open_file"] = create_icon_button("open_file")
|
|
|
|
|
toolbar_buttons["save_file"] = create_icon_button("save_file")
|
|
|
|
|
toolbar_buttons["save_as"] = create_icon_button("save_as")
|
|
|
|
|
|
|
|
|
|
toolbar_buttons["import_dna"] = QtWidgets.QPushButton("导入DNA")
|
|
|
|
|
toolbar_buttons["import_dna"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["import_dna"].setMinimumWidth(80)
|
|
|
|
|
# 预设操作按钮
|
|
|
|
|
toolbar_buttons["load_preset"] = create_icon_button("load_preset")
|
|
|
|
|
toolbar_buttons["save_preset"] = create_icon_button("save_preset")
|
|
|
|
|
|
|
|
|
|
toolbar_buttons["export_dna"] = QtWidgets.QPushButton("导出DNA")
|
|
|
|
|
toolbar_buttons["export_dna"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["export_dna"].setMinimumWidth(80)
|
|
|
|
|
# DNA操作按钮
|
|
|
|
|
toolbar_buttons["import_dna"] = create_icon_button("import_dna")
|
|
|
|
|
toolbar_buttons["export_dna"] = create_icon_button("export_dna")
|
|
|
|
|
|
|
|
|
|
toolbar_buttons["create_rl4"] = QtWidgets.QPushButton("创建RL4节点")
|
|
|
|
|
toolbar_buttons["create_rl4"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["create_rl4"].setMinimumWidth(100)
|
|
|
|
|
# RL4节点操作按钮
|
|
|
|
|
toolbar_buttons["create_rl4"] = create_icon_button("create_rl4")
|
|
|
|
|
toolbar_buttons["delete_rl4"] = create_icon_button("delete_rl4")
|
|
|
|
|
|
|
|
|
|
toolbar_buttons["delete_rl4"] = QtWidgets.QPushButton("删除RL4节点")
|
|
|
|
|
toolbar_buttons["delete_rl4"].setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
toolbar_buttons["delete_rl4"].setMinimumWidth(100)
|
|
|
|
|
|
|
|
|
|
# DNA下拉菜单
|
|
|
|
|
dna_dropdown = QtWidgets.QComboBox()
|
|
|
|
|
dna_dropdown.addItem("选择DNA文件...")
|
|
|
|
|
dna_dropdown.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
dna_dropdown.setMinimumWidth(150)
|
|
|
|
|
# 移除DNA下拉菜单
|
|
|
|
|
|
|
|
|
|
# 状态标签
|
|
|
|
|
status_label = QtWidgets.QLabel("就绪")
|
|
|
|
|
status_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
|
|
|
|
|
status_label.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
status_label.setObjectName("StatusLabel")
|
|
|
|
|
# status_label.setStyleSheet("""
|
|
|
|
|
# QLabel {
|
|
|
|
|
# color: #CCCCCC;
|
|
|
|
|
# padding-right: 5px;
|
|
|
|
|
# font-size: 9pt;
|
|
|
|
|
# }
|
|
|
|
|
# """)
|
|
|
|
|
|
|
|
|
|
#========================================== LAYOUTS ==========================================
|
|
|
|
|
def layouts(parent_frame=None):
|
|
|
|
@@ -96,21 +133,36 @@ def layouts(parent_frame=None):
|
|
|
|
|
# 创建工具栏布局
|
|
|
|
|
toolbar_layout = QtWidgets.QHBoxLayout()
|
|
|
|
|
toolbar_layout.setContentsMargins(2, 2, 2, 2)
|
|
|
|
|
toolbar_layout.setSpacing(4)
|
|
|
|
|
toolbar_layout.setSpacing(2) # 减小按钮之间的间距
|
|
|
|
|
toolbar_layout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint) # 设置布局约束为默认,允许自适应
|
|
|
|
|
|
|
|
|
|
# 添加按钮到工具栏
|
|
|
|
|
# 创建分隔符样式
|
|
|
|
|
def create_separator():
|
|
|
|
|
separator = QtWidgets.QFrame()
|
|
|
|
|
separator.setFrameShape(QtWidgets.QFrame.VLine)
|
|
|
|
|
separator.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
|
|
separator.setObjectName("ToolbarSeparator")
|
|
|
|
|
return separator
|
|
|
|
|
|
|
|
|
|
# 添加文件操作按钮
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["open_file"])
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["save_file"])
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["save_as"])
|
|
|
|
|
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
|
|
|
|
|
|
|
|
|
# 添加预设操作按钮
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["load_preset"])
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["save_preset"])
|
|
|
|
|
toolbar_layout.addWidget(QtWidgets.QLabel("|"))
|
|
|
|
|
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
|
|
|
|
|
|
|
|
|
# 添加DNA操作按钮
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["import_dna"])
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["export_dna"])
|
|
|
|
|
toolbar_layout.addWidget(QtWidgets.QLabel("|"))
|
|
|
|
|
toolbar_layout.addWidget(create_separator()) # 使用自定义分隔符
|
|
|
|
|
|
|
|
|
|
# 添加RL4节点操作按钮
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["create_rl4"])
|
|
|
|
|
toolbar_layout.addWidget(toolbar_buttons["delete_rl4"])
|
|
|
|
|
toolbar_layout.addWidget(QtWidgets.QLabel("|"))
|
|
|
|
|
toolbar_layout.addWidget(QtWidgets.QLabel("DNA文件:"))
|
|
|
|
|
toolbar_layout.addWidget(dna_dropdown)
|
|
|
|
|
toolbar_layout.addStretch()
|
|
|
|
|
toolbar_layout.addWidget(status_label)
|
|
|
|
|
|
|
|
|
@@ -122,16 +174,22 @@ def connections():
|
|
|
|
|
"""
|
|
|
|
|
连接工具栏UI信号和槽
|
|
|
|
|
"""
|
|
|
|
|
# 连接按钮点击事件到占位函数
|
|
|
|
|
# 文件操作按钮连接
|
|
|
|
|
toolbar_buttons["open_file"].clicked.connect(lambda: print("打开文件功能待实现"))
|
|
|
|
|
toolbar_buttons["save_file"].clicked.connect(lambda: print("保存文件功能待实现"))
|
|
|
|
|
toolbar_buttons["save_as"].clicked.connect(lambda: print("另存为功能待实现"))
|
|
|
|
|
|
|
|
|
|
# 预设操作按钮连接
|
|
|
|
|
toolbar_buttons["load_preset"].clicked.connect(lambda: print("加载预设功能待实现"))
|
|
|
|
|
toolbar_buttons["save_preset"].clicked.connect(lambda: print("保存预设功能待实现"))
|
|
|
|
|
toolbar_buttons["save_preset"].clicked.connect(lambda: print("导出预设功能待实现"))
|
|
|
|
|
|
|
|
|
|
# DNA操作按钮连接
|
|
|
|
|
toolbar_buttons["import_dna"].clicked.connect(lambda: print("导入DNA功能待实现"))
|
|
|
|
|
toolbar_buttons["export_dna"].clicked.connect(lambda: print("导出DNA功能待实现"))
|
|
|
|
|
|
|
|
|
|
# RL4节点操作按钮连接
|
|
|
|
|
toolbar_buttons["create_rl4"].clicked.connect(lambda: print("创建RL4节点功能待实现"))
|
|
|
|
|
toolbar_buttons["delete_rl4"].clicked.connect(lambda: print("删除RL4节点功能待实现"))
|
|
|
|
|
|
|
|
|
|
# 连接下拉菜单选择事件
|
|
|
|
|
dna_dropdown.currentIndexChanged.connect(lambda index: print(f"选择的DNA文件索引: {index}"))
|
|
|
|
|
|
|
|
|
|
#===================================== PLACEHOLDER FUNCTION ===================================
|
|
|
|
|
def toolbar_temp_function():
|
|
|
|
|