Update
This commit is contained in:
parent
6a41571643
commit
816523347d
@ -6,7 +6,7 @@ import maya.cmds as cmds
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
class DNABrowserWidget(QtWidgets.QWidget):
|
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):
|
def __init__(self, dna_path, img_path, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -17,16 +17,16 @@ class DNABrowserWidget(QtWidgets.QWidget):
|
|||||||
self.update_grid()
|
self.update_grid()
|
||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
# 创建主布局
|
# Create main layout
|
||||||
self.main_layout = QtWidgets.QVBoxLayout(self)
|
self.main_layout = QtWidgets.QVBoxLayout(self)
|
||||||
self.main_layout.setContentsMargins(0, 0, 0, 0)
|
self.main_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
# 创建流式布局容器
|
# Create flow layout container
|
||||||
self.flow_widget = QtWidgets.QWidget()
|
self.flow_widget = QtWidgets.QWidget()
|
||||||
self.flow_layout = FlowLayout(self.flow_widget)
|
self.flow_layout = FlowLayout(self.flow_widget)
|
||||||
self.flow_layout.setSpacing(5)
|
self.flow_layout.setSpacing(5)
|
||||||
|
|
||||||
# 创建滚动区域
|
# Create scroll area
|
||||||
self.scroll_area = QtWidgets.QScrollArea()
|
self.scroll_area = QtWidgets.QScrollArea()
|
||||||
self.scroll_area.setWidgetResizable(True)
|
self.scroll_area.setWidgetResizable(True)
|
||||||
self.scroll_area.setWidget(self.flow_widget)
|
self.scroll_area.setWidget(self.flow_widget)
|
||||||
@ -54,7 +54,7 @@ class DNABrowserWidget(QtWidgets.QWidget):
|
|||||||
self.main_layout.addWidget(self.scroll_area)
|
self.main_layout.addWidget(self.scroll_area)
|
||||||
|
|
||||||
def scan_dna_files(self):
|
def scan_dna_files(self):
|
||||||
"""扫描DNA文件夹并建立索引"""
|
"""Scan DNA folder and build index"""
|
||||||
self.dna_files = {}
|
self.dna_files = {}
|
||||||
if not os.path.exists(self.dna_path):
|
if not os.path.exists(self.dna_path):
|
||||||
cmds.warning(f"DNA path not found: {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]
|
name = os.path.splitext(file)[0]
|
||||||
dna_file = os.path.join(self.dna_path, file).replace("\\", "/")
|
dna_file = os.path.join(self.dna_path, file).replace("\\", "/")
|
||||||
|
|
||||||
# 直接在img目录下查找图片
|
# Search for images directly in the img directory
|
||||||
img_file = None
|
img_file = None
|
||||||
for ext in ['.jpg', '.png', '.jpeg']:
|
for ext in ['.jpg', '.png', '.jpeg']:
|
||||||
img_path = os.path.join(self.img_path, f"{name}{ext}").replace("\\", "/")
|
img_path = os.path.join(self.img_path, f"{name}{ext}").replace("\\", "/")
|
||||||
@ -82,39 +82,39 @@ class DNABrowserWidget(QtWidgets.QWidget):
|
|||||||
'img_path': img_file
|
'img_path': img_file
|
||||||
}
|
}
|
||||||
|
|
||||||
# 打印调试信息
|
# Print debug information
|
||||||
print(f"DNA file: {name}")
|
print(f"DNA file: {name}")
|
||||||
print(f" DNA path: {dna_file}")
|
print(f" DNA path: {dna_file}")
|
||||||
print(f" Image path: {img_file}")
|
print(f" Image path: {img_file}")
|
||||||
print(f" Image exists: {bool(img_file and os.path.exists(img_file))}")
|
print(f" Image exists: {bool(img_file and os.path.exists(img_file))}")
|
||||||
|
|
||||||
def update_grid(self):
|
def update_grid(self):
|
||||||
"""更新DNA网格"""
|
"""Update DNA grid"""
|
||||||
# 清除现有按钮
|
# Clear existing buttons
|
||||||
for i in reversed(range(self.flow_layout.count())):
|
for i in reversed(range(self.flow_layout.count())):
|
||||||
self.flow_layout.itemAt(i).widget().deleteLater()
|
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
|
container_width = self.flow_widget.width() or 300
|
||||||
button_width = (container_width - 60) // 6 # 每行6个按钮
|
button_width = (container_width - 60) // 6 # 6 buttons per row
|
||||||
button_height = int(button_width * 1.2) # 保持宽高比
|
button_height = int(button_width * 1.2) # Maintain aspect ratio
|
||||||
|
|
||||||
# 创建DNA样本按钮
|
# Create DNA sample buttons
|
||||||
for name, info in self.dna_files.items():
|
for name, info in self.dna_files.items():
|
||||||
dna_btn = self.create_dna_button(name, info, button_width, button_height)
|
dna_btn = self.create_dna_button(name, info, button_width, button_height)
|
||||||
self.flow_layout.addWidget(dna_btn)
|
self.flow_layout.addWidget(dna_btn)
|
||||||
|
|
||||||
def create_dna_button(self, name, info, width, height):
|
def create_dna_button(self, name, info, width, height):
|
||||||
"""创建DNA按钮"""
|
"""Create DNA button"""
|
||||||
btn = QtWidgets.QPushButton()
|
btn = QtWidgets.QPushButton()
|
||||||
btn.setFixedSize(width, height)
|
btn.setFixedSize(width, height)
|
||||||
|
|
||||||
# 创建按钮布局
|
# Create button layout
|
||||||
layout = QtWidgets.QVBoxLayout(btn)
|
layout = QtWidgets.QVBoxLayout(btn)
|
||||||
layout.setContentsMargins(2, 2, 2, 2)
|
layout.setContentsMargins(2, 2, 2, 2)
|
||||||
layout.setSpacing(1)
|
layout.setSpacing(1)
|
||||||
|
|
||||||
# 创建图标标签
|
# Create icon label
|
||||||
icon_label = QtWidgets.QLabel()
|
icon_label = QtWidgets.QLabel()
|
||||||
icon_label.setAlignment(QtCore.Qt.AlignCenter)
|
icon_label.setAlignment(QtCore.Qt.AlignCenter)
|
||||||
|
|
||||||
@ -129,24 +129,24 @@ class DNABrowserWidget(QtWidgets.QWidget):
|
|||||||
icon_label.setPixmap(scaled_pixmap)
|
icon_label.setPixmap(scaled_pixmap)
|
||||||
else:
|
else:
|
||||||
icon_label.setText("No Image")
|
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 = QtWidgets.QLabel(name)
|
||||||
text_label.setAlignment(QtCore.Qt.AlignCenter)
|
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(icon_label)
|
||||||
layout.addWidget(text_label)
|
layout.addWidget(text_label)
|
||||||
|
|
||||||
# 设置样式 - 保持黑色背景,文字改为白色
|
# Set style - maintain black background with white text
|
||||||
btn.setStyleSheet("""
|
btn.setStyleSheet("""
|
||||||
QPushButton {
|
QPushButton {
|
||||||
background-color: #303030;
|
background-color: #303030;
|
||||||
border: 1px solid #202020;
|
border: 1px solid #202020;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
color: #FFFFFF; /* 按钮文字颜色改为白色 */
|
color: #FFFFFF;
|
||||||
}
|
}
|
||||||
QPushButton:hover {
|
QPushButton:hover {
|
||||||
background-color: #404040;
|
background-color: #404040;
|
||||||
@ -163,7 +163,7 @@ class DNABrowserWidget(QtWidgets.QWidget):
|
|||||||
return btn
|
return btn
|
||||||
|
|
||||||
def on_dna_selected(self, dna_path):
|
def on_dna_selected(self, dna_path):
|
||||||
"""当DNA被选中时发出信号"""
|
"""Emit signal when DNA is selected"""
|
||||||
self.dna_selected.emit(dna_path)
|
self.dna_selected.emit(dna_path)
|
||||||
|
|
||||||
class FlowLayout(QtWidgets.QLayout):
|
class FlowLayout(QtWidgets.QLayout):
|
||||||
@ -233,5 +233,5 @@ class FlowLayout(QtWidgets.QLayout):
|
|||||||
return y + lineHeight - rect.y()
|
return y + lineHeight - rect.y()
|
||||||
|
|
||||||
def create_browser(dna_path, img_path, parent=None):
|
def create_browser(dna_path, img_path, parent=None):
|
||||||
"""创建并返回DNA浏览器实例"""
|
"""Create and return DNA browser instance"""
|
||||||
return DNABrowserWidget(dna_path, img_path, parent)
|
return DNABrowserWidget(dna_path, img_path, parent)
|
||||||
|
@ -33,7 +33,7 @@ TOOL_AUTHOR = "Virtuos"
|
|||||||
# UI Constants
|
# UI Constants
|
||||||
TOOL_WSCL_NAME = "MetaFusionWorkSpaceControl"
|
TOOL_WSCL_NAME = "MetaFusionWorkSpaceControl"
|
||||||
TOOL_HELP_URL = f"http://10.72.61.59:3000/ArtGroup/{TOOL_NAME}/wiki"
|
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
|
# Paths
|
||||||
TOOL_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace("\\", "/")
|
TOOL_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace("\\", "/")
|
||||||
@ -248,8 +248,8 @@ class MainWindow(QtWidgets.QWidget):
|
|||||||
floating=True,
|
floating=True,
|
||||||
retain=True,
|
retain=True,
|
||||||
resizeWidth=True,
|
resizeWidth=True,
|
||||||
initialWidth=500,
|
initialWidth=450,
|
||||||
minimumWidth=500
|
minimumWidth=450
|
||||||
)
|
)
|
||||||
cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True)
|
cmds.workspaceControl(TOOL_WSCL_NAME, e=True, resizeWidth=True)
|
||||||
cmds.control(self.objectName(), e=True, p=workspace_control)
|
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_label)
|
||||||
self.dna_file_layout.addWidget(self.dna_file_input)
|
self.dna_file_layout.addWidget(self.dna_file_input)
|
||||||
|
|
||||||
self.load_dna_btn = MainButton(LANG[TOOL_LANG]["Load DNA"],
|
self.load_dna_btn = MainButton(LANG[TOOL_LANG]["Load DNA"], color="#E6B3B3", hover_color="#F2BFBF", pressed_color="#D99E9E")
|
||||||
color="#E6B3B3", hover_color="#F2BFBF",
|
|
||||||
pressed_color="#D99E9E")
|
|
||||||
|
|
||||||
# Create function buttons
|
# Create function buttons
|
||||||
# Prepare group
|
# Prepare group
|
||||||
@ -402,17 +400,30 @@ class MainWindow(QtWidgets.QWidget):
|
|||||||
|
|
||||||
# DNA Edit group
|
# DNA Edit group
|
||||||
def run_dna_viewer(self):
|
def run_dna_viewer(self):
|
||||||
import DNA_Viewer
|
import dna_viewer
|
||||||
DNA_Viewer.show()
|
dna_viewer.show()
|
||||||
|
|
||||||
# DNA Samples group
|
# DNA Samples group
|
||||||
def run_load_dna(self):
|
def run_load_dna(self):
|
||||||
"""加载选中的DNA文件"""
|
"""加载选中的DNA文件"""
|
||||||
if hasattr(self, 'dna_list') and self.dna_list.currentItem():
|
if hasattr(self, 'dna_list') and self.dna_list.currentItem():
|
||||||
import DNA_Viewer
|
import dna_viewer
|
||||||
DNA_Viewer.load_dna(DNA_File)
|
dna_viewer.load_dna(DNA_File)
|
||||||
else:
|
else:
|
||||||
cmds.warning("Please select a DNA file first")
|
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 =====================================
|
#===================================== BOTTOM LAYOUT =====================================
|
||||||
def help(self):
|
def help(self):
|
||||||
@ -456,19 +467,6 @@ class MainWindow(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.dna_file_label.setText(LANG[TOOL_LANG]["DNA File:"])
|
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 =====================================
|
#===================================== LAUNCH FUNCTIONS =====================================
|
||||||
def show():
|
def show():
|
||||||
return MainWindow.show_window()
|
return MainWindow.show_window()
|
||||||
|
Loading…
Reference in New Issue
Block a user