Files
fluent_widgets_pyside6/tests/test_moju.py

174 lines
6.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from common import *
from PySide6.QtWidgets import (
QApplication,
QWidget,
QFormLayout,
QHBoxLayout,
QVBoxLayout,
QLineEdit,
QComboBox,
QPushButton,
QLabel,
QFileDialog,
QMessageBox,
)
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont
from qfluentwidgets import PushButton, ComboBox, LineEdit, PrimaryPushButton
# 模具管理界面
class MoldManagementUI(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
# 初始化字体(用于左侧标签和控件)
self.left_font = QFont()
self.left_font.setPointSize(16) # 左侧标签字体大小
self.setWindowTitle("模具管理界面")
self.resize(1066, 630) # 窗口大小
self.__initWidget()
def __initWidget(self):
# 创建控件
self.__createWidgets()
# 设置样式
self.__initStyles()
# 布局
self.__initLayout()
# 绑定事件
self.__bind()
def __createWidgets(self):
# ========== 创建控件 ==========
# 左侧表单控件
self.serial_edit = LineEdit()
self.serial_edit.setPlaceholderText("模具序列号")
self.serial_edit.setFont(self.left_font) # 输入框字体
self.type_combo = ComboBox()
self.type_combo.addItems(["一板一个", "一板两个", "一板三个", "一板四个"])
self.type_combo.setFont(self.left_font) # 下拉框字体
# 左侧按钮(上传点位等)
self.btn_upload_model = PrimaryPushButton("从文件上传")
self.btn_suction_point = PrimaryPushButton("上传点位")
self.btn_place_point = PrimaryPushButton("上传点位")
self.btn_pick_point = PrimaryPushButton("上传点位")
self.btn_high_freq = PrimaryPushButton("上传点位")
# 右侧操作按钮
self.btn_upload_mold = PrimaryPushButton("上传模具")
self.btn_modify_mold = PrimaryPushButton("修改模具")
self.btn_delete_mold = PrimaryPushButton("删除模具")
self.btn_batch_upload = PrimaryPushButton("通过文件上传") # 需要文件对话框
def __initStyles(self):
# ========== 设置样式 ==========
# 1. 左侧按钮样式(适中大小)
for btn in [
self.btn_upload_model,
self.btn_suction_point,
self.btn_place_point,
self.btn_pick_point,
self.btn_high_freq,
]:
btn.setFixedHeight(46)
# 2. 右侧按钮样式(较大尺寸)
for btn in [
self.btn_upload_mold,
self.btn_modify_mold,
self.btn_delete_mold,
self.btn_batch_upload,
]:
btn.setFixedHeight(99)
def __initLayout(self):
# ========== 布局设计 =========
# 左侧表单布局(创建标签并设置字体)
form_layout = QFormLayout()
form_layout.setSpacing(20) # 行间距
form_layout.setRowWrapPolicy(QFormLayout.DontWrapRows)
# 添加表单行(左侧标签+控件)
label_config = [
("模具序列号:", self.serial_edit),
("模具类型:", self.type_combo),
("模具三维模型:", self.btn_upload_model),
("吸取点位设置:", self.btn_suction_point),
("放置点位设置:", self.btn_place_point),
("取料点位设置:", self.btn_pick_point),
("高周波放料点位设置:", self.btn_high_freq),
]
for text, widget in label_config:
label = QLabel(text)
label.setFont(self.left_font)
form_layout.addRow(label, widget)
# 右侧垂直布局(按钮更大,保持居中)
right_layout = QVBoxLayout()
right_layout.addWidget(self.btn_upload_mold)
right_layout.addWidget(self.btn_modify_mold)
right_layout.addWidget(self.btn_delete_mold)
right_layout.addWidget(self.btn_batch_upload)
right_layout.setAlignment(Qt.AlignCenter)
right_layout.setSpacing(66) # 右侧按钮间距
# 主布局左侧2/3右侧1/3
main_layout = QHBoxLayout()
main_layout.addLayout(form_layout)
main_layout.addLayout(right_layout)
main_layout.setContentsMargins(50, 50, 50, 50)
main_layout.setSpacing(66)
main_layout.setStretchFactor(form_layout, 2)
main_layout.setStretchFactor(right_layout, 1)
self.setLayout(main_layout)
def __bind(self):
# ========== 绑定事件 ==========
self.btn_batch_upload.clicked.connect(self.onFileUpload) # 文件上传
self.btn_upload_model.clicked.connect(self.on3DModelUpload) # 三维模型上传
# 文件上传 (暂时不知道是上传什么文件,待定)
def onFileUpload(self):
"""打开文件对话框"""
# 打开文件选择框
file_paths, _ = QFileDialog.getOpenFileNames(
self, "选择上传文件", "", "所有文件 (*)"
)
if file_paths:
# 显示选中的文件数量(实际应用中可替换为上传逻辑)
QMessageBox.information(self, "文件选择完成", f"准备上传!")
# 这里可以添加文件上传的业务逻辑
print("选中的文件路径:", file_paths)
# 三维模型上传
def on3DModelUpload(self):
"""打开三维模型文件对话框"""
# 只允许选择三维模型相关格式
file_path, _ = QFileDialog.getOpenFileName(
self, "选择三维模型文件", "", "模型文件 (*.stl *.obj *.step);;所有文件 (*)"
)
if file_path:
QMessageBox.information(
self, "模型选择完成", f"已选择模型文件:\n{file_path}"
)
# 这里可以添加模型上传的业务逻辑
print("选中的模型路径:", file_path)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = MoldManagementUI()
window.show()
sys.exit(app.exec())