404 lines
13 KiB
Python
404 lines
13 KiB
Python
from common import *
|
||
|
||
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())
|