-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
197 lines (159 loc) · 7.74 KB
/
Copy pathmain.py
File metadata and controls
197 lines (159 loc) · 7.74 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
import sys
from PyQt6.QtCore import QEasingCurve, QParallelAnimationGroup, QPropertyAnimation, Qt
from PyQt6.QtWidgets import (
QApplication,
QFrame,
QHBoxLayout,
QLabel,
QMainWindow,
QPushButton,
QStackedWidget,
QVBoxLayout,
QWidget,
)
from PyQt6.QtGui import QFont, QIcon, QCursor
from PyQt6.QtCore import QSize, Qt
from src.screens.giveaway_screens.screens import Screen
from src.app_icon import app_window_icon, resource_path
import qtawesome as qta
from style import styling
class MainWindow(QMainWindow):
SIDEBAR_OPEN_WIDTH = 150
SIDEBAR_CLOSED_WIDTH = 62
def __init__(self):
super().__init__()
self.setWindowTitle("buddy")
self.setWindowIcon(app_window_icon())
self.setFixedSize(580, 640)
self._is_sidebar_open = True
self._menu_buttons = []
self._menu_section_labels = []
self._page_index = {}
self._build_ui()
self.setStyleSheet(styling.body)
def _build_ui(self) -> None:
root = QWidget()
self.setCentralWidget(root)
shell = QHBoxLayout(root)
shell.setContentsMargins(0, 0, 0, 0)
shell.setSpacing(0)
self.sidebar = QFrame()
self.sidebar.setObjectName("sidebar")
self.sidebar.setMinimumWidth(0)
self.sidebar.setMaximumWidth(self.SIDEBAR_OPEN_WIDTH)
sidebar_layout = QVBoxLayout(self.sidebar)
sidebar_layout.setContentsMargins(10, 12, 10, 12)
sidebar_layout.setSpacing(8)
self.menu_toggle_btn = QPushButton()
self.menu_toggle_btn.setIcon(qta.icon("fa5s.bars", color="white"))
self.menu_toggle_btn.setToolTip("toggle menubar")
self.menu_toggle_btn.setObjectName("menuToggle")
self.menu_toggle_btn.clicked.connect(self.toggle_sidebar)
sidebar_layout.addWidget(self.menu_toggle_btn)
nav_items = [
("all", " Free Games", "fa5s.tags", styling.all_free_games_section_btn, "black", "All Free to Play Games", Screen.all_games),
("ai", " Chatbot ", "fa5s.robot", styling.ai_chat_section_btn, "black", "AI powered chat", Screen.ai_chat),
("epic_games", " Epic Games", resource_path("icons", "epic_games.png"), styling.epic_games_section_btn, "black", "Epic Games Giveaways", Screen.epic_games),
("steam", " Steam", "fa6b.steam", styling.steam_section_btn, "white", "Steam Giveaways", Screen.steam),
("ubisoft", " Ubisoft", resource_path("icons", "ubisoft.png"), styling.ubisoft_section_btn, "black", "Ubisoft Giveaways", Screen.ubisoft),
("battlenet", " Battlenet", resource_path("icons", "battlenet.png"), styling.battlenet_section_btn, "blue", "Battlenet Giveaways", Screen.battlenet),
("xbox", " Xbox", "fa6b.xbox", styling.xbox_section_btn, "white", "Xbox Gaming Stuff Giveaways", Screen.xbox),
("playstation", " PlayStation", "fa5b.playstation", styling.playstation_section_btn, "black", "PlayStation Gaming Stuff Giveaways", Screen.playstation),
("switch", " Switch", resource_path("icons", "switch.png"), styling.switch_section_btn, "white", "Switch Gaming Stuff Giveaways", Screen.switch),
("android", " Android", "fa6b.android", styling.android_section_btn, "green", "Android Games Giveaways", Screen.android),
("ios", " iOS", "fa6b.apple", styling.ios_section_btn, "white", "iOS Games Giveaways", Screen.ios),
]
self.stack = QStackedWidget()
self.stack.setObjectName("contentArea")
for key, label, icon, style, color, tooltip, page_class in nav_items:
btn = QPushButton(label)
if not icon.startswith("f"):
btn.setIcon(QIcon(icon))
btn.setIconSize(QSize(20, 20))
else:
btn.setIcon(qta.icon(icon, color=color))
btn.setFont(QFont("monospace", 14))
btn.setObjectName(key)
btn.setToolTip(tooltip)
btn.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
btn.setCheckable(True)
btn.setProperty("full_label", label)
btn.setProperty("short_label", label[0])
btn.setStyleSheet(style)
btn.clicked.connect(lambda checked=False, name=key: self.show_page(name))
sidebar_layout.addWidget(btn)
self._menu_buttons.append((key, btn))
page = page_class()
page_idx = self.stack.addWidget(page)
self._page_index[key] = page_idx
if key == "ai":
section_label = QLabel("Giveaways")
section_label.setProperty("full_label", "Giveaways")
section_label.setProperty("short_label", "-----")
section_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
section_label.setStyleSheet(
"color: #8a8f99; font-size: 11px; font-weight: 600; letter-spacing: 1px; margin-top: 8px;"
)
sidebar_layout.addWidget(section_label)
self._menu_section_labels.append(section_label)
sidebar_layout.addStretch(1)
content_shell = QWidget()
content_layout = QVBoxLayout(content_shell)
content_layout.setContentsMargins(0, 0, 0, 0)
content_layout.addWidget(self.stack)
shell.addWidget(self.sidebar)
shell.addWidget(content_shell, 1)
self.sidebar_animation = QPropertyAnimation(self.sidebar, b"maximumWidth", self)
self.sidebar_min_animation = QPropertyAnimation(self.sidebar, b"minimumWidth", self)
self.sidebar_animation_group = QParallelAnimationGroup(self)
self.sidebar_animation_group.addAnimation(self.sidebar_animation)
self.sidebar_animation_group.addAnimation(self.sidebar_min_animation)
self.sidebar_animation.finished.connect(self._sync_sidebar_button_labels)
for animation in (self.sidebar_animation, self.sidebar_min_animation):
animation.setDuration(220)
animation.setEasingCurve(QEasingCurve.Type.InOutCubic)
self.show_page("search")
def toggle_sidebar(self) -> None:
target_width = (
self.SIDEBAR_CLOSED_WIDTH if self._is_sidebar_open else self.SIDEBAR_OPEN_WIDTH
)
self._is_sidebar_open = not self._is_sidebar_open
if self._is_sidebar_open:
self._sync_sidebar_button_labels()
current_width = self.sidebar.width()
self.sidebar_animation_group.stop()
self.sidebar_animation.setStartValue(current_width)
self.sidebar_animation.setEndValue(target_width)
self.sidebar_min_animation.setStartValue(current_width)
self.sidebar_min_animation.setEndValue(target_width)
self.sidebar_animation_group.start()
def _sync_sidebar_button_labels(self) -> None:
if self._is_sidebar_open:
self.menu_toggle_btn.setText("Menu")
else:
self.menu_toggle_btn.setText("M")
for _, btn in self._menu_buttons:
if self._is_sidebar_open:
btn.setText(btn.property("full_label"))
else:
btn.setText(btn.property("short_label"))
for label in self._menu_section_labels:
if self._is_sidebar_open:
label.setText(label.property("full_label"))
else:
label.setText(label.property("short_label"))
def show_page(self, page_name: str) -> None:
idx = self._page_index.get(page_name)
if idx is None:
return
self.stack.setCurrentIndex(idx)
for key, btn in self._menu_buttons:
btn.setChecked(key == page_name)
def main() -> None:
app = QApplication(sys.argv)
app.setWindowIcon(app_window_icon())
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()