密胺制品的登录界面(实现了布局和拉伸,支持两种用户登录验证)
This commit is contained in:
1197
app/view/cood_forms_interface.py
Normal file
1197
app/view/cood_forms_interface.py
Normal file
File diff suppressed because it is too large
Load Diff
145
main.py
145
main.py
@ -1,11 +1,39 @@
|
|||||||
# coding:utf-8
|
# coding:utf-8
|
||||||
import sys
|
import sys
|
||||||
from PySide6.QtCore import Qt, QRect, QUrl
|
import os
|
||||||
from PySide6.QtGui import QIcon, QPainter, QImage, QBrush, QColor, QFont, QDesktopServices
|
import sqlite3
|
||||||
from PySide6.QtWidgets import QApplication, QFrame, QStackedWidget, QHBoxLayout, QLabel
|
from PySide6.QtCore import Qt, QRect, QUrl, Signal
|
||||||
|
from PySide6.QtGui import (
|
||||||
|
QIcon,
|
||||||
|
QPainter,
|
||||||
|
QImage,
|
||||||
|
QBrush,
|
||||||
|
QColor,
|
||||||
|
QFont,
|
||||||
|
QDesktopServices,
|
||||||
|
)
|
||||||
|
from PySide6.QtWidgets import (
|
||||||
|
QApplication,
|
||||||
|
QFrame,
|
||||||
|
QStackedWidget,
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QWidget,
|
||||||
|
)
|
||||||
|
|
||||||
from qfluentwidgets import (NavigationInterface, NavigationItemPosition, NavigationWidget, MessageBox,
|
from qfluentwidgets import (
|
||||||
isDarkTheme, setTheme, Theme, setThemeColor, qrouter, FluentWindow, NavigationAvatarWidget)
|
NavigationInterface,
|
||||||
|
NavigationItemPosition,
|
||||||
|
NavigationWidget,
|
||||||
|
MessageBox,
|
||||||
|
isDarkTheme,
|
||||||
|
setTheme,
|
||||||
|
Theme,
|
||||||
|
setThemeColor,
|
||||||
|
qrouter,
|
||||||
|
FluentWindow,
|
||||||
|
NavigationAvatarWidget,
|
||||||
|
)
|
||||||
from qfluentwidgets import FluentIcon as FIF
|
from qfluentwidgets import FluentIcon as FIF
|
||||||
from qframelesswindow import FramelessWindow, StandardTitleBar
|
from qframelesswindow import FramelessWindow, StandardTitleBar
|
||||||
|
|
||||||
@ -14,6 +42,9 @@ from app.view.produce_interface import ProduceInterface
|
|||||||
from app.view.text_interface import TextInterface
|
from app.view.text_interface import TextInterface
|
||||||
from app.view.data_interface import DataInterface
|
from app.view.data_interface import DataInterface
|
||||||
|
|
||||||
|
from app.view.cood_forms_interface import CoodFormsInterface
|
||||||
|
|
||||||
|
|
||||||
class Widget(QFrame):
|
class Widget(QFrame):
|
||||||
|
|
||||||
def __init__(self, text: str, parent=None):
|
def __init__(self, text: str, parent=None):
|
||||||
@ -22,11 +53,12 @@ class Widget(QFrame):
|
|||||||
self.label.setAlignment(Qt.AlignCenter)
|
self.label.setAlignment(Qt.AlignCenter)
|
||||||
self.hBoxLayout = QHBoxLayout(self)
|
self.hBoxLayout = QHBoxLayout(self)
|
||||||
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
|
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
|
||||||
self.setObjectName(text.replace(' ', '-'))
|
self.setObjectName(text.replace(" ", "-"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Window(FramelessWindow):
|
class Window(FramelessWindow):
|
||||||
|
## 定义信号:调整高度
|
||||||
|
heightChanged = Signal(int)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -43,15 +75,15 @@ class Window(FramelessWindow):
|
|||||||
self.stackWidget = QStackedWidget(self)
|
self.stackWidget = QStackedWidget(self)
|
||||||
|
|
||||||
# create sub interface
|
# create sub interface
|
||||||
# self.system = SystemInterface(self)
|
self.system = SystemInterface(self)
|
||||||
# self.product = ProduceInterface(self)
|
self.product = ProduceInterface(self)
|
||||||
# self.robot = Widget('机械臂基础设置', self)
|
self.robot = Widget("机械臂基础设置", self) # 暂时不用
|
||||||
# self.io = Widget('IO面板', self)
|
self.io = Widget("IO面板", self) # 需要完成
|
||||||
# self.position = Widget('位置设定', self)
|
self.position = CoodFormsInterface(self) # 位置设定
|
||||||
# self.basic = Widget('基础设置', self)
|
self.basic = Widget("基础设置", self) # 需要完成
|
||||||
# self.point = Widget('点位调试', self)
|
self.point = Widget("点位调试", self)
|
||||||
# self.other = Widget('其他设置', self)
|
self.other = Widget("其他设置", self)
|
||||||
self.data=DataInterface(self)
|
self.data = DataInterface(self)
|
||||||
|
|
||||||
# initialize layout
|
# initialize layout
|
||||||
self.initLayout()
|
self.initLayout()
|
||||||
@ -73,18 +105,30 @@ class Window(FramelessWindow):
|
|||||||
# self.navigationInterface.setAcrylicEnabled(True)
|
# self.navigationInterface.setAcrylicEnabled(True)
|
||||||
|
|
||||||
# self.addSubInterface 加入导航栏页面
|
# self.addSubInterface 加入导航栏页面
|
||||||
# self.addSubInterface(self.system, FIF.SETTING, '系统设置', NavigationItemPosition.SCROLL)
|
self.addSubInterface(
|
||||||
# self.addSubInterface(self.product, FIF.COMPLETED, '生产界面', parent=self.system)
|
self.system, FIF.SETTING, "系统设置", NavigationItemPosition.SCROLL
|
||||||
# self.addSubInterface(self.robot, FIF.ROBOT, '机械臂基础设置', parent=self.system)
|
)
|
||||||
# self.addSubInterface(self.io, FIF.GAME, 'IO面板', parent=self.system)
|
self.addSubInterface(
|
||||||
# self.addSubInterface(self.position, FIF.IOT, '位置设定', parent=self.system)
|
self.product, FIF.COMPLETED, "生产界面", parent=self.system
|
||||||
# self.addSubInterface(self.basic, FIF.DEVELOPER_TOOLS, '基础设置', parent=self.system)
|
)
|
||||||
# self.addSubInterface(self.point, FIF.MOVE, '点位调试', parent=self.system)
|
self.addSubInterface(
|
||||||
#
|
self.robot, FIF.ROBOT, "机械臂基础设置", parent=self.system
|
||||||
# self.navigationInterface.addSeparator()
|
)
|
||||||
#self.addSubInterface(self.other, FIF.APPLICATION, '其他设置', NavigationItemPosition.SCROLL)
|
self.addSubInterface(self.io, FIF.GAME, "IO面板", parent=self.system)
|
||||||
|
self.addSubInterface(self.position, FIF.IOT, "位置设定", parent=self.system)
|
||||||
|
self.addSubInterface(
|
||||||
|
self.basic, FIF.DEVELOPER_TOOLS, "基础设置", parent=self.system
|
||||||
|
)
|
||||||
|
self.addSubInterface(self.point, FIF.MOVE, "点位调试", parent=self.system)
|
||||||
|
|
||||||
self.addSubInterface(self.data, FIF.PHOTO, '数据采集', NavigationItemPosition.SCROLL)
|
# self.navigationInterface.addSeparator()
|
||||||
|
self.addSubInterface(
|
||||||
|
self.other, FIF.APPLICATION, "其他设置", NavigationItemPosition.SCROLL
|
||||||
|
)
|
||||||
|
|
||||||
|
self.addSubInterface(
|
||||||
|
self.data, FIF.PHOTO, "数据采集", NavigationItemPosition.SCROLL
|
||||||
|
)
|
||||||
# add navigation items to scroll area
|
# add navigation items to scroll area
|
||||||
# for i in range(1, 21):
|
# for i in range(1, 21):
|
||||||
# self.navigationInterface.addItem(
|
# self.navigationInterface.addItem(
|
||||||
@ -97,8 +141,8 @@ class Window(FramelessWindow):
|
|||||||
|
|
||||||
# add custom widget to bottom
|
# add custom widget to bottom
|
||||||
self.navigationInterface.addWidget(
|
self.navigationInterface.addWidget(
|
||||||
routeKey='avatar',
|
routeKey="avatar",
|
||||||
widget=NavigationAvatarWidget('zhiyiYo', 'resource/shoko.png'),
|
widget=NavigationAvatarWidget("zhiyiYo", "resource/shoko.png"),
|
||||||
onClick=self.showMessageBox,
|
onClick=self.showMessageBox,
|
||||||
position=NavigationItemPosition.BOTTOM,
|
position=NavigationItemPosition.BOTTOM,
|
||||||
)
|
)
|
||||||
@ -117,13 +161,13 @@ class Window(FramelessWindow):
|
|||||||
|
|
||||||
def initWindow(self):
|
def initWindow(self):
|
||||||
self.resize(900, 700)
|
self.resize(900, 700)
|
||||||
self.setWindowIcon(QIcon('resource/logo.png'))
|
self.setWindowIcon(QIcon("resource/logo.png"))
|
||||||
self.setWindowTitle('密胺投料控制系统')
|
self.setWindowTitle("密胺投料控制系统")
|
||||||
self.titleBar.setAttribute(Qt.WA_StyledBackground)
|
self.titleBar.setAttribute(Qt.WA_StyledBackground)
|
||||||
|
|
||||||
desktop = QApplication.screens()[0].availableGeometry()
|
desktop = QApplication.screens()[0].availableGeometry()
|
||||||
w, h = desktop.width(), desktop.height()
|
w, h = desktop.width(), desktop.height()
|
||||||
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
|
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
|
||||||
|
|
||||||
# NOTE: set the minimum window width that allows the navigation panel to be expanded
|
# NOTE: set the minimum window width that allows the navigation panel to be expanded
|
||||||
self.navigationInterface.setMinimumExpandWidth(900)
|
self.navigationInterface.setMinimumExpandWidth(900)
|
||||||
@ -131,8 +175,15 @@ class Window(FramelessWindow):
|
|||||||
|
|
||||||
self.setQss()
|
self.setQss()
|
||||||
|
|
||||||
def addSubInterface(self, interface, icon, text: str, position=NavigationItemPosition.TOP, parent=None):
|
def addSubInterface(
|
||||||
""" add sub interface """
|
self,
|
||||||
|
interface,
|
||||||
|
icon,
|
||||||
|
text: str,
|
||||||
|
position=NavigationItemPosition.TOP,
|
||||||
|
parent=None,
|
||||||
|
):
|
||||||
|
"""add sub interface"""
|
||||||
self.stackWidget.addWidget(interface)
|
self.stackWidget.addWidget(interface)
|
||||||
self.navigationInterface.addItem(
|
self.navigationInterface.addItem(
|
||||||
routeKey=interface.objectName(),
|
routeKey=interface.objectName(),
|
||||||
@ -141,12 +192,12 @@ class Window(FramelessWindow):
|
|||||||
onClick=lambda: self.switchTo(interface),
|
onClick=lambda: self.switchTo(interface),
|
||||||
position=position,
|
position=position,
|
||||||
tooltip=text,
|
tooltip=text,
|
||||||
parentRouteKey=parent.objectName() if parent else None
|
parentRouteKey=parent.objectName() if parent else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setQss(self):
|
def setQss(self):
|
||||||
color = 'dark' if isDarkTheme() else 'light'
|
color = "dark" if isDarkTheme() else "light"
|
||||||
with open(f'resource/{color}/demo.qss', encoding='utf-8') as f:
|
with open(f"resource/{color}/demo.qss", encoding="utf-8") as f:
|
||||||
self.setStyleSheet(f.read())
|
self.setStyleSheet(f.read())
|
||||||
|
|
||||||
def switchTo(self, widget):
|
def switchTo(self, widget):
|
||||||
@ -159,21 +210,27 @@ class Window(FramelessWindow):
|
|||||||
#!IMPORTANT: This line of code needs to be uncommented if the return button is enabled
|
#!IMPORTANT: This line of code needs to be uncommented if the return button is enabled
|
||||||
# qrouter.push(self.stackWidget, widget.objectName())
|
# qrouter.push(self.stackWidget, widget.objectName())
|
||||||
|
|
||||||
|
def resizeEvent(self, event):
|
||||||
|
super().resizeEvent(event)
|
||||||
|
self.heightChanged.emit(self.height())
|
||||||
|
|
||||||
def showMessageBox(self):
|
def showMessageBox(self):
|
||||||
w = MessageBox(
|
w = MessageBox(
|
||||||
'支持作者🥰',
|
"支持作者🥰",
|
||||||
'个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
|
"个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀",
|
||||||
self
|
self,
|
||||||
)
|
)
|
||||||
w.yesButton.setText('来啦老弟')
|
w.yesButton.setText("来啦老弟")
|
||||||
w.cancelButton.setText('下次一定')
|
w.cancelButton.setText("下次一定")
|
||||||
|
|
||||||
if w.exec():
|
if w.exec():
|
||||||
QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))
|
QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
# 初始化数据库
|
||||||
|
# init_database()
|
||||||
|
app = QApplication([])
|
||||||
w = Window()
|
w = Window()
|
||||||
w.show()
|
w.show()
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|||||||
BIN
resource/login.png
Normal file
BIN
resource/login.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 162 KiB |
401
test_login1.py
Normal file
401
test_login1.py
Normal 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
506
test_login2.py
Normal 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())
|
||||||
Reference in New Issue
Block a user