密胺制品的登录界面(实现了布局和拉伸,支持两种用户登录验证)

This commit is contained in:
2025-08-26 09:21:41 +08:00
parent 4c66886257
commit c76389f863
5 changed files with 2207 additions and 46 deletions

149
main.py
View File

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