Update MetaFusion.py

This commit is contained in:
Jeffreytsai1004 2025-01-14 01:35:58 +08:00
parent 3cb0e24d7d
commit f240236e9f

View File

@ -189,13 +189,36 @@ class MainWindow(QtWidgets.QWidget):
self.setObjectName(TOOL_PATH)
self.setWindowFlags(QtCore.Qt.Window)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Preferred)
self.setMinimumSize(300, 800)
# 修改尺寸策略,允许水平和垂直方向都可以调整
self.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, # 水平方向可扩展
QtWidgets.QSizePolicy.Expanding # 垂直方向可扩展
)
# 设置最小尺寸
self.setMinimumSize(300, 400)
# 创建滚动区域
self.scroll_area = QtWidgets.QScrollArea()
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.scroll_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
# 创建主容器widget
self.main_container = QtWidgets.QWidget()
self.scroll_area.setWidget(self.main_container)
# 创建布局
self.create_widgets()
self.create_layouts()
self.create_connections()
# 设置主布局
main_layout = QtWidgets.QVBoxLayout(self)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.addWidget(self.scroll_area)
if os.path.exists(TOOL_ICON):
self.setWindowIcon(QtGui.QIcon(TOOL_ICON))
else:
@ -223,10 +246,20 @@ class MainWindow(QtWidgets.QWidget):
if cmds.workspaceControl(TOOL_WSCL_NAME, exists=True):
cmds.deleteUI(TOOL_WSCL_NAME)
try:
workspace_control = cmds.workspaceControl(TOOL_WSCL_NAME, label=TOOL_NAME, floating=True, retain=True, resizeWidth=True, initialWidth=500, minimumWidth=500)
cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True)
workspace_control = cmds.workspaceControl(
TOOL_WSCL_NAME,
label=TOOL_NAME,
floating=True,
retain=True,
resizeWidth=True,
resizeHeight=True,
initialWidth=300,
initialHeight=600,
minimumWidth=300,
minimumHeight=400
)
cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True, resizeHeight=True)
cmds.control(self.objectName(), e=True, p=workspace_control)
cmds.evalDeferred(lambda: cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True))
except Exception as e:
print(f"Error creating workspace control: {e}")
@ -249,40 +282,51 @@ class MainWindow(QtWidgets.QWidget):
button.setFont(QtGui.QFont("Microsoft YaHei", 10))
def create_layouts(self):
main_layout = QtWidgets.QVBoxLayout(self)
# 主布局应用到main_container而不是self
main_layout = QtWidgets.QVBoxLayout(self.main_container)
main_layout.setContentsMargins(2, 2, 2, 2)
# 内容布局
content_layout = QtWidgets.QVBoxLayout()
content_layout.setContentsMargins(5, 5, 5, 5)
# 添加各个组
prepare_group = QtWidgets.QGroupBox(LANG[TOOL_LANG]["Prepare"])
prepare_layout = QtWidgets.QVBoxLayout(prepare_group)
prepare_layout.addWidget(self.body_prepare_btn)
content_layout.addWidget(prepare_group)
dna_edit_group = QtWidgets.QGroupBox(LANG[TOOL_LANG]["DNA Edit"])
dna_edit_layout = QtWidgets.QVBoxLayout(dna_edit_group)
dna_edit_layout.addWidget(self.dna_viewer_btn)
content_layout.addWidget(dna_edit_group)
import_group = QtWidgets.QGroupBox(LANG[TOOL_LANG]["Import"])
import_layout = QtWidgets.QVBoxLayout(import_group)
import_layout.addWidget(self.batch_import_btn)
content_layout.addWidget(import_group)
main_layout.addLayout(content_layout)
# Bottom layout
main_layout.addLayout(content_layout)
main_layout.addStretch()
# 底部布局
bottom_layout = QtWidgets.QHBoxLayout()
bottom_layout.setContentsMargins(5, 0, 5, 5)
icon_label = QtWidgets.QLabel()
if os.path.exists(TOOL_ICON):
icon = QtGui.QPixmap(TOOL_ICON).scaled(24, 24, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
icon_label.setPixmap(icon)
version_label = QtWidgets.QLabel(f"{TOOL_VERSION}")
version_label.setStyleSheet("color: gray; font-size: 12px;")
bottom_layout.addWidget(icon_label)
bottom_layout.addWidget(version_label)
bottom_layout.addStretch()
bottom_layout.addWidget(self.help_btn)
bottom_layout.addWidget(self.lang_btn)
main_layout.addLayout(bottom_layout)
def create_connections(self):