1- # English Version
21import sys
32import os
43from PyQt6 .QtWidgets import *
1211tab_name = "New Tab"
1312history = "./public/browser/history.txt"
1413config_path = "./config/config.conf"
14+ bookmarks = "./public/browser/bookmarks.txt"
1515
1616if not os .path .exists (history ):
1717 with open (history , 'x' ) as history_file :
2424[Appearance]
2525tab_color = #2aa1b3
2626not_selected_tab_color = #22818f""" )
27+ if not os .path .exists (bookmarks ):
28+ with open (bookmarks , 'x' ) as bf :
29+ pass
2730
2831config = configparser .ConfigParser ()
2932config .read (config_path )
@@ -74,42 +77,50 @@ def __init__(self):
7477 self .back_button = QPushButton ()
7578 self .back_button .clicked .connect (self .browser_back )
7679 self .back_button .setIcon (QIcon ("./public/img/back.png" ))
77- self .back_button .setFixedSize (QSize (25 , 25 ))
78- self .back_button .setIconSize (QSize (25 , 25 ))
80+ self .back_button .setFixedSize (QSize (20 , 20 ))
81+ self .back_button .setIconSize (QSize (20 , 20 ))
7982 self .back_button .setStyleSheet ("background-color: transparent; border: none;" )
8083 self .back_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
8184
8285 self .forward_button = QPushButton ()
8386 self .forward_button .clicked .connect (self .browser_forward )
8487 self .forward_button .setIcon (QIcon ("public/img/forward.png" ))
85- self .forward_button .setFixedSize (QSize (25 , 25 ))
86- self .forward_button .setIconSize (QSize (25 , 25 ))
88+ self .forward_button .setFixedSize (QSize (20 , 20 ))
89+ self .forward_button .setIconSize (QSize (20 , 20 ))
8790 self .forward_button .setStyleSheet ("background-color: transparent; border: none;" )
8891 self .forward_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
8992
9093 self .new_tab_button = QPushButton ()
9194 self .new_tab_button .clicked .connect (self .add_new_tab_button )
9295 self .new_tab_button .setIcon (QIcon ("public/img/newtab.png" ))
93- self .new_tab_button .setFixedSize (QSize (25 , 25 ))
94- self .new_tab_button .setIconSize (QSize (25 , 25 ))
96+ self .new_tab_button .setFixedSize (QSize (20 , 20 ))
97+ self .new_tab_button .setIconSize (QSize (20 , 20 ))
9598 self .new_tab_button .setStyleSheet ("background-color: transparent; border: none;" )
9699 self .new_tab_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
97100
98101 self .reload_button = QPushButton ()
99102 self .reload_button .clicked .connect (self .browser_reload )
100103 self .reload_button .setIcon (QIcon ("public/img/reload.png" ))
101- self .reload_button .setFixedSize (QSize (25 , 25 ))
102- self .reload_button .setIconSize (QSize (25 , 25 ))
104+ self .reload_button .setFixedSize (QSize (20 , 20 ))
105+ self .reload_button .setIconSize (QSize (20 , 20 ))
103106 self .reload_button .setStyleSheet ("background-color: transparent; border: none;" )
104107 self .reload_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
105-
106108
109+ self .bookmark_button = QPushButton ()
110+ self .bookmark_button .clicked .connect (self .bookmark )
111+ self .bookmark_button .setIcon (QIcon ("public/img/bookmark-regular.png" ))
112+ self .bookmark_button .setFixedSize (QSize (20 ,20 ))
113+ self .bookmark_button .setIconSize (QSize (20 ,20 ))
114+ self .bookmark_button .setStyleSheet ("background-color: transparent; border: none;" )
115+ self .bookmark_button .setCursor (Qt .CursorShape .PointingHandCursor )
116+
117+
107118 self .settings_button = QPushButton ()
108119 self .settings_button .clicked .connect (self .open_settings )
109120 self .settings_button .setIcon (QIcon ("public/img/settingsbar.png" ))
110- self .settings_button .setFixedSize (QSize (25 , 25 ))
111- self .settings_button .setIconSize (QSize (25 , 25 ))
112- self .settings_button .setStyleSheet ("background-color: transparent; border: none;" )
121+ self .settings_button .setFixedSize (QSize (20 , 20 ))
122+ self .settings_button .setIconSize (QSize (20 , 20 ))
123+ self .settings_button .setStyleSheet ("background-color: transparent; border: none; margin-right: 8px; " )
113124 self .settings_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
114125
115126 top_layout = QHBoxLayout ()
@@ -118,9 +129,12 @@ def __init__(self):
118129 top_layout .addWidget (self .forward_button )
119130 top_layout .addWidget (self .new_tab_button )
120131 top_layout .addWidget (self .reload_button )
132+ top_layout .addWidget (self .bookmark_button )
121133 top_layout .addWidget (self .url_bar )
122134 top_layout .addWidget (self .settings_button )
123135
136+ self .load_bookmarks (top_layout )
137+
124138 main_layout = QVBoxLayout ()
125139 main_layout .setContentsMargins (0 ,0 ,0 ,0 )
126140 main_layout .addLayout (top_layout )
@@ -174,7 +188,7 @@ def update_url(self, url):
174188 current_browser .setUrl (QUrl (url ))
175189 with open (history , 'r' , encoding = "utf-8" ) as file :
176190 old_history = file .read ()
177- new_history = str ( url ) + "\n " + old_history
191+ new_history = current_browser . url (). toString ( ) + "\n " + old_history
178192 with open (history , 'w' , encoding = "utf-8" ) as file :
179193 file .write (new_history )
180194
@@ -196,11 +210,7 @@ def load_url(self):
196210 url = search_engine + "/search?q=" + url
197211
198212
199- self .update_url (url )
200-
201-
202-
203-
213+ self .update_url (url )
204214
205215
206216 def browser_back (self ):
@@ -224,6 +234,7 @@ def show_context_menu(self, position):
224234 context_menu .addAction ("Back" , self .browser_back )
225235 context_menu .addAction ("Forward" , self .browser_forward )
226236 context_menu .addAction ("Reload" , self .browser_reload )
237+
227238
228239 context_menu .exec (self .tabs .currentWidget ().mapToGlobal (position ))
229240
@@ -240,19 +251,49 @@ def browser_paste(self):
240251 text = clipboard .text ()
241252 current_browser = self .tabs .currentWidget ()
242253 current_browser .page ().runJavaScript (f"document.execCommand('insertText', false, '{ text } ');" )
254+
255+
243256
244257 def browser_save (self ):
245258 current_browser = self .tabs .currentWidget ()
246259 current_browser .page ().toHtml (self .save_html )
247260
248261 def save_html (self , html ):
249- file_name , _ = QFileDialog .getSaveFileName (self , "Kaydet " , "" , "HTML File (*.html);;WEBP File(*.webp);;Tüm Dosyalar (*)" )
262+ file_name , _ = QFileDialog .getSaveFileName (self , "Save " , "" , "HTML File (*.html);;WEBP File(*.webp);;All Files (*)" )
250263 if file_name :
251264 with open (file_name , 'w' , encoding = 'utf-8' ) as file :
252265 file .write (html )
253266 def open_settings (self ):
254267 settings = AnkaBrowserSettings (self )
255268 settings .exec ()
269+ def bookmark (self ):
270+ current_browser = self .tabs .currentWidget ()
271+ current_url = current_browser .url ().toString ()
272+
273+ with open (bookmarks , 'r' , encoding = "utf-8" ) as bookmarks_file :
274+ a = bookmarks_file .read ()
275+ if current_url in a :
276+ pass
277+ else :
278+ old_bookmarks = bookmarks_file .read ()
279+ new_bookmarks = current_url + "\n " + old_bookmarks
280+ with open (bookmarks ,'w' , encoding = "utf-8" ) as bookmarks_file2 :
281+ bookmarks_file2 .write (new_bookmarks )
282+ def load_bookmarks (self , top_layout ):
283+ with open (bookmarks , 'r' , encoding = "utf-8" ) as bookmarks_file :
284+ urls = bookmarks_file .readlines ()
285+
286+ for url in urls :
287+ url = url .strip ()
288+ if url :
289+
290+ bookmark_button = QPushButton (url )
291+ bookmark_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
292+ bookmark_button .clicked .connect (lambda checked , url = url : self .add_new_tab (QUrl (url ), url ))
293+ top_layout .addWidget (bookmark_button )
294+
295+
296+
256297
257298
258299
@@ -302,7 +343,7 @@ def __init__(self, parent=None):
302343 self .delete_history_button .clicked .connect (self .delete_history )
303344 layout .addWidget (self .delete_history_button )
304345
305- self .note_label = QLabel ("Please restart browser for configurate the settings." )
346+ self .note_label = QLabel ("Please restart the browser for configure the settings." )
306347 self .note_label .setStyleSheet ("padding-top: 5px;" )
307348 layout .addWidget (self .note_label )
308349
@@ -360,11 +401,6 @@ def __init__(self, parent=None):
360401 config .write (configfile )
361402
362403
363-
364-
365-
366-
367-
368404if __name__ == "__main__" :
369405 app = QApplication (sys .argv )
370406 anka_browser_window = AnkaBrowser ()
0 commit comments