-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.py
More file actions
207 lines (177 loc) · 7.23 KB
/
Copy pathMainWindow.py
File metadata and controls
207 lines (177 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# coding:utf-8
"""
Online Bookstore Management System
----------------------------------
Developed by: Yiwei Lyu
GitHub: https://github.com/POEG1726
GitHub Repository: https://github.com/POEG1726/BookStoreManagementSystem
This Online Bookstore Management System is designed to facilitate the management and purchase of books online.
It features a responsive and accessible user interface developed with PySide6 and Python 3.9, alongside a backend
leveraging JSON for efficient data storage and retrieval. This system allows users to browse, search, and purchase
books and provides administrators with tools to manage inventory, orders, and customer information efficiently.
Technical Stack:
- Frontend: PySide6 with QFluentWidgets, ensuring a smooth graphical user interface.
- Backend: Python 3.9, handling logic for user management, data inquiry, and order processing.
- Database: JSON files used for storing data related to books, users, and transactions.
Usage:
Run `MainWindow.py` to launch the application. Ensure all dependencies are installed as per the README instructions.
"""
import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QColor, QPixmap
from PySide6.QtWidgets import (
QApplication,
QFrame,
QHBoxLayout,
QLabel,
QSizePolicy,
QMessageBox,
)
from qfluentwidgets import FluentBackgroundTheme
from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets import FluentWindow, SplitTitleBar, setThemeColor
from qframelesswindow import FramelessWindow as Window
from Backend import *
from Cart import CartInterface
from Home import HomeInterface
from Management import ManagementInterface
from WindowUI import Login_Ui_Form, Register_Ui_Form
class LoginWindow(Window, Login_Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
setThemeColor("#28afe9")
self.setTitleBar(SplitTitleBar(self))
self.titleBar.raise_()
self.label.setScaledContents(False)
self.setWindowTitle("Book Store -Login")
self.resize(1000, 650)
color = QColor(240, 244, 249)
self.setStyleSheet(f"LoginWindow{{background: {color.name()}}}")
desktop = QApplication.screens()[0].availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
def bind(self):
self.pushButton.clicked.connect(self.login)
self.pushButton_2.clicked.connect(self.registration)
self.lineEdit_4.returnPressed.connect(self.login)
def resizeEvent(self, e):
super().resizeEvent(e)
pixmap = QPixmap(":/images/resource/images/BookStoreBackground.jpg").scaled(
self.label.size(), Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation
)
self.label.setPixmap(pixmap)
def login(self):
email = self.lineEdit_3.text()
password = self.lineEdit_4.text()
res = authorization(email, password)
if res[0]:
QMessageBox.information(self, "Login Success", "You are logged in!")
Main = Window(user_id=res[1])
Main.show()
self.close()
else:
QMessageBox.warning(self, "Login Failed", "Incorrect email or password.")
def registration(self):
tmp = register()
tmp.show()
self.close()
class register(Window, Register_Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
setThemeColor("#28afe9")
self.setTitleBar(SplitTitleBar(self))
self.titleBar.raise_()
self.label.setScaledContents(False)
self.setWindowTitle("Book Store -Registration")
self.resize(1000, 650)
color = QColor(240, 244, 249)
self.setStyleSheet(f"LoginWindow{{background: {color.name()}}}")
desktop = QApplication.screens()[0].availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
self.pushButton_2.clicked.connect(self.reg)
self.lineEdit_4.returnPressed.connect(self.reg)
def resizeEvent(self, e):
super().resizeEvent(e)
pixmap = QPixmap(":/images/resource/images/BookStoreBackground.jpg").scaled(
self.label.size(), Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation
)
self.label.setPixmap(pixmap)
def reg(self):
name = self.lineEdit.text()
email = self.lineEdit_3.text()
password = self.lineEdit_4.text()
res = add_user(name=name, email=email, password=password)
if res:
QMessageBox.information(
self, "Registration", "Registration successful! Logging you in..."
)
Main = Window(user_id=res[1])
Main.show()
self.close()
return
else:
QMessageBox.warning(self, "User is already existed!")
self.close() # Close the registration window
class Widget(QFrame):
def __init__(self, text: str, parent=None):
super().__init__(parent=parent)
self.label = QLabel(text, self)
self.label.setStyleSheet(
"""font-size: 30px;
color: green;"""
)
self.hBoxLayout = QHBoxLayout(self)
# setFont(self.label, 24)
self.label.setAlignment(Qt.AlignCenter)
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
self.setObjectName(text.replace(" ", "-"))
class Window(FluentWindow):
def __init__(self, user_id: str):
super().__init__()
# create sub interface
self.user = look_up_user(user_id=user_id)
self.homeInterface = HomeInterface(self)
self.cartInterface = CartInterface(self)
self.managementInterface = ManagementInterface(self)
self.initNavigation()
self.initWindow()
self.stackedWidget.currentChanged.connect(self.reload_page)
def reload_page(self, index):
if index == 1:
self.cartInterface.reload()
self.homeInterface.reload()
# if index == 2:
# if self.user['permission'] == 'user':
# self.managementInterface.reload()
def initNavigation(self):
self.addSubInterface(self.homeInterface, FIF.HOME, "Home")
self.addSubInterface(self.cartInterface, FIF.SHOPPING_CART, "Cart")
if self.user["permission"] == "admin":
self.addSubInterface(self.managementInterface, FIF.SETTING, "Management")
else:
self.addSubInterface(
Widget("You Are Not Admin!!!", self), FIF.SETTING, "Management"
)
def initWindow(self):
# self.resize(940, 700)
self.setFixedSize(940,700)
self.setWindowTitle(f"Book Store User: {self.user['email']}")
# self.setWindowIcon(QI)
desktop = QApplication.screens()[0].availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
self.setCustomBackgroundColor(*FluentBackgroundTheme.DEFAULT_BLUE)
if __name__ == "__main__":
app = QApplication(sys.argv)
debug = False
if debug == True:
Main = Window(user_id="0008bc60")
Main.show()
else:
login = LoginWindow()
login.show()
app.exec()