-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
191 lines (151 loc) · 5.6 KB
/
main.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
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
"""
====================================================================================================
MAIN UI CREATED BY : WANDERSON M.PIMENTA (https://github.com/Wanderson-Magalhaes)
EDITED/ENHANCED BY : OFFICIALAHMED (https://github.com/OfficialAhmed)
====================================================================================================
"""
# BUILT-INS
from json import load as jsonLoad
from json import dump as jsonDump
from os import environ, path, makedirs
from sys import argv, exit
from platform import system
# QT / PYSIDE FRAMEWORK
from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *
# CUSTOME WIDGETS STYLING
from frontend.modules.home import *
from frontend.modules.settings import *
# FIX Problem for High DPI and Scale above 100%
environ["QT_FONT_DPI"] = "96"
class MainWindow(QMainWindow):
widgets = None
def __init__(self):
QMainWindow.__init__(self)
# SET AS GLOBAL WIDGETS
self.ui = Ui()
self.ui.setupUi(self)
# global widgets
self.widgets = self.ui
shared_views.set_widgets(self.widgets, self.ui)
# USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
self.ui.EENABLE_CUSTOM_TITLE_BAR = True if system() == "Windows" else False
self.setWindowTitle(
"File Engine"
)
self.widgets.titleRightInfo.setText(
"File Management & Automation Tool"
)
# SET UI DEFINITIONS
UiSettings.uiDefinitions(self)
# LEFT MENUS
self.widgets.home_page_btn.clicked.connect(
lambda: shared_views.change(
self.widgets.home_page_btn, "home_page", self.widgets.home_widgets)
)
self.widgets.delete_page_btn.clicked.connect(
lambda: shared_views.change(
self.widgets.delete_page_btn, "delete_page", self.widgets.delete_widgets)
)
self.widgets.rename_page_btn.clicked.connect(
lambda: shared_views.change(
self.widgets.rename_page_btn, "rename_page", self.widgets.rename_widgets)
)
self.widgets.search_page_btn.clicked.connect(
lambda: shared_views.change(
self.widgets.search_page_btn, "search_page", self.widgets.search_widgets)
)
self.widgets.move_page_btn.clicked.connect(
lambda: shared_views.change(
self.widgets.move_page_btn, "move_page", self.widgets.move_widgets)
)
# TOGGLE MENU
self.widgets.toggleButton.clicked.connect(
lambda: UiSettings.toggleMenu(self, True)
)
# EXTRA LEFT MENU
self.widgets.toggleLeftBox.clicked.connect(
lambda: UiSettings.toggleLeftBox(self, True)
)
self.widgets.extraCloseColumnBtn.clicked.connect(
lambda: UiSettings.toggleLeftBox(self, True)
)
# EXTRA RIGHT MENU
self.widgets.moreBtn.clicked.connect(
lambda: UiSettings.toggleRightBox(self, True)
)
self.show()
default_settings = self.get_settings()
# APPLY THEME - DARK IS THE DEFAULT
if default_settings.get("is_light_theme"):
UiSettings.theme(self, True)
# SET HOME PAGE AND SELECT MENU
self.widgets.stackedWidget.setCurrentWidget(
self.widgets.home_widgets
)
self.widgets.home_page_btn.setStyleSheet(
UiSettings.selectMenu(
self.widgets.home_page_btn.styleSheet()
)
)
# SIGNALS TO CHANGE PAGE FROM SEARCH PAGE
self.widgets.search_widgets.findChild(QPushButton, "deleteOptionBtn").clicked.connect(
lambda: shared_views.change_indirect("delete_page")
)
self.widgets.search_widgets.findChild(QPushButton, "renameOptionBtn").clicked.connect(
lambda: shared_views.change_indirect("rename_page")
)
self.widgets.search_widgets.findChild(QPushButton, "moveOptionBtn").clicked.connect(
lambda: shared_views.change_indirect("move_page")
)
def resizeEvent(self, event):
"""
RESIZE EVENTS
"""
# Update Size Grips
# UiSettings.resize_grips(self)
if UiStyle.ENABLE_CUSTOM_TITLE_BAR:
self.left_grip.setGeometry(
0, 10, 10, self.height()
)
self.right_grip.setGeometry(
self.width() - 10, 10, 10, self.height()
)
self.top_grip.setGeometry(
0, 0, self.width(), 10
)
self.bottom_grip.setGeometry(
0, self.height() - 10, self.width(), 10
)
def mousePressEvent(self, event):
"""
MOUSE CLICK EVENTS
"""
# GET CURRENT POSITION AS QPointF
qpointf = event.globalPosition()
# CONVERT QPointF TO QPoint
self.dragPos = QPoint(
int(qpointf.x()),
int(qpointf.y())
)
def get_settings(self) -> dict:
dir = "data/settings/"
file = "default.json"
if not path.exists(dir):
makedirs(dir)
# MAKE SURE FILE EXISTS BEFORE MOVING ON
if path.exists(dir + file):
return jsonLoad(open(dir + file))
# DEFAULT SETTINGS ON CREATE
data = {
"is_light_theme": False,
}
jsonDump(data, open(dir + file, "w+"))
return data
if __name__ == "__main__":
from backend.views import shared_views
app = QApplication(argv)
app.setWindowIcon(QIcon("icon.ico"))
window = MainWindow()
exit(app.exec())