You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
6.7 KiB
190 lines
6.7 KiB
2 years ago
|
# coding: utf-8
|
||
|
from typing import List
|
||
|
from PySide6.QtCore import Qt, Signal, QEasingCurve, QUrl
|
||
|
from PySide6.QtGui import QIcon, QDesktopServices
|
||
|
from PySide6.QtWidgets import QApplication, QHBoxLayout, QFrame, QWidget
|
||
|
|
||
|
from qfluentwidgets import (NavigationInterface, NavigationItemPosition, MessageBox,
|
||
|
isDarkTheme, PopUpAniStackedWidget, qrouter)
|
||
|
from qfluentwidgets import FluentIcon as FIF
|
||
|
from qframelesswindow import FramelessWindow
|
||
|
|
||
|
from .admin_interface import AdminTools
|
||
|
from .borrow_return_interface import BorrowAndReturn
|
||
|
from .index_interface import IndexInterface
|
||
|
from .login_window import LoginWindow
|
||
|
from .setting_interface import SettingInterface
|
||
|
|
||
|
from .title_bar import CustomTitleBar
|
||
|
from .gallery_interface import GalleryInterface
|
||
|
from .home_interface import HomeInterface
|
||
|
from .user_record_interface import UserRecordInterface
|
||
|
from ..common.Manager import UserManager
|
||
|
from ..common.config import SUPPORT_URL
|
||
|
from ..components.avatar_widget import AvatarWidget
|
||
|
from ..common.icon import Icon
|
||
|
from ..common.signal_bus import signalBus
|
||
|
from ..common.style_sheet import StyleSheet
|
||
|
from ..common import resource
|
||
|
|
||
|
|
||
|
class StackedWidget(QFrame):
|
||
|
""" Stacked widget """
|
||
|
|
||
|
currentWidgetChanged = Signal(QWidget)
|
||
|
|
||
|
def __init__(self, parent=None):
|
||
|
super().__init__(parent=parent)
|
||
|
self.hBoxLayout = QHBoxLayout(self)
|
||
|
self.view = PopUpAniStackedWidget(self)
|
||
|
|
||
|
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
|
||
|
self.hBoxLayout.addWidget(self.view)
|
||
|
|
||
|
self.view.currentChanged.connect(
|
||
|
lambda i: self.currentWidgetChanged.emit(self.view.widget(i)))
|
||
|
|
||
|
def addWidget(self, widget):
|
||
|
""" add widget to view """
|
||
|
self.view.addWidget(widget)
|
||
|
|
||
|
def setCurrentWidget(self, widget, popOut=True):
|
||
|
widget.verticalScrollBar().setValue(0)
|
||
|
if not popOut:
|
||
|
self.view.setCurrentWidget(widget, duration=300)
|
||
|
else:
|
||
|
self.view.setCurrentWidget(
|
||
|
widget, True, False, 200, QEasingCurve.InQuad)
|
||
|
|
||
|
def setCurrentIndex(self, index, popOut=False):
|
||
|
self.setCurrentWidget(self.view.widget(index), popOut)
|
||
|
|
||
|
|
||
|
class MainWindow(FramelessWindow):
|
||
|
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.setTitleBar(CustomTitleBar(self))
|
||
|
self.hBoxLayout = QHBoxLayout(self)
|
||
|
self.widgetLayout = QHBoxLayout()
|
||
|
|
||
|
self.stackWidget = StackedWidget(self)
|
||
|
self.navigationInterface = NavigationInterface(self, True, True)
|
||
|
|
||
|
# create sub interface
|
||
|
self.homeInterface = HomeInterface(self)
|
||
|
self.borrowAndReturnInterface = BorrowAndReturn(self)
|
||
|
self.indexInterface = IndexInterface(self)
|
||
|
|
||
|
self.recordInterface = UserRecordInterface(self)
|
||
|
self.adminTools = AdminTools(self)
|
||
|
|
||
|
self.settingInterface = SettingInterface(self)
|
||
|
|
||
|
# initialize layout
|
||
|
self.initLayout()
|
||
|
|
||
|
# add items to navigation interface
|
||
|
self.initNavigation()
|
||
|
|
||
|
self.initWindow()
|
||
|
|
||
|
self.login_window = LoginWindow(self)
|
||
|
self.login_window.show()
|
||
|
|
||
|
|
||
|
def initLayout(self):
|
||
|
self.hBoxLayout.setSpacing(0)
|
||
|
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
|
||
|
self.hBoxLayout.addWidget(self.navigationInterface)
|
||
|
self.hBoxLayout.addLayout(self.widgetLayout)
|
||
|
self.hBoxLayout.setStretchFactor(self.widgetLayout, 1)
|
||
|
|
||
|
self.widgetLayout.addWidget(self.stackWidget)
|
||
|
self.widgetLayout.setContentsMargins(0, 48, 0, 0)
|
||
|
|
||
|
signalBus.switchToSampleCard.connect(self.switchToSample)
|
||
|
signalBus.supportSignal.connect(self.onSupport)
|
||
|
|
||
|
self.navigationInterface.displayModeChanged.connect(
|
||
|
self.titleBar.raise_)
|
||
|
self.titleBar.raise_()
|
||
|
|
||
|
def initNavigation(self):
|
||
|
self.addSubInterface(
|
||
|
self.homeInterface, 'homeInterface', FIF.HOME, self.tr('Home'), NavigationItemPosition.TOP)
|
||
|
self.navigationInterface.addSeparator()
|
||
|
self.addSubInterface(
|
||
|
self.borrowAndReturnInterface, 'borrowAndReturnInterface', FIF.MESSAGE, self.tr('Borrow And Return')
|
||
|
)
|
||
|
self.addSubInterface(
|
||
|
self.indexInterface, 'indexInterface', FIF.BOOK_SHELF, self.tr('Index Interface')
|
||
|
)
|
||
|
|
||
|
self.addSubInterface(
|
||
|
self.recordInterface, 'recordInterface', FIF.VIEW, self.tr('User Record')
|
||
|
)
|
||
|
self.addSubInterface(
|
||
|
self.adminTools, 'adminTools', FIF.MORE, self.tr('Admin Tools')
|
||
|
)
|
||
|
|
||
|
|
||
|
self.addSubInterface(
|
||
|
self.settingInterface, 'settingInterface', FIF.SETTING, self.tr('Settings'), NavigationItemPosition.BOTTOM)
|
||
|
|
||
|
#!IMPORTANT: don't forget to set the default route key if you enable the return button
|
||
|
qrouter.setDefaultRouteKey(self.stackWidget, self.homeInterface.objectName())
|
||
|
|
||
|
self.stackWidget.currentWidgetChanged.connect(self.onCurrentWidgetChanged)
|
||
|
self.navigationInterface.setCurrentItem(
|
||
|
self.homeInterface.objectName())
|
||
|
self.stackWidget.setCurrentIndex(0)
|
||
|
|
||
|
|
||
|
def addSubInterface(self, interface: QWidget, objectName: str, icon, text: str, position=NavigationItemPosition.SCROLL):
|
||
|
""" add sub interface """
|
||
|
interface.setObjectName(objectName)
|
||
|
self.stackWidget.addWidget(interface)
|
||
|
self.navigationInterface.addItem(
|
||
|
routeKey=objectName,
|
||
|
icon=icon,
|
||
|
text=text,
|
||
|
onClick=lambda t: self.switchTo(interface, t),
|
||
|
position=position,
|
||
|
tooltip=text
|
||
|
)
|
||
|
|
||
|
def initWindow(self):
|
||
|
self.resize(960, 780)
|
||
|
self.setMinimumWidth(760)
|
||
|
self.setWindowIcon(QIcon(':/gallery/images/logo.png'))
|
||
|
self.setWindowTitle('Fluent图书管理系统')
|
||
|
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)
|
||
|
|
||
|
StyleSheet.MAIN_WINDOW.apply(self)
|
||
|
|
||
|
def switchTo(self, widget, triggerByUser=True):
|
||
|
self.stackWidget.setCurrentWidget(widget, not triggerByUser)
|
||
|
|
||
|
def onCurrentWidgetChanged(self, widget: QWidget):
|
||
|
self.navigationInterface.setCurrentItem(widget.objectName())
|
||
|
qrouter.push(self.stackWidget, widget.objectName())
|
||
|
|
||
|
def resizeEvent(self, e):
|
||
|
self.titleBar.move(46, 0)
|
||
|
self.titleBar.resize(self.width()-46, self.titleBar.height())
|
||
|
|
||
|
def onSupport(self):
|
||
|
QDesktopServices.openUrl(QUrl(SUPPORT_URL))
|
||
|
|
||
|
def switchToSample(self, routeKey, index):
|
||
|
""" switch to sample """
|
||
|
interfaces = self.findChildren(GalleryInterface)
|
||
|
for w in interfaces:
|
||
|
if w.objectName() == routeKey:
|
||
|
self.stackWidget.setCurrentWidget(w, False)
|
||
|
w.scrollToCard(index)
|