From 816523347d5d067c081c7ca3f4285d2761d40d33 Mon Sep 17 00:00:00 2001 From: Jeffreytsai1004 Date: Sat, 11 Jan 2025 18:26:42 +0800 Subject: [PATCH] Update --- scripts/DNA_Browser.py | 46 +++++++++++++++++++++--------------------- scripts/MetaFusion.py | 44 +++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/scripts/DNA_Browser.py b/scripts/DNA_Browser.py index 43ab3ac..64dafe3 100644 --- a/scripts/DNA_Browser.py +++ b/scripts/DNA_Browser.py @@ -6,7 +6,7 @@ import maya.cmds as cmds import os class DNABrowserWidget(QtWidgets.QWidget): - dna_selected = QtCore.Signal(str) # 信号:当DNA被选中时发出 + dna_selected = QtCore.Signal(str) # Signal: emitted when a DNA is selected def __init__(self, dna_path, img_path, parent=None): super().__init__(parent) @@ -17,16 +17,16 @@ class DNABrowserWidget(QtWidgets.QWidget): self.update_grid() def setup_ui(self): - # 创建主布局 + # Create main layout self.main_layout = QtWidgets.QVBoxLayout(self) self.main_layout.setContentsMargins(0, 0, 0, 0) - # 创建流式布局容器 + # Create flow layout container self.flow_widget = QtWidgets.QWidget() self.flow_layout = FlowLayout(self.flow_widget) self.flow_layout.setSpacing(5) - # 创建滚动区域 + # Create scroll area self.scroll_area = QtWidgets.QScrollArea() self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.flow_widget) @@ -54,7 +54,7 @@ class DNABrowserWidget(QtWidgets.QWidget): self.main_layout.addWidget(self.scroll_area) def scan_dna_files(self): - """扫描DNA文件夹并建立索引""" + """Scan DNA folder and build index""" self.dna_files = {} if not os.path.exists(self.dna_path): cmds.warning(f"DNA path not found: {self.dna_path}") @@ -69,7 +69,7 @@ class DNABrowserWidget(QtWidgets.QWidget): name = os.path.splitext(file)[0] dna_file = os.path.join(self.dna_path, file).replace("\\", "/") - # 直接在img目录下查找图片 + # Search for images directly in the img directory img_file = None for ext in ['.jpg', '.png', '.jpeg']: img_path = os.path.join(self.img_path, f"{name}{ext}").replace("\\", "/") @@ -82,39 +82,39 @@ class DNABrowserWidget(QtWidgets.QWidget): 'img_path': img_file } - # 打印调试信息 + # Print debug information print(f"DNA file: {name}") print(f" DNA path: {dna_file}") print(f" Image path: {img_file}") print(f" Image exists: {bool(img_file and os.path.exists(img_file))}") def update_grid(self): - """更新DNA网格""" - # 清除现有按钮 + """Update DNA grid""" + # Clear existing buttons for i in reversed(range(self.flow_layout.count())): self.flow_layout.itemAt(i).widget().deleteLater() - # 计算按钮大小 - 减小到原来的1/4左右 + # Calculate button size - reduced to about 1/4 of original container_width = self.flow_widget.width() or 300 - button_width = (container_width - 60) // 6 # 每行6个按钮 - button_height = int(button_width * 1.2) # 保持宽高比 + button_width = (container_width - 60) // 6 # 6 buttons per row + button_height = int(button_width * 1.2) # Maintain aspect ratio - # 创建DNA样本按钮 + # Create DNA sample buttons for name, info in self.dna_files.items(): dna_btn = self.create_dna_button(name, info, button_width, button_height) self.flow_layout.addWidget(dna_btn) def create_dna_button(self, name, info, width, height): - """创建DNA按钮""" + """Create DNA button""" btn = QtWidgets.QPushButton() btn.setFixedSize(width, height) - # 创建按钮布局 + # Create button layout layout = QtWidgets.QVBoxLayout(btn) layout.setContentsMargins(2, 2, 2, 2) layout.setSpacing(1) - # 创建图标标签 + # Create icon label icon_label = QtWidgets.QLabel() icon_label.setAlignment(QtCore.Qt.AlignCenter) @@ -129,24 +129,24 @@ class DNABrowserWidget(QtWidgets.QWidget): icon_label.setPixmap(scaled_pixmap) else: icon_label.setText("No Image") - icon_label.setStyleSheet("color: #FFFFFF; font-size: 8px;") # 改为白色 + icon_label.setStyleSheet("color: #FFFFFF; font-size: 8px;") - # 创建文本标签 + # Create text label text_label = QtWidgets.QLabel(name) text_label.setAlignment(QtCore.Qt.AlignCenter) - text_label.setStyleSheet("color: #FFFFFF; font-size: 8px;") # 改为白色 + text_label.setStyleSheet("color: #FFFFFF; font-size: 8px;") layout.addWidget(icon_label) layout.addWidget(text_label) - # 设置样式 - 保持黑色背景,文字改为白色 + # Set style - maintain black background with white text btn.setStyleSheet(""" QPushButton { background-color: #303030; border: 1px solid #202020; border-radius: 5px; padding: 2px; - color: #FFFFFF; /* 按钮文字颜色改为白色 */ + color: #FFFFFF; } QPushButton:hover { background-color: #404040; @@ -163,7 +163,7 @@ class DNABrowserWidget(QtWidgets.QWidget): return btn def on_dna_selected(self, dna_path): - """当DNA被选中时发出信号""" + """Emit signal when DNA is selected""" self.dna_selected.emit(dna_path) class FlowLayout(QtWidgets.QLayout): @@ -233,5 +233,5 @@ class FlowLayout(QtWidgets.QLayout): return y + lineHeight - rect.y() def create_browser(dna_path, img_path, parent=None): - """创建并返回DNA浏览器实例""" + """Create and return DNA browser instance""" return DNABrowserWidget(dna_path, img_path, parent) diff --git a/scripts/MetaFusion.py b/scripts/MetaFusion.py index c5e787a..29e4816 100644 --- a/scripts/MetaFusion.py +++ b/scripts/MetaFusion.py @@ -33,7 +33,7 @@ TOOL_AUTHOR = "Virtuos" # UI Constants TOOL_WSCL_NAME = "MetaFusionWorkSpaceControl" TOOL_HELP_URL = f"http://10.72.61.59:3000/ArtGroup/{TOOL_NAME}/wiki" -DEFAULT_WINDOW_SIZE = (500, 800) +DEFAULT_WINDOW_SIZE = (450, 800) # Paths TOOL_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace("\\", "/") @@ -248,8 +248,8 @@ class MainWindow(QtWidgets.QWidget): floating=True, retain=True, resizeWidth=True, - initialWidth=500, - minimumWidth=500 + initialWidth=450, + minimumWidth=450 ) cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True) cmds.control(self.objectName(), e=True, p=workspace_control) @@ -289,9 +289,7 @@ class MainWindow(QtWidgets.QWidget): self.dna_file_layout.addWidget(self.dna_file_label) self.dna_file_layout.addWidget(self.dna_file_input) - self.load_dna_btn = MainButton(LANG[TOOL_LANG]["Load DNA"], - color="#E6B3B3", hover_color="#F2BFBF", - pressed_color="#D99E9E") + self.load_dna_btn = MainButton(LANG[TOOL_LANG]["Load DNA"], color="#E6B3B3", hover_color="#F2BFBF", pressed_color="#D99E9E") # Create function buttons # Prepare group @@ -402,17 +400,30 @@ class MainWindow(QtWidgets.QWidget): # DNA Edit group def run_dna_viewer(self): - import DNA_Viewer - DNA_Viewer.show() + import dna_viewer + dna_viewer.show() # DNA Samples group def run_load_dna(self): """加载选中的DNA文件""" if hasattr(self, 'dna_list') and self.dna_list.currentItem(): - import DNA_Viewer - DNA_Viewer.load_dna(DNA_File) + import dna_viewer + dna_viewer.load_dna(DNA_File) else: cmds.warning("Please select a DNA file first") + + def on_dna_selected(self, dna_path): + """当DNA被选中时""" + global DNA_File + DNA_File = dna_path + self.dna_file_input.setText(DNA_File) + print(f"Selected DNA file: {DNA_File}") + + def on_dna_file_changed(self): + """当DNA文件输入框内容改变时""" + global DNA_File + DNA_File = self.dna_file_input.text() + print(f"DNA file path updated: {DNA_File}") #===================================== BOTTOM LAYOUT ===================================== def help(self): @@ -456,19 +467,6 @@ class MainWindow(QtWidgets.QWidget): self.dna_file_label.setText(LANG[TOOL_LANG]["DNA File:"]) - def on_dna_selected(self, dna_path): - """当DNA被选中时""" - global DNA_File - DNA_File = dna_path - self.dna_file_input.setText(DNA_File) - print(f"Selected DNA file: {DNA_File}") - - def on_dna_file_changed(self): - """当DNA文件输入框内容改变时""" - global DNA_File - DNA_File = self.dna_file_input.text() - print(f"DNA file path updated: {DNA_File}") - #===================================== LAUNCH FUNCTIONS ===================================== def show(): return MainWindow.show_window()