Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 1fd7d8c

Browse files
committed
Anka v1.9.8
1 parent 31387a3 commit 1fd7d8c

File tree

1 file changed

+94
-18
lines changed

1 file changed

+94
-18
lines changed

anka-browser.py

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@
7070
"en-US": "English",
7171
}
7272

73-
with open(f"/public/browser/languages/{language}.json", "r", encoding="UTF-8") as jsonn:
73+
with open(f"./public/browser/languages/{language}.json", "r", encoding="UTF-8") as jsonn:
7474
texts = json.load(jsonn)
7575

7676
tab_name = texts["tab-name"]
7777
history = f"{config_anka}/public/browser/history.txt"
7878
bookmarks = f"{config_anka}/public/browser/bookmarks.txt"
79+
downloads = f"{config_anka}/public/browser/downloads.txt"
7980

8081
if not os.path.exists(history):
8182
with open(history, 'x') as history_file:
@@ -85,6 +86,9 @@
8586
with open(bookmarks, 'x') as bf:
8687
pass
8788

89+
if not os.path.exists(downloads):
90+
with open(downloads, 'x') as df:
91+
pass
8892

8993

9094
search_engine = config['Settings']['search_engine']
@@ -121,66 +125,69 @@ def __init__(self):
121125

122126
self.tabs.tabCloseRequested.connect(self.close_tab)
123127

124-
self.setWindowIcon(QIcon(f"{config_anka}/public/img/logo.ico"))
128+
self.setWindowIcon(QIcon(".public/img/logo.ico"))
125129

126130
self.add_new_tab(QUrl(search_engine), tab_name)
127131

128132
current_browser = self.tabs.currentWidget()
129133
current_browser.settings().setAttribute(current_browser.settings().WebAttribute.PluginsEnabled, True)
130134
current_browser.settings().setAttribute(current_browser.settings().WebAttribute.PdfViewerEnabled, True)
131-
135+
profile = self.tabs.currentWidget().page().profile()
136+
profile.downloadRequested.connect(self.handle_download)
137+
138+
self.is_fullscreen = False
132139

133140
self.url_bar = QLineEdit()
134141
self.url_bar.returnPressed.connect(self.load_url)
135142
self.url_bar.setPlaceholderText(texts["url_bar_placeholder"])
136143
self.url_bar.setFont(QFont("Lexend"))
137144
self.url_bar.setFixedHeight(25)
138-
self.url_bar.setStyleSheet("white-space: nowrap;")
145+
self.url_bar.setStyleSheet("white-space: nowrap; border: 1.5px solid black; border-radius: 0.6px")
139146

140147

141148
self.back_button = QPushButton()
142149
self.back_button.clicked.connect(self.browser_back)
143-
self.back_button.setIcon(QIcon(f"{config_anka}/public/img/back.png"))
150+
self.back_button.setIcon(QIcon("./public/img/back.png"))
144151
self.back_button.setFixedSize(QSize(20, 20))
145152
self.back_button.setIconSize(QSize(20, 20))
146153
self.back_button.setStyleSheet("background-color: transparent; border: none;")
147154
self.back_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
148155

149156
self.forward_button = QPushButton()
150157
self.forward_button.clicked.connect(self.browser_forward)
151-
self.forward_button.setIcon(QIcon(f"{config_anka}/public/img/forward.png"))
158+
self.forward_button.setIcon(QIcon("./public/img/forward.png"))
152159
self.forward_button.setFixedSize(QSize(20, 20))
153160
self.forward_button.setIconSize(QSize(20, 20))
154161
self.forward_button.setStyleSheet("background-color: transparent; border: none;")
155162
self.forward_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
156163

157164
self.new_tab_button = QPushButton()
158165
self.new_tab_button.clicked.connect(self.add_new_tab_button)
159-
self.new_tab_button.setIcon(QIcon(f"{config_anka}/public/img/newtab.png"))
166+
self.new_tab_button.setIcon(QIcon("./public/img/newtab.png"))
160167
self.new_tab_button.setFixedSize(QSize(20, 20))
161168
self.new_tab_button.setIconSize(QSize(20, 20))
162169
self.new_tab_button.setStyleSheet("background-color: transparent; border: none;")
163170
self.new_tab_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
164171

165172
self.reload_button = QPushButton()
166173
self.reload_button.clicked.connect(self.browser_reload)
167-
self.reload_button.setIcon(QIcon(f"{config_anka}/public/img/reload.png"))
174+
self.reload_button.setIcon(QIcon("./public/img/reload.png"))
168175
self.reload_button.setFixedSize(QSize(20, 20))
169176
self.reload_button.setIconSize(QSize(20, 20))
170177
self.reload_button.setStyleSheet("background-color: transparent; border: none;")
171178
self.reload_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
172179

173180
self.bookmark_button = QPushButton()
174181
self.bookmark_button.clicked.connect(self.bookmark)
175-
self.bookmark_button.setIcon(QIcon(f"{config_anka}/public/img/bookmark-regular.png"))
182+
self.bookmark_button.setIcon(QIcon("./public/img/bookmark-regular.png"))
176183
self.bookmark_button.setFixedSize(QSize(20,20))
177184
self.bookmark_button.setIconSize(QSize(20,20))
178185
self.bookmark_button.setStyleSheet("background-color: transparent; border: none;")
179186
self.bookmark_button.setCursor(Qt.CursorShape.PointingHandCursor)
180187

181188

182189
self.settings_button = QPushButton()
183-
self.settings_button.setIcon(QIcon(f"{config_anka}/public/img/settingsbar.png"))
190+
self.settings_button.setIcon(QIcon("./public/img/settingsbar.png"))
184191
self.settings_button.setFixedSize(QSize(20, 20))
185192
self.settings_button.setIconSize(QSize(20, 20))
186193
self.settings_button.setStyleSheet("background-color: transparent; border: none; margin-right: 8px;")
@@ -215,27 +222,57 @@ def __init__(self):
215222

216223
self.setWindowTitle("Anka")
217224
self.showMaximized()
218-
self.setWindowIcon(QIcon(f"{config_anka}/public/img/logo.ico"))
225+
self.setWindowIcon(QIcon("./public/img/logo.ico"))
219226
self.resize(1920, 1080)
220227

221228
self.tabs.currentChanged.connect(self.update_url_from_tab)
222229

223230
def show_settings_menu(self):
224231
menu = QMenu(self)
225-
history_action = QAction(texts['history'], self)
226-
history_action.triggered.connect(self.show_history)
227-
menu.addAction(history_action)
228232

229233
settings_action = QAction(texts['settings'], self)
230234
settings_action.triggered.connect(self.open_settings)
231235
menu.addAction(settings_action)
236+
237+
downloads_action = QAction(texts['downloads'], self)
238+
downloads_action.triggered.connect(self.show_downloads)
239+
menu.addAction(downloads_action)
240+
241+
history_action = QAction(texts['history'], self)
242+
history_action.triggered.connect(self.show_history)
243+
menu.addAction(history_action)
232244

233245
file_action = QAction(texts['open_file'], self)
234246
file_action.triggered.connect(self.open_file)
235247
menu.addAction(file_action)
236248

237249
button_position = self.settings_button.mapToGlobal(QPoint(0, self.settings_button.height()))
238250
menu.exec(button_position)
251+
def show_downloads(self):
252+
downloads_dialog = QDialog(self)
253+
downloads_dialog.setWindowTitle("Downloads")
254+
downloads_dialog.setFixedSize(600, 400)
255+
256+
layout = QVBoxLayout(downloads_dialog)
257+
258+
downloads_list = QListWidget()
259+
layout.addWidget(downloads_list)
260+
261+
# Load downloads from file
262+
if os.path.exists(downloads):
263+
with open(downloads, 'r', encoding="utf-8") as file:
264+
lines = file.readlines()
265+
for line in lines:
266+
line = line.strip()
267+
if line:
268+
downloads_list.addItem(line)
269+
270+
close_button = QPushButton(texts['close'])
271+
close_button.clicked.connect(downloads_dialog.close)
272+
layout.addWidget(close_button)
273+
274+
downloads_dialog.exec()
275+
239276

240277
def show_history(self):
241278
history_dialog = QDialog(self)
@@ -278,7 +315,10 @@ def open_file(self):
278315

279316
def add_new_tab(self, url, label):
280317
new_browser = QWebEngineView()
281-
new_browser.setUrl(QUrl(search_engine))
318+
if url:
319+
new_browser.setUrl(QUrl(url))
320+
else:
321+
new_browser.setUrl(QUrl(search_engine))
282322
self.tabs.addTab(new_browser, self.truncate_tab_text(label))
283323
self.tabs.setCurrentWidget(new_browser)
284324

@@ -290,13 +330,34 @@ def add_new_tab(self, url, label):
290330
new_browser.urlChanged.connect(lambda q: self.update_url(q))
291331
new_browser.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
292332
new_browser.customContextMenuRequested.connect(self.show_context_menu)
333+
334+
335+
293336

294337
def close_tab(self, index):
295338
if self.tabs.count() == 1:
296339
exit()
297340
else:
298341
self.tabs.removeTab(index)
299-
342+
def handle_download(self, download_item):
343+
344+
save_path, _ = QFileDialog.getSaveFileName(
345+
self,
346+
texts['right-click-save'],
347+
os.path.join(home, download_item.suggestedFileName()),
348+
f"{texts['html_file']} (*.html);;{texts['png_file']};;{texts['webp_file']};;{texts['pdf_file']};;{texts['all_files']}"
349+
)
350+
351+
if save_path:
352+
download_item.setDownloadDirectory(save_path.rsplit('/', 1)[0])
353+
download_item.setDownloadFileName(save_path.rsplit('/', 1)[-1])
354+
download_item.accept()
355+
356+
with open(downloads, 'r+', encoding="utf-8") as downloads_file:
357+
downloads_file.write(save_path + download_item.downloadFileName() + "\n")
358+
359+
else:
360+
download_item.cancel()
300361
def update_title(self, browser, title):
301362
index = self.tabs.indexOf(browser)
302363
#self.tabs.setTabText(index, title if title else tab_name)
@@ -392,7 +453,7 @@ def browser_save(self):
392453
current_browser.page().toHtml(self.save_html)
393454

394455
def save_html(self, html):
395-
file_name, _ = QFileDialog.getSaveFileName(self, texts['right-click-save'], "", f"{texts['html_file']} (*.html);;{texts['webp_file']}(*.webp);;{texts['all_files']} (*)")
456+
file_name, _ = QFileDialog.getSaveFileName(self, texts['right-click-save'], "", f"{texts['html_file']} (*.html);;{texts['png_file']};;{texts['webp_file']};;{texts['pdf_file']};;{texts['all_files']}")
396457
if file_name:
397458
with open(file_name, 'w', encoding='utf-8') as file:
398459
file.write(html)
@@ -421,7 +482,14 @@ def load_bookmarks(self, top_layout):
421482
bookmark_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
422483
bookmark_button.clicked.connect(lambda checked, url=url: self.add_new_tab(QUrl(url), url))
423484
top_layout.addWidget(bookmark_button)
424-
485+
def keyPressEvent(self, event):
486+
if event.key() == Qt.Key.Key_F11:
487+
if self.is_fullscreen:
488+
self.showNormal()
489+
self.is_fullscreen = False
490+
else:
491+
self.showFullScreen()
492+
self.is_fullscreen = True
425493

426494
class AnkaBrowserSettings(QDialog):
427495
def __init__(self, parent=None):
@@ -488,6 +556,11 @@ def __init__(self, parent=None):
488556
self.delete_history_button.clicked.connect(self.delete_history)
489557
layout.addWidget(self.delete_history_button)
490558

559+
self.delete_bookmarks_button = QPushButton(texts["settings-bookmarks"])
560+
self.delete_bookmarks_button.setFixedSize(QSize(450,25))
561+
self.delete_bookmarks_button.clicked.connect(self.delete_bookmarks)
562+
layout.addWidget(self.delete_bookmarks_button)
563+
491564
self.note_label = QLabel(texts["settings-info-msg"])
492565
self.note_label.setStyleSheet("padding-top: 5px;")
493566
layout.addWidget(self.note_label)
@@ -530,6 +603,9 @@ def open_tab_color_dialog(self):
530603
def delete_history(self):
531604
with open(history, 'w', encoding="utf-8") as file:
532605
file.write(" ")
606+
def delete_bookmarks(self):
607+
with open(bookmarks, 'w', encoding="utf-8") as file:
608+
file.write(" ")
533609

534610
class Tab_Color_Dialog(QColorDialog):
535611
def __init__(self, parent=None):

0 commit comments

Comments
 (0)