-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
286 lines (234 loc) · 10 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import os
import sys
from PySide6 import QtCore
from PySide6.QtCore import *
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtWebEngineCore import *
from PySide6.QtNetwork import QNetworkCookieJar, QNetworkCookie
from PySide6.QtWidgets import QApplication, QMainWindow, QGraphicsDropShadowEffect
from PySide6.QtCore import Qt, QPoint, QRect
import sys
from PySide6 import QtWidgets
import threading
from ui_settings import Ui_MainWindow
from py_toggle import *
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QByteArray
from BlurWindow.blurWindow import blur
from BlurWindow.blurWindow import GlobalBlur
global counter_for_tabs
counter_for_tabs = 1
current_dir = os.getcwd()
global cookie_file
global cookie_path
cookie_path = os.path.join(current_dir, "cookies")
cookie_file = os.path.join(current_dir, "cookies", "cookies.txt")
settings_path = os.path.join(current_dir, "settings")
cookies_settings_path = (settings_path + "\\cookieson.txt")
global use_cookies
with open(cookies_settings_path, 'r+') as cookies_on:
use_cookies = cookies_on.read()
class Browser(QWidget):
def __init__(self):
super().__init__()
# Webview
self.profile = QWebEngineProfile.defaultProfile()
self.cookie_jar = QNetworkCookieJar()
if str(use_cookies) == str("1"):
# Using cookies
pass
self.web_view = QWebEngineView(self)
self.web_view.setPage(QWebEnginePage(self.profile, self.web_view))
self.web_view.load(QUrl('https://www.google.com/'))
self.web_view.urlChanged.connect(self.update_url_bar)
self.web_view.titleChanged.connect(self.update_tab_name)
# Set the background color to RGB(33, 37, 45)
self.web_view.setStyleSheet("background-color: rgb(33, 37, 45);")
# Back button
self.back_button = QPushButton("<")
self.back_button.clicked.connect(self.back)
self.back_button.setMinimumHeight(25)
self.back_button.setStyleSheet("""color: gray;
background-color: rgb(33, 37, 45);
font: 700 10pt "Montserrat";
""")
# URL bar
self.url_bar = QLineEdit()
self.url_bar.returnPressed.connect(self.navigate)
self.url_bar.setMinimumHeight(25)
self.url_bar.setMinimumWidth(1800) # Set the minimum width (1800)
self.url_bar.setStyleSheet("""border: 1px solid rgb(33, 37, 45);""")
# Apply dark mode to every loaded page
dark_mode_script = """
var style = document.createElement('style');
style.textContent = 'html { filter: invert(1) hue-rotate(180deg); background-color: #1a1a1a; } img:not([src*=".svg"]), video { filter: invert(1) hue-rotate(180deg); }';
document.head.appendChild(style);
"""
dark_mode_qscript = QWebEngineScript()
dark_mode_qscript.setName('dark_mode')
dark_mode_qscript.setInjectionPoint(QWebEngineScript.DocumentReady)
dark_mode_qscript.setRunsOnSubFrames(True)
dark_mode_qscript.setWorldId(QWebEngineScript.MainWorld)
dark_mode_qscript.setSourceCode(dark_mode_script)
self.web_view.page().scripts().insert(dark_mode_qscript)
# Layout
hbox = QHBoxLayout()
hbox.addWidget(self.back_button)
hbox.addWidget(self.url_bar)
hbox.addStretch()
layout = QVBoxLayout()
layout.addLayout(hbox)
layout.addWidget(self.web_view)
self.setLayout(layout)
def back(self):
self.web_view.back()
def navigate(self):
url = self.url_bar.text()
self.web_view.load(QUrl(url))
if str(use_cookies) == str(1):
print("Using cookies")
else:
print("Not using cookies")
def update_url_bar(self, q):
self.url_bar.setText(q.toString())
def update_tab_name(self, title):
parent = self.parentWidget().parentWidget() # Get the TabbedBrowser
index = parent.indexOf(self) # Get index of current tab
# Truncate title to 20 characters if it is longer than that
truncated_title = (title[:17] + '...') if len(title) > 20 else title
parent.setTabText(index, truncated_title) # Set tab name to truncated title
class TabbedBrowser(QMainWindow):
def __init__(self):
super().__init__()
# Title Bar
if sys.platform == 'win32':
self.setWindowFlag(Qt.FramelessWindowHint)
# Set background color of main window
self.setStyleSheet("""background-color: #3C4052;
color: gray;""")
self.setGeometry(0, 0, 800, 600)
# Tab widget
self.tab_widget = QTabWidget()
self.tab_widget.setTabsClosable(True)
self.tab_widget.tabCloseRequested.connect(self.close_tab)
# Tab stylesheet
self.tab_widget.setStyleSheet("""QTabBar::tab { height: 25px; width: 150px; }
QTabBar::tab:selected { background-color: rgb(70, 74, 95); }
QTabBar::tab { background-color: #3C4052; }
""")
# Set the background color and shadow
palette = self.tab_widget.palette()
palette.setColor(self.tab_widget.backgroundRole(), QColor(60, 64, 82)) # RGB values for #3C4052
self.tab_widget.setPalette(palette)
self.setCentralWidget(self.tab_widget)
# Create first tab
self.add_tab()
# Add "+" button to add new tabs
self.plus_button = QPushButton("+")
self.plus_button.clicked.connect(self.add_tab)
self.tab_widget.setCornerWidget(self.plus_button)
self.plus_button.setStyleSheet("""color: gray;
background-color: rgb(33, 37, 45);
font: 700 12pt "Montserrat";
""")
self.plus_button.setShortcut("Ctrl+T")
# Create "Settings", "History", "Saved" and "Exit" buttons in menu bar
settings_button = QAction("Settings", self)
settings_button.triggered.connect(self.show_settings_page)
self.menuBar().addAction(settings_button)
settings_button.setShortcut("Ctrl+,")
history_button = QAction("History", self)
history_button.triggered.connect(self.show_history_page)
self.menuBar().addAction(history_button)
history_button.setShortcut("Ctrl+H")
saved_button = QAction("Saved", self)
saved_button.triggered.connect(self.show_saved_page)
self.menuBar().addAction((saved_button))
exit_button = QAction("Exit", self)
exit_button.triggered.connect(self.exit_function)
self.menuBar().addAction((exit_button))
def show_settings_page(self):
global settings_window
settings_window = SettingsWindow()
settings_window.show()
return settings_window
def show_history_page(self):
# Create new tab with the history page
browser = Browser()
browser.web_view.setHtml("""<h1>History page hasn't been implemented yet</h1>
<p>This page will allow you to view your history in the future</p>""")
self.tab_widget.addTab(browser, "History")
# Switch to the new tab
self.tab_widget.setCurrentWidget(browser)
def show_saved_page(self):
# Create new tab with the saved page
browser = Browser()
browser.web_view.setHtml("""<h1>Saved page hasn't been implemented yet</h1>
<p>This page will allow you to quickly access websites you've saved in the future</p>""")
self.tab_widget.addTab(browser, "Saved")
# Switch to the new tab
self.tab_widget.setCurrentWidget(browser)
def exit_function(self):
sys.exit()
def add_tab(self):
# Create new tab
browser = Browser()
self.tab_widget.addTab(browser, "New Tab")
self.tab_widget.setCurrentWidget(browser)
def close_tab(self, index):
if self.tab_widget.count() > 1:
self.tab_widget.removeTab(index)
class SettingsWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None, *args, obj=None, **kwargs):
super(SettingsWindow, self).__init__(*args, **kwargs, parent=parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle(" ")
GlobalBlur(self.winId(), Dark=True, QWidget=self)
self.setStyleSheet("background-color: rgba(0, 0, 0, 0)")
if sys.platform == 'win32':
self.setWindowFlag(Qt.FramelessWindowHint)
self.cookies_on_toggle = PyToggle(
width=50
)
self.apply_button = QPushButton('Apply', parent=self)
self.apply_button.setMinimumHeight(71)
self.apply_button.setFixedWidth(281)
self.apply_button.setStyleSheet('color: gray')
self.apply_button.clicked.connect(self.settings_apply)
self.back_button = QPushButton('Back', parent=self)
self.back_button.setMinimumHeight(71)
self.back_button.setFixedWidth(131)
self.back_button.setStyleSheet('color: gray')
self.back_button.clicked.connect(self.close)
self.ui.cookies_toggle_layout.addWidget(self.cookies_on_toggle, Qt.AlignCenter, Qt.AlignCenter)
self.ui.apply_button_layout.addWidget(self.apply_button, Qt.AlignCenter, Qt.AlignCenter)
self.ui.settings_back_button_layout.addWidget(self.back_button, Qt.AlignCenter, Qt.AlignCenter)
if use_cookies == str(0):
self.cookies_on_toggle.setCheckState(Qt.Unchecked)
else:
self.cookies_on_toggle.setCheckState(Qt.Checked)
def settings_apply(self):
global use_cookies
with open('settings/cookieson.txt', 'w+') as file:
file.truncate(0)
if self.cookies_on_toggle.isChecked() == True:
file.write("1")
use_cookies = str("1")
else:
file.write("0")
use_cookies = str("0")
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
my_pixmap = QPixmap("browsericon.ico")
my_icon = QIcon(my_pixmap)
app.setWindowIcon(my_icon)
browser = TabbedBrowser()
browser.showMaximized()
browser.setWindowTitle("Fluorite Browser")
if str(use_cookies) == str("1"):
# Use cookies
pass
sys.exit(app.exec())