66from PyQt6 .QtGui import *
77import configparser
88import json
9-
9+ import re
1010
1111
1212config_path = "./config/config.conf"
@@ -57,6 +57,7 @@ def __init__(self):
5757
5858
5959 self .tabs = QTabWidget ()
60+ self .max_tab_text_length = 18
6061 self .tabs .setStyleSheet (f"""
6162 QTabBar::tab{{
6263 background: { notselected_tab_color } ;
@@ -132,12 +133,12 @@ def __init__(self):
132133
133134
134135 self .settings_button = QPushButton ()
135- self .settings_button .clicked .connect (self .open_settings )
136136 self .settings_button .setIcon (QIcon ("public/img/settingsbar.png" ))
137137 self .settings_button .setFixedSize (QSize (20 , 20 ))
138138 self .settings_button .setIconSize (QSize (20 , 20 ))
139139 self .settings_button .setStyleSheet ("background-color: transparent; border: none; margin-right: 8px;" )
140140 self .settings_button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
141+ self .settings_button .clicked .connect (self .show_settings_menu )
141142
142143 top_layout = QHBoxLayout ()
143144 top_layout .setContentsMargins (0 ,0 ,0 ,0 )
@@ -172,11 +173,49 @@ def __init__(self):
172173
173174 self .tabs .currentChanged .connect (self .update_url_from_tab )
174175
175-
176+ def show_settings_menu (self ):
177+ menu = QMenu (self )
178+ history_action = QAction (texts ['history' ], self )
179+ history_action .triggered .connect (self .show_history )
180+ menu .addAction (history_action )
181+
182+ settings_action = QAction (texts ['settings' ], self )
183+ settings_action .triggered .connect (self .open_settings )
184+ menu .addAction (settings_action )
185+
186+ button_position = self .settings_button .mapToGlobal (QPoint (0 , self .settings_button .height ()))
187+ menu .exec (button_position )
188+
189+ def show_history (self ):
190+ history_dialog = QDialog (self )
191+ history_dialog .setWindowTitle ("History" )
192+ history_dialog .setFixedSize (600 , 400 )
193+
194+ layout = QVBoxLayout (history_dialog )
195+
196+ history_list = QListWidget ()
197+ layout .addWidget (history_list )
198+
199+ # Load history from file
200+ if os .path .exists (history ):
201+ with open (history , 'r' , encoding = "utf-8" ) as file :
202+ lines = file .readlines ()
203+ for line in lines :
204+ line = line .strip ()
205+ if line :
206+ history_list .addItem (line )
207+
208+ close_button = QPushButton (texts ['close' ])
209+ close_button .clicked .connect (history_dialog .close )
210+ layout .addWidget (close_button )
211+
212+ history_dialog .exec ()
213+
214+
176215 def add_new_tab (self , url , label ):
177216 new_browser = QWebEngineView ()
178217 new_browser .setUrl (QUrl (search_engine ))
179- self .tabs .addTab (new_browser , label )
218+ self .tabs .addTab (new_browser , self . truncate_tab_text ( label ) )
180219 self .tabs .setCurrentWidget (new_browser )
181220
182221 self .close_tab_button = QPushButton ()
@@ -187,6 +226,7 @@ def add_new_tab(self, url, label):
187226 new_browser .urlChanged .connect (lambda q : self .update_url (q ))
188227 new_browser .setContextMenuPolicy (Qt .ContextMenuPolicy .CustomContextMenu )
189228 new_browser .customContextMenuRequested .connect (self .show_context_menu )
229+
190230 def close_tab (self , index ):
191231 if self .tabs .count () == 1 :
192232 exit ()
@@ -195,7 +235,13 @@ def close_tab(self, index):
195235
196236 def update_title (self , browser , title ):
197237 index = self .tabs .indexOf (browser )
198- self .tabs .setTabText (index , title if title else tab_name )
238+ #self.tabs.setTabText(index, title if title else tab_name)
239+ self .tabs .setTabText (index , self .truncate_tab_text (title if title else tab_name ))
240+
241+ def truncate_tab_text (self , text ):
242+ if len (text ) > self .max_tab_text_length :
243+ return text [:self .max_tab_text_length ] + "..."
244+ return text
199245
200246 def add_new_tab_button (self ):
201247 self .add_new_tab (search_engine , tab_name )
@@ -221,9 +267,11 @@ def update_url_from_tab(self):
221267 self .url_bar .setText (current_url .toString ())
222268
223269 def load_url (self ):
224- url = self .url_bar .text ()
225- if url .startswith ("http://" ) or url .startswith ("https://" ):
226- url = url
270+ url = self .url_bar .text ().strip ()
271+
272+ if re .match (r"^[^\s]+\.[^\s]+$" , url ):
273+ if not url .startswith ("http://" ) and not url .startswith ("https://" ):
274+ url = "http://" + url
227275 else :
228276 if search_engine == "https://duckduckgo.com" :
229277 url = search_engine + "/?q=" + url
@@ -401,10 +449,10 @@ def ok(self):
401449 config ["Settings" ]["search_engine" ] = "https://bing.com"
402450 elif s_engine == "Brave" :
403451 config ["Settings" ]["search_engine" ] = "https://search.brave.com"
404- elif s_engine == "StartPage " :
452+ elif s_engine == "Startpage " :
405453 config ["Settings" ]["search_engine" ] = "https://startpage.com"
406454
407- # Burada her bir dosya için ayrı ayrı kodu uzatmak yerine, kısaca kodun Data'sına eşitlemesini sağladım.
455+ # Burada her bir dosya için ayrı ayrı kodu uzatmak yerine, kısaca Data'sına eşitlemesini sağladım.
408456 lan = self .language .currentData ()
409457 config ["Language" ]["language" ] = lan
410458 with open ('config/config.conf' , 'w' ) as configfile :
0 commit comments