fix bug(解决登录界面加载图片bug、示教器界面html加载环境问题)、add (模块管理界面、用户授权注册界面)

This commit is contained in:
2025-08-27 20:32:55 +08:00
parent 6b07e6ced4
commit 7cb36c75ea
6 changed files with 1295 additions and 0 deletions

BIN
resource/login.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

401
test_login1.py Normal file
View File

@ -0,0 +1,401 @@
import sys
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QMessageBox,
QFrame,
)
from PySide6.QtCore import Qt, QTimer
from PySide6.QtGui import QFont, QCursor
class LoginWindow(QMainWindow):
"""登录窗口类,优化宽高比例和布局美观度"""
def __init__(self, use_dark_theme=False):
super().__init__()
# 浅色主题样式表
self.light_style = """
QMainWindow, QWidget {
background-color: #f0f2f5;
}
QLabel#titleLabel {
font-weight: bold;
color: #1a73e8;
}
QLabel#subtitleLabel {
font-size: 16px;
color: #5f6368;
}
QLabel#normalLabel {
font-size: 14px;
color: #5f6368;
}
QLabel#linkLabel {
font-size: 14px;
color: #1a73e8;
text-decoration: underline;
background: transparent;
border: none;
}
QLabel#hintLabel {
font-size: 16px;
color: white;
background-color: #4caf50;
border-radius: 8px;
padding: 3px 16px;
min-height: 29px;
min-width: 106px;
max-width: 300px;
border: none;
text-align: center;
}
QLineEdit {
padding: 10px;
border: 1px solid #dadce0;
border-radius: 6px;
font-size: 14px;
background-color: white;
color: #202124;
}
QLineEdit:focus {
border: 2px solid #1a73e8;
outline: none;
}
QPushButton {
background-color: #1a73e8;
color: white;
padding: 10px;
border-radius: 6px;
font-size: 16px;
font-weight: 500;
}
QPushButton:hover {
background-color: #1765cc;
}
QPushButton:pressed {
background-color: #165dba;
}
QFrame#loginFrame {
background-color: white;
border-radius: 10px;
padding: 30px;
border: 1px solid #e0e0e0;
max-height: 350px;
max-width: 400px; /* 限制登录框最大宽度 */
}
"""
# 深色主题样式表
self.dark_style = """
QMainWindow, QWidget {
background-color: #1a1a1a;
}
QLabel#titleLabel {
font-weight: bold;
color: #8ab4f8;
}
QLabel#subtitleLabel {
font-size: 16px;
color: #d0d0d0;
}
QLabel#normalLabel {
font-size: 14px;
color: #d0d0d0;
}
QLabel#linkLabel {
font-size: 14px;
color: #8ab4f8;
text-decoration: underline;
background: transparent;
border: none;
}
QLabel#hintLabel {
font-size: 16px;
color: white;
background-color: #4caf50;
border-radius: 8px;
padding: 3px 16px;
min-height: 29px;
min-width: 106px;
max-width: 300px;
border: none;
text-align: center;
}
QLineEdit {
padding: 10px;
border: 1px solid #444444;
border-radius: 6px;
font-size: 14px;
background-color: #333333;
color: #e0e0e0;
}
QLineEdit:focus {
border: 2px solid #8ab4f8;
outline: none;
}
QPushButton {
background-color: #1a73e8;
color: white;
padding: 10px;
border-radius: 6px;
font-size: 16px;
font-weight: 500;
}
QPushButton:hover {
background-color: #2962ff;
}
QPushButton:pressed {
background-color: #1565c0;
}
QFrame#loginFrame {
background-color: #2d2d2d;
border-radius: 10px;
padding: 30px;
border: 1px solid #444444;
max-height: 350px;
max-width: 400px; /* 限制登录框最大宽度 */
}
"""
# 初始化主题
if use_dark_theme:
self.setStyleSheet(self.dark_style)
else:
self.setStyleSheet(self.light_style)
self.init_ui()
def init_ui(self):
# 宽高比例调整为3:2宽度减少更紧凑美观
self.setWindowTitle("密胺餐盘自动化生产控制系统")
self.resize(900, 600) # 3:2比例900/600=1.5
self.setMinimumSize(750, 500) # 最小尺寸保持3:2比例
# 创建中心部件和主布局
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
main_layout.setContentsMargins(50, 10, 50, 50)
main_layout.setSpacing(15)
# 提示信息容器
hint_container = QWidget()
hint_container.setFixedHeight(50)
hint_layout = QHBoxLayout(hint_container)
hint_layout.setContentsMargins(0, 0, 0, 0)
hint_layout.setAlignment(Qt.AlignCenter)
self.hint_label = QLabel("密码: 123")
self.hint_label.setObjectName("hintLabel")
self.hint_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.hint_label.setVisible(False)
hint_layout.addWidget(self.hint_label)
main_layout.addWidget(hint_container)
# 系统标题(随窗口动态缩放)
self.title_label = QLabel("密胺餐盘自动化生产控制系统")
self.title_label.setObjectName("titleLabel")
self.title_label.setAlignment(Qt.AlignCenter)
main_layout.addWidget(self.title_label)
# 系统描述
subtitle_label = QLabel("高效、安全的自动化控制系统")
subtitle_label.setObjectName("subtitleLabel")
subtitle_label.setAlignment(Qt.AlignCenter)
subtitle_label.setFixedHeight(25)
main_layout.addWidget(subtitle_label)
main_layout.addSpacing(20)
# 登录框(宽度减少,更紧凑)
login_frame = QFrame()
login_frame.setObjectName("loginFrame")
login_layout = QVBoxLayout(login_frame)
login_layout.setSpacing(20)
login_layout.setContentsMargins(20, 20, 20, 20)
# 账号输入
self.username_input = QLineEdit()
self.username_input.setPlaceholderText("请输入账号")
self.username_input.setText("manager")
self.username_input.setMinimumWidth(250)
self.username_input.setMaximumWidth(350) # 限制输入框最大宽度
# 密码输入
self.password_input = QLineEdit()
self.password_input.setPlaceholderText("请输入密码")
self.password_input.setEchoMode(QLineEdit.Password)
self.password_input.setMinimumWidth(250)
self.password_input.setMaximumWidth(350)
# 登录按钮和忘记密码布局
btn_layout = QVBoxLayout()
self.login_btn = QPushButton("登录")
self.login_btn.clicked.connect(self.validate_login)
self.login_btn.setMinimumWidth(250)
self.login_btn.setMaximumWidth(350)
forgot_layout = QHBoxLayout()
forgot_layout.setAlignment(Qt.AlignLeft)
self.forgot_password = QLabel("忘记密码")
self.forgot_password.setObjectName("linkLabel")
self.forgot_password.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.forgot_password.setCursor(QCursor(Qt.PointingHandCursor))
self.forgot_password.mousePressEvent = self.show_password_hint
forgot_layout.addWidget(self.forgot_password)
forgot_layout.addStretch()
btn_layout.addWidget(self.login_btn)
btn_layout.addLayout(forgot_layout)
login_layout.addWidget(self.username_input)
login_layout.addWidget(self.password_input)
login_layout.addLayout(btn_layout)
# 水平布局(登录框宽度占比减少,左右留白增加)
center_layout = QHBoxLayout()
center_layout.addStretch(2) # 左侧空白占2份比之前增加
center_layout.addWidget(login_frame, 3) # 登录框占3份比之前减少
center_layout.addStretch(2) # 右侧空白占2份比之前增加
main_layout.addLayout(center_layout, 2)
main_layout.addStretch(1)
# 默认选中密码框
self.password_input.setFocus()
# 提示定时器
self.hint_timer = QTimer(self)
self.hint_timer.setSingleShot(True)
self.hint_timer.timeout.connect(self.hide_password_hint)
# 初始化标题大小
self.adjust_title_size()
def adjust_title_size(self):
"""调整标题大小,适应新的宽高比例"""
window_width = self.width()
# 字体大小计算更保守(宽度减少后避免文字过大)
font_size = max(20, min(36, window_width // 66)) # 除数增大,字体增长更平缓
font = QFont()
font.setPointSize(font_size)
self.title_label.setFont(font)
def resizeEvent(self, event):
"""窗口大小改变时调整标题"""
super().resizeEvent(event)
self.adjust_title_size()
def toggle_theme(self):
"""切换主题接口"""
current_style = self.styleSheet()
if current_style == self.light_style:
self.setStyleSheet(self.dark_style)
else:
self.setStyleSheet(self.light_style)
def show_password_hint(self, event):
self.hint_label.setVisible(True)
self.hint_timer.start(3000)
def hide_password_hint(self):
self.hint_label.setVisible(False)
def validate_login(self):
username = self.username_input.text().strip()
password = self.password_input.text().strip()
if password != "123":
QMessageBox.warning(self, "登录失败", "密码错误,请重试!")
return
if username == "manager":
self.open_workshop_manager_interface()
elif username == "admin":
self.open_debugger_interface()
else:
QMessageBox.warning(self, "登录失败", "用户名不存在!")
return
def open_workshop_manager_interface(self):
current_style = self.styleSheet()
self.workshop_window = WorkshopManagerWindow(current_style)
self.workshop_window.show()
self.close()
def open_debugger_interface(self):
current_style = self.styleSheet()
self.debugger_window = DebuggerWindow(current_style)
self.debugger_window.show()
self.close()
class WorkshopManagerWindow(QMainWindow):
def __init__(self, style_sheet):
super().__init__()
self.setStyleSheet(style_sheet)
self.init_ui()
def init_ui(self):
self.setWindowTitle("车间主管控制台 - 密胺餐盘自动化生产控制系统")
self.resize(1050, 700) # 3:2比例
self.setMinimumSize(900, 600)
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
title_label = QLabel("欢迎使用车间主管系统")
title_label.setObjectName("titleLabel")
title_label.setAlignment(Qt.AlignCenter)
title_label.setFont(QFont("Arial", 18, QFont.Bold))
info_label = QLabel("这里是密胺餐盘生产线的管理和监控功能界面")
info_label.setObjectName("normalLabel")
info_label.setAlignment(Qt.AlignCenter)
layout.addStretch()
layout.addWidget(title_label)
layout.addWidget(info_label)
layout.addStretch()
class DebuggerWindow(QMainWindow):
def __init__(self, style_sheet):
super().__init__()
self.setStyleSheet(style_sheet)
self.init_ui()
def init_ui(self):
self.setWindowTitle("调试人员控制台 - 密胺餐盘自动化生产控制系统")
self.resize(1050, 700) # 3:2比例
self.setMinimumSize(900, 600)
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
title_label = QLabel("欢迎使用调试人员系统")
title_label.setObjectName("titleLabel")
title_label.setAlignment(Qt.AlignCenter)
title_label.setFont(QFont("Arial", 18, QFont.Bold))
info_label = QLabel("这里是密胺餐盘生产设备的调试和参数配置界面")
info_label.setObjectName("normalLabel")
info_label.setAlignment(Qt.AlignCenter)
layout.addStretch()
layout.addWidget(title_label)
layout.addWidget(info_label)
layout.addStretch()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = LoginWindow(use_dark_theme=False)
window.show()
sys.exit(app.exec())

506
test_login2.py Normal file
View File

@ -0,0 +1,506 @@
import sys
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QMessageBox,
QFrame,
QSizePolicy,
)
from PySide6.QtCore import Qt, QTimer, QPoint, QRectF
from PySide6.QtGui import (
QFont,
QCursor,
QPixmap,
QImage,
QRegion,
QPainterPath,
QPainter,
QColor,
)
class LoginWindow(QMainWindow):
"""登录窗口类,优化宽高比例和布局美观度"""
def __init__(self, use_dark_theme=False):
super().__init__()
# 浅色主题样式表
# 后期写入 .qss 文件
self.light_style = """
QMainWindow, QWidget {
background-color: #ffffff;
}
QLabel#titleLabel {
font-weight: bold;
color: #2C3E50; /* 工业灰 */
}
QLabel#subtitleLabel {
font-size: 16px;
color: #5f6368;
}
QLabel#normalLabel {
font-size: 14px;
color: #5f6368;
}
QLabel#linkLabel {
font-size: 14px;
color: #1a73e8;
text-decoration: underline;
background: transparent;
border: none;
}
QLabel#hintLabel {
font-size: 16px;
color: white;
background-color: #4caf50;
border-radius: 8px;
padding: 3px 16px;
min-height: 29px;
min-width: 106px;
max-width: 300px;
border: none;
text-align: center;
}
QLineEdit {
padding: 10px;
border: 1px solid #dadce0;
border-radius: 6px;
font-size: 14px;
background-color: white;
color: #202124;
}
QLineEdit:focus {
border: 2px solid #1A1A1A;
border-radius: 8px;
padding: 4px;
}
QLineEdit::placeholder {
color: #424242;
}
QPushButton {
background-color: #1a73e8;
color: white;
padding: 10px;
border-radius: 6px;
font-size: 16px;
font-weight: 500;
}
QPushButton:hover {
background-color: #1765cc;
}
QPushButton:pressed {
background-color: #165dba;
}
QFrame#loginFrame {
background-color: white;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border: 1px solid #e0e0e0;
min-width: 600px;
min-height: 360px;
max-width: 900px;
max-height: 460px;
}
QWidget#formWidget {
background-color: #f8f9fa;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
}
QLabel#loginTitleLabel {
font-size: 24px;
color: #333333;
margin-bottom: 16px;
background-color: #f8f9fa;
}
"""
# 深色主题样式表
self.dark_style = """
QMainWindow, QWidget {
background-color: #1a1a1a;
}
QLabel#titleLabel {
font-weight: bold;
color: white;
}
QLabel#subtitleLabel {
font-size: 16px;
color: #d0d0d0;
}
QLabel#normalLabel {
font-size: 14px;
color: #d0d0d0;
}
QLabel#linkLabel {
font-size: 14px;
color: #8ab4f8;
text-decoration: underline;
background: transparent;
border: none;
}
QLabel#hintLabel {
font-size: 16px;
color: white;
background-color: #4caf50;
border-radius: 8px;
padding: 3px 16px;
min-height: 29px;
min-width: 106px;
max-width: 300px;
border: none;
text-align: center;
}
QLineEdit {
padding: 10px;
border: 1px solid #444444;
border-radius: 6px;
font-size: 14px;
background-color: #333333;
color: #e0e0e0;
}
QLineEdit:focus {
border: 2px solid #8ab4f8;
outline: none;
}
QPushButton {
background-color: #1a73e8;
color: white;
padding: 10px;
border-radius: 6px;
font-size: 16px;
font-weight: 500;
}
QPushButton:hover {
background-color: #2962ff;
}
QPushButton:pressed {
background-color: #1565c0;
}
QFrame#loginFrame {
background-color: #2d2d2d;
border: 1px solid #444444;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
min-width: 600px;
min-height: 360px;
max-width: 900px;
max-height: 460px;
}
QWidget#formWidget {
background-color: #e9e9e9;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
}
QLabel#loginTitleLabel {
font-size: 24px;
color: #333333;
margin-bottom: 16px;
background-color: #e9e9e9;
}
"""
# 可以根据不同的主题,设置不同的样式表
if use_dark_theme:
self.setStyleSheet(self.dark_style)
else:
self.setStyleSheet(self.light_style)
self.init_ui()
def init_ui(self):
self.setWindowTitle("密胺餐盘自动化生产控制系统")
self.resize(900, 600) # 3:2比例900/600=1.5
self.setMinimumSize(750, 500) # 最小尺寸保持3:2比例
# 创建中心部件和主布局
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
main_layout.setContentsMargins(50, 10, 50, 50)
main_layout.setSpacing(15)
# 提示信息容器
hint_container = QWidget()
hint_container.setFixedHeight(50)
hint_layout = QHBoxLayout(hint_container)
hint_layout.setContentsMargins(0, 0, 0, 0)
hint_layout.setAlignment(Qt.AlignCenter)
self.hint_label = QLabel("密码: 123")
self.hint_label.setObjectName("hintLabel")
self.hint_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.hint_label.setVisible(False)
hint_layout.addWidget(self.hint_label)
main_layout.addWidget(hint_container)
# 系统标题(随窗口动态缩放)
self.title_label = QLabel("密胺餐盘自动化生产控制系统")
self.title_label.setObjectName("titleLabel")
self.title_label.setAlignment(Qt.AlignCenter)
main_layout.addWidget(self.title_label)
# 系统描述
subtitle_label = QLabel("高效、安全的自动化控制系统")
subtitle_label.setObjectName("subtitleLabel")
subtitle_label.setAlignment(Qt.AlignCenter)
subtitle_label.setFixedHeight(25)
main_layout.addWidget(subtitle_label)
main_layout.addSpacing(20)
# ---------------- 登录框:左图 + 右表单 ----------------
# -------- 登录框 占比左图1份 + 右表单1份 --------
login_frame = QFrame()
login_frame.setObjectName("loginFrame")
login_layout = QHBoxLayout(login_frame)
login_layout.setSpacing(0) # 左右紧贴,无间距
login_layout.setContentsMargins(0, 0, 0, 0) # 左上右下内边距为0
# -------- 左侧图片区域占1份宽度 --------
self.image_label = QLabel()
self.image_label.setSizePolicy(
QSizePolicy.Expanding, QSizePolicy.Expanding # 水平拉伸 # 垂直拉伸
)
self.image_label.setAlignment(Qt.AlignCenter)
# 加载左侧图片png图片
image_path = r"resource\login.png"
pixmap = QPixmap(image_path)
if not pixmap.isNull():
self.image_label.setPixmap(pixmap)
self.image_label.setScaledContents(True) # 填充容器,保持比例
else:
self.image_label.setText("图片加载失败")
self.image_label.setStyleSheet("font-size: 14px; color: #888;")
login_layout.addWidget(self.image_label, stretch=1) # 图片占1份
# -------- 右侧表单区域占2份宽度内容居中 --------
form_widget = QWidget()
form_widget.setObjectName("formWidget")
form_widget.setContentsMargins(30, 30, 30, 30)
form_layout = QVBoxLayout(form_widget)
form_layout.setSpacing(25)
form_layout.setContentsMargins(0, 0, 0, 0) # 上左下右内边距为0
form_layout.setAlignment(Qt.AlignCenter) # 表单内容居中
self.login_title_label = QLabel("Sign In") # 登录标题文本
self.login_title_label.setObjectName("loginTitleLabel")
# 账号输入
self.username_input = QLineEdit()
self.username_input.setPlaceholderText("请输入账号")
self.username_input.setText("manager")
self.username_input.setFixedWidth(250) # 固定宽度,避免过度拉伸
# 密码输入
self.password_input = QLineEdit()
self.password_input.setPlaceholderText("请输入密码")
self.password_input.setEchoMode(QLineEdit.Password)
self.password_input.setFixedWidth(250)
# 登录按钮
self.login_btn = QPushButton("登录")
self.login_btn.clicked.connect(self.validate_login) # 用户登录验证
self.login_btn.setMinimumWidth(120)
self.login_btn.setMaximumWidth(200)
# 登录按钮样式
self.login_btn.setStyleSheet(
"""
QPushButton {
background-color: #4A6FA5;
color: white;
padding: 6px 10px;
border-radius: 15px;
font-size: 16px;
font-weight: 550;
min-height: 24px;
max-height: 32px;
}
QPushButton:hover {
background-color: #3D5D8A;
}
QPushButton:pressed {
background-color: #304C70;
}
"""
)
# 忘记密码链接
forgot_layout = QHBoxLayout()
forgot_layout.setAlignment(Qt.AlignCenter) # 忘记密码居中
self.forgot_password = QLabel("忘记密码")
self.forgot_password.setObjectName("linkLabel")
self.forgot_password.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.forgot_password.setCursor(QCursor(Qt.PointingHandCursor))
self.forgot_password.mousePressEvent = self.show_password_hint
forgot_layout.addWidget(self.forgot_password)
# forgot_layout.addStretch()
# 组装表单布局
# 添加到布局时显式指定水平居中
form_layout.addWidget(self.login_title_label, alignment=Qt.AlignHCenter)
form_layout.addWidget(self.username_input, alignment=Qt.AlignHCenter)
form_layout.addWidget(self.password_input, alignment=Qt.AlignHCenter)
form_layout.addWidget(self.login_btn, alignment=Qt.AlignHCenter)
form_layout.addLayout(forgot_layout)
login_layout.addWidget(form_widget, stretch=1) # 表单占1份
# -------- 登录框加入主布局 --------
center_layout = QHBoxLayout() # 使登录框居中显示
center_layout.addStretch(2)
center_layout.addWidget(login_frame, stretch=3) # 登录框整体占3份
center_layout.addStretch(2)
main_layout.addLayout(center_layout, stretch=2)
main_layout.addStretch(1)
# 默认选中密码框
self.password_input.setFocus()
# 提示定时器
self.hint_timer = QTimer(self)
self.hint_timer.setSingleShot(True)
self.hint_timer.timeout.connect(self.hide_password_hint)
# 初始化标题大小
self.adjust_title_size()
def adjust_title_size(self):
"""调整标题大小,适应新的宽高比例"""
window_width = self.width()
font_size = max(20, min(36, window_width // 60)) # 除数增大,字体增长更平缓
font = QFont()
font.setPointSize(font_size)
self.title_label.setFont(font)
def resizeEvent(self, event):
"""窗口大小改变时调整标题"""
super().resizeEvent(event)
self.adjust_title_size()
def toggle_theme(self):
"""切换主题"""
current_style = self.styleSheet()
if current_style == self.light_style:
self.setStyleSheet(self.dark_style)
else:
self.setStyleSheet(self.light_style)
def show_password_hint(self, event):
self.hint_label.setVisible(True)
self.hint_timer.start(3000)
def hide_password_hint(self):
self.hint_label.setVisible(False)
# 目前写死密码都是123
# 后续 可以从数据库读入
def validate_login(self):
username = self.username_input.text().strip()
password = self.password_input.text().strip()
if password != "123":
QMessageBox.warning(self, "登录失败", "密码错误,请重试!")
return
# 根据登录的用户的不同,跳转到不同的界面
if username == "manager":
self.open_workshop_manager_interface()
elif username == "admin":
self.open_debugger_interface()
else:
QMessageBox.warning(self, "登录失败", "用户名不存在!")
return
# 测试界面接口一
def open_workshop_manager_interface(self):
current_style = self.styleSheet()
self.workshop_window = WorkshopManagerWindow(current_style)
self.workshop_window.show()
self.close()
# 测试界面接口二
def open_debugger_interface(self):
current_style = self.styleSheet()
self.debugger_window = DebuggerWindow(current_style)
self.debugger_window.show()
self.close()
class WorkshopManagerWindow(QMainWindow):
def __init__(self, style_sheet):
super().__init__()
self.setStyleSheet(style_sheet)
self.init_ui()
def init_ui(self):
self.setWindowTitle("车间主管控制台 - 密胺餐盘自动化生产控制系统")
self.resize(1050, 700) # 3:2比例
self.setMinimumSize(900, 600)
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
title_label = QLabel("欢迎使用车间主管系统")
title_label.setObjectName("titleLabel")
title_label.setAlignment(Qt.AlignCenter)
title_label.setFont(QFont("Arial", 18, QFont.Bold))
info_label = QLabel("这里是密胺餐盘生产线的管理和监控功能界面")
info_label.setObjectName("normalLabel")
info_label.setAlignment(Qt.AlignCenter)
layout.addStretch()
layout.addWidget(title_label)
layout.addWidget(info_label)
layout.addStretch()
class DebuggerWindow(QMainWindow):
def __init__(self, style_sheet):
super().__init__()
self.setStyleSheet(style_sheet)
self.init_ui()
def init_ui(self):
self.setWindowTitle("调试人员控制台 - 密胺餐盘自动化生产控制系统")
self.resize(1050, 700) # 3:2比例
self.setMinimumSize(900, 600)
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
title_label = QLabel("欢迎使用调试人员系统")
title_label.setObjectName("titleLabel")
title_label.setAlignment(Qt.AlignCenter)
title_label.setFont(QFont("Arial", 18, QFont.Bold))
info_label = QLabel("这里是密胺餐盘生产设备的调试和参数配置界面")
info_label.setObjectName("normalLabel")
info_label.setAlignment(Qt.AlignCenter)
layout.addStretch()
layout.addWidget(title_label)
layout.addWidget(info_label)
layout.addStretch()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = LoginWindow()
window.show()
sys.exit(app.exec())

187
test_moju.py Normal file
View File

@ -0,0 +1,187 @@
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
# 模具管理界面
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 = PushButton("从文件上传")
self.btn_suction_point = PushButton("上传点位")
self.btn_place_point = PushButton("上传点位")
self.btn_pick_point = PushButton("上传点位")
self.btn_high_freq = PushButton("上传点位")
# 右侧操作按钮
self.btn_upload_mold = PushButton("上传模具")
self.btn_modify_mold = PushButton("修改模具")
self.btn_delete_mold = PushButton("删除模具")
self.btn_batch_upload = PushButton("通过文件上传") # 需要文件对话框
def __initStyles(self):
# ========== 设置样式 ==========
# 1. 左侧按钮样式(适中大小)
left_btn_style = """
QPushButton {
min-height: 40px;
min-width: 150px;
font-size: 14px;
padding: 5px 10px;
}
"""
for btn in [
self.btn_upload_model,
self.btn_suction_point,
self.btn_place_point,
self.btn_pick_point,
self.btn_high_freq,
]:
btn.setStyleSheet(left_btn_style)
# 2. 右侧按钮样式(较大尺寸)
right_btn_style = """
QPushButton {
min-height: 36px;
min-width: 166px;
font-size: 16px;
padding: 10px 20px;
}
"""
for btn in [
self.btn_upload_mold,
self.btn_modify_mold,
self.btn_delete_mold,
self.btn_batch_upload,
]:
btn.setStyleSheet(right_btn_style)
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())

105
test_register.py Normal file
View File

@ -0,0 +1,105 @@
from PySide6.QtWidgets import (
QApplication,
QWidget,
QVBoxLayout,
QFormLayout,
QLineEdit,
QComboBox,
QPushButton,
QLabel,
QSpacerItem,
QSizePolicy,
)
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont
from qfluentwidgets import PushButton, ComboBox, LineEdit
class RegistrationUI(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.init_ui()
def init_ui(self):
# 窗口基础设置
self.setWindowTitle("用户注册")
self.resize(800, 600) # 窗口大小
self.setStyleSheet("background-color: #f0f2f5;") # 浅灰背景
# ========== 注册表单(居中显示) ==========
# 表单容器(带白色背景和阴影,增强层次感)
form_container = QWidget()
form_container.setStyleSheet(
"""
QWidget {
background-color: white;
border-radius: 10px;
}
"""
)
form_container.setFixedWidth(466) # 表单固定宽度
# 表单标题
title_label = QLabel("Register")
title_label.setFont(QFont("Microsoft YaHei", 18, QFont.Bold))
title_label.setAlignment(Qt.AlignCenter)
title_label.setStyleSheet("margin: 20px 0; color: #333;")
# 注册控件
self.account_edit = LineEdit()
self.account_edit.setPlaceholderText("请输入账号")
self.password_edit = LineEdit()
self.password_edit.setEchoMode(QLineEdit.Password)
self.password_edit.setPlaceholderText("请输入密码")
self.confirm_edit = LineEdit()
self.confirm_edit.setEchoMode(QLineEdit.Password)
self.confirm_edit.setPlaceholderText("请确认密码")
# 权限选择(调试人员 + 车间主管)
self.permission_combo = ComboBox()
self.permission_combo.addItems(["调试人员", "车间主管"])
# 确认按钮(红色样式)
self.confirm_btn = PushButton("确认")
self.confirm_btn.setCursor(Qt.PointingHandCursor)
# 表单布局QFormLayout 自动对齐标签和输入框)
form_layout = QFormLayout()
form_layout.addRow("账号:", self.account_edit)
form_layout.addRow("密码:", self.password_edit)
form_layout.addRow("确认密码:", self.confirm_edit)
form_layout.addRow("权限:", self.permission_combo)
form_layout.setVerticalSpacing(16) # 行间距
form_layout.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter) # 标签右对齐
# 表单容器内部布局(垂直排列标题、表单、按钮)
container_layout = QVBoxLayout(form_container)
container_layout.addWidget(title_label)
container_layout.addLayout(form_layout)
container_layout.addWidget(self.confirm_btn, alignment=Qt.AlignCenter)
container_layout.setContentsMargins(30, 10, 30, 30) # 容器内边距
container_layout.setSpacing(20) # 控件间距
# ========== 主布局(让表单居中显示) ==========
main_layout = QVBoxLayout(self)
# 顶部和底部添加弹簧,实现垂直居中
main_layout.addItem(
QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)
)
main_layout.addWidget(form_container, alignment=Qt.AlignCenter) # 表单水平居中
main_layout.addItem(
QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)
)
# 左右留空(可选,控制表单左右边距)
main_layout.setContentsMargins(50, 50, 50, 50)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = RegistrationUI()
window.show()
sys.exit(app.exec())

96
test_teachhtml.py Normal file
View File

@ -0,0 +1,96 @@
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl, QTimer
# 示教器页面
class TeachBrowser(QWidget):
def __init__(
self,
parent=None,
url="http://192.168.58.2/login.html",
username="admin",
password="123",
):
super().__init__(parent=parent)
self.setWindowTitle("示教器页面")
# self.setGeometry(100, 100, 1024, 768)
# 1. 配置登录信息
self.login_username = username # 登录的用户名
self.login_password = password # 登录的密码
# 2. 初始化浏览器视图
self.web_view = QWebEngineView()
# 加载登录页面
self.web_view.load(QUrl(url))
# 3. 绑定网页加载完成信号
self.web_view.loadFinished.connect(self.onPageLoaded)
# 4. 设置窗口布局
layout = QVBoxLayout(self)
layout.addWidget(self.web_view)
def onPageLoaded(self, success):
"""页面加载完成后,执行登录逻辑"""
if not success:
# print("登录页面加载失败!")
return
self.injectLoginJs()
self.web_view.loadFinished.disconnect(self.onPageLoaded)
def injectLoginJs(self):
"""注入 JavaScript 代码,自动输入用户名和密码"""
auto_login_js = f"""
// 1. 等待 AngularJS 完全初始化(确保能获取到 scope
function waitForAngular() {{
return new Promise((resolve) => {{
const checkAngular = () => {{
// 判断 Angular 是否加载完成且登录表单if_Login0已显示
if (window.angular && document.querySelector('#loginForm')) {{
resolve();
}} else {{
setTimeout(checkAngular, 200); // 每 200ms 检查一次
}}
}};
checkAngular();
}});
}}
// 2. 核心登录逻辑
async function autoLogin() {{
await waitForAngular(); // 等待 Angular 初始化
// 获取第一个登录表单id="loginForm"ng-if="if_Login0")的 Angular 作用域
const loginForm = document.querySelector('#loginForm');
const scope = window.angular.element(loginForm).scope();
if (!scope) {{
return;
}}
// 3. 填充用户名和密码(对应 ng-model="$parent.userName""$parent.password"
scope.$apply(() => {{
scope.$parent.userName = "{self.login_username}"; // 用户名
scope.$parent.password = "{self.login_password}"; // 密码
}});
}}
// 执行登录
autoLogin();
"""
# 执行注入的 JS 代码
self.web_view.page().runJavaScript(auto_login_js)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = TeachBrowser()
window.show()
sys.exit(app.exec())