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.
189 lines
6.3 KiB
189 lines
6.3 KiB
import sys
|
|
|
|
from PySide6.QtCore import Signal
|
|
from PySide6.QtGui import Qt
|
|
from PySide6.QtWidgets import QLabel, QFrame, QPushButton, QVBoxLayout, QHBoxLayout, QApplication
|
|
|
|
from app.common.Manager import UserManager
|
|
from qfluentwidgets import FluentStyleSheet, PrimaryPushButton, TextWrap, LineEdit, InfoBar, InfoBarPosition
|
|
|
|
from qfluentwidgets.components.dialog_box.dialog import Ui_MessageBox
|
|
from qframelesswindow import FramelessDialog
|
|
|
|
|
|
class AddBookBox:
|
|
yesSignal = Signal()
|
|
cancelSignal = Signal()
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
|
|
def _setUpUi(self, title, parent):
|
|
self.titleLabel = QLabel(title, parent)
|
|
|
|
self.ISBN = LineEdit()
|
|
self.ISBNBox = QHBoxLayout()
|
|
self.ISBN_text = QLabel('ISBN', parent)
|
|
self.ISBNBox.addWidget(self.ISBN_text)
|
|
self.ISBNBox.addWidget(self.ISBN)
|
|
|
|
self.name = LineEdit()
|
|
self.nameBox = QHBoxLayout()
|
|
self.name_text = QLabel('书名', parent)
|
|
self.nameBox.addWidget(self.name_text)
|
|
self.nameBox.addWidget(self.name)
|
|
|
|
self.author = LineEdit()
|
|
self.authorBox = QHBoxLayout()
|
|
self.author_text = QLabel('作者', parent)
|
|
self.authorBox.addWidget(self.author_text)
|
|
self.authorBox.addWidget(self.author)
|
|
|
|
self.category = LineEdit()
|
|
self.categoryBox = QHBoxLayout()
|
|
self.category_text = QLabel('分类', parent)
|
|
self.categoryBox.addWidget(self.category_text)
|
|
self.categoryBox.addWidget(self.category)
|
|
|
|
self.buttonGroup = QFrame(parent)
|
|
self.yesButton = PrimaryPushButton(self.tr('OK'), self.buttonGroup)
|
|
self.cancelButton = QPushButton(self.tr('Cancel'), self.buttonGroup)
|
|
|
|
self.vBoxLayout = QVBoxLayout(parent)
|
|
self.textLayout = QVBoxLayout()
|
|
self.buttonLayout = QHBoxLayout(self.buttonGroup)
|
|
|
|
self.__initWidget()
|
|
|
|
def __initWidget(self):
|
|
self.__setQss()
|
|
self.__initLayout()
|
|
|
|
# fixes https://github.com/zhiyiYo/PyQt-Fluent-Widgets/issues/19
|
|
self.yesButton.setAttribute(Qt.WA_LayoutUsesWidgetRect)
|
|
self.cancelButton.setAttribute(Qt.WA_LayoutUsesWidgetRect)
|
|
|
|
self.yesButton.setFocus()
|
|
self.buttonGroup.setFixedHeight(81)
|
|
|
|
self._adjustText()
|
|
|
|
#self.yesButton.clicked.connect(self.__onYesButtonClicked)
|
|
self.cancelButton.clicked.connect(self.__onCancelButtonClicked)
|
|
|
|
def _adjustText(self):
|
|
if self.isWindow():
|
|
if self.parent():
|
|
w = max(self.titleLabel.width(), self.parent().width())
|
|
chars = max(min(w / 9, 140), 30)
|
|
else:
|
|
chars = 100
|
|
else:
|
|
w = max(self.titleLabel.width(), self.window().width())
|
|
chars = max(min(w / 9, 100), 30)
|
|
|
|
#self.contentLabel.setText(TextWrap.wrap(self.content, chars, False)[0])
|
|
|
|
def __initLayout(self):
|
|
self.vBoxLayout.setSpacing(0)
|
|
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
|
|
self.vBoxLayout.addLayout(self.textLayout, 1)
|
|
|
|
self.vBoxLayout.addLayout(self.ISBNBox)
|
|
self.vBoxLayout.addLayout(self.nameBox)
|
|
self.vBoxLayout.addLayout(self.authorBox)
|
|
self.vBoxLayout.addLayout(self.categoryBox)
|
|
|
|
self.vBoxLayout.addWidget(self.buttonGroup, 0, Qt.AlignBottom)
|
|
self.vBoxLayout.setSizeConstraint(QVBoxLayout.SetMinimumSize)
|
|
|
|
self.textLayout.setSpacing(12)
|
|
self.textLayout.setContentsMargins(24, 24, 24, 24)
|
|
self.textLayout.addWidget(self.titleLabel, 0, Qt.AlignTop)
|
|
|
|
|
|
self.ISBNBox.setContentsMargins(24, 24, 24, 24)
|
|
self.authorBox.setContentsMargins(24, 24, 24, 24)
|
|
self.nameBox.setContentsMargins(24, 24, 24, 24)
|
|
self.categoryBox.setContentsMargins(24, 24, 24, 24)
|
|
|
|
self.buttonLayout.setSpacing(12)
|
|
self.buttonLayout.setContentsMargins(24, 24, 24, 24)
|
|
self.buttonLayout.addWidget(self.yesButton, 1, Qt.AlignVCenter)
|
|
self.buttonLayout.addWidget(self.cancelButton, 1, Qt.AlignVCenter)
|
|
|
|
def __onCancelButtonClicked(self):
|
|
self.reject()
|
|
self.cancelSignal.emit()
|
|
|
|
def __onYesButtonClicked(self):
|
|
self.accept()
|
|
self.yesSignal.emit()
|
|
|
|
def __setQss(self):
|
|
self.titleLabel.setObjectName("titleLabel")
|
|
self.buttonGroup.setObjectName('buttonGroup')
|
|
self.cancelButton.setObjectName('cancelButton')
|
|
|
|
FluentStyleSheet.DIALOG.apply(self)
|
|
|
|
self.yesButton.adjustSize()
|
|
self.cancelButton.adjustSize()
|
|
|
|
|
|
class AddBookDialog(FramelessDialog, AddBookBox):
|
|
yesSignal = Signal()
|
|
cancelSignal = Signal()
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent=parent)
|
|
self._setUpUi("图书录入", self)
|
|
|
|
self.windowTitleLabel = QLabel("图书录入", self)
|
|
|
|
self.setResizeEnabled(False)
|
|
self.resize(540, 192)
|
|
self.titleBar.hide()
|
|
|
|
self.vBoxLayout.insertWidget(0, self.windowTitleLabel, 0, Qt.AlignTop)
|
|
self.windowTitleLabel.setObjectName('windowTitleLabel')
|
|
FluentStyleSheet.DIALOG.apply(self)
|
|
self.setFixedSize(self.size())
|
|
|
|
self.yesButton.clicked.connect(self.addBook)
|
|
|
|
def setTitleBarVisible(self, isVisible: bool):
|
|
self.windowTitleLabel.setVisible(isVisible)
|
|
|
|
def addBook(self):
|
|
isbn = self.ISBN.text()
|
|
author = self.author.text()
|
|
name = self.name.text()
|
|
category = self.category.text()
|
|
|
|
if isbn == '' or author == '' or name == '' or category == '':
|
|
InfoBar.warning(
|
|
title='操作失败',
|
|
content="你填写的内容不够完全!",
|
|
orient=Qt.Horizontal,
|
|
isClosable=False, # disable close button
|
|
position=InfoBarPosition.TOP_LEFT,
|
|
duration=2000,
|
|
parent=self
|
|
)
|
|
else:
|
|
UserManager.addBookInfo(isbn, name, author, category)
|
|
self.ISBN.clear()
|
|
self.author.clear()
|
|
self.name.clear()
|
|
self.category.clear()
|
|
InfoBar.success(
|
|
title='录入书籍信息成功',
|
|
content="录入书籍信息成功,你可以继续添加书籍或退出此界面.",
|
|
orient=Qt.Horizontal,
|
|
isClosable=True,
|
|
position=InfoBarPosition.TOP,
|
|
duration=2000,
|
|
parent=self
|
|
)
|