-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.py
126 lines (104 loc) · 3.49 KB
/
Home.py
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
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel, QSizePolicy
from qfluentwidgets import ScrollArea
from BookCard import BookCardView
from Backend import *
class ToolBar(QWidget):
"""Tool bar"""
def __init__(self, title, subtitle, parent=None):
super().__init__(parent=parent)
self.titleLabel = QLabel(title, self)
self.titleLabel.setObjectName("TitleLabel")
self.subtitleLabel = QLabel(subtitle, self)
self.subtitleLabel.setObjectName("SubtitleLabel")
self.vBoxLayout = QVBoxLayout(self)
self.__initWidget()
def __initWidget(self):
self.setFixedHeight(80)
self.vBoxLayout.setSpacing(0)
self.vBoxLayout.setContentsMargins(36, 36, 36, 0)
self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addSpacing(4)
self.vBoxLayout.addWidget(self.subtitleLabel)
# self.vBoxLayout.addSpacing(4)
self.vBoxLayout.setAlignment(Qt.AlignTop)
class HomeInterface(ScrollArea):
"""Home interface"""
def __init__(self, parent=None):
super().__init__(parent=parent)
if parent:
self.parent = parent
self.BookCardView = None
self.view = QWidget(self)
self.vBoxLayout = QVBoxLayout(self.view)
# TitleLabel = QLabel(self)
# TitleLabel.setText("Home Interface")
# TitleLabel.setStyleSheet("""font-size: 24px;""")
# TitleLabel.setContentsMargins(36, 10, 0, 0)
# self.vBoxLayout.addWidget(TitleLabel)
self.toolBar = ToolBar("Home Interface", "Click to add book to your cart", self)
self.setViewportMargins(0, self.toolBar.height(), 0, 0)
# SubTitleLabel = QLabel(self)
# SubTitleLabel.setText("Double Click to add book to your cart")
# SubTitleLabel.setStyleSheet("""font-size: 16px;""")
# SubTitleLabel.setContentsMargins(36, 10, 0, 0)
# self.vBoxLayout.addWidget(SubTitleLabel)
self.__initWidget()
def __initWidget(self):
self.view.setObjectName("view")
self.setObjectName("homeInterface")
self.setStyleSheet(
"""SettingInterface,
#view {
background-color: transparent;
}
QScrollArea {
border: none;
background-color: transparent;
}
BannerWidget > #galleryLabel {
font: 42px;
background-color: transparent;
color: black;
padding-left: 28px;
}
CartCardView {
background-color: transparent;
}
ToolBar > #TitleLabel {
color: black;
font: 28px;
}
ToolBar > #SubtitleLabel {
font: 14px;
color: rgb(96, 96, 96);
}
TitleLabel {
color: black;
}
"""
)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setWidget(self.view)
self.setWidgetResizable(True)
self.vBoxLayout.setContentsMargins(0, 30, 0, 36)
# self.vBoxLayout.setSpacing(40)
self.vBoxLayout.setAlignment(Qt.AlignTop)
self.Books = loadBooks()
self.BookCardView = BookCardView(self)
self.vBoxLayout.addWidget(
self.BookCardView,
1,
)
self.Add_ALL_Book_To_Screen()
def Add_ALL_Book_To_Screen(self):
for id, book in self.Books.items():
self.BookCardView.addCard(
title=book["name"],
content=book["desc"],
book_id=id,
)
def reload(self):
self.BookCardView.flowLayout.takeAllWidgets()
self.Books = loadBooks()
self.Add_ALL_Book_To_Screen()