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

Commit c9ee6b6

Browse files
authored
Merge pull request #2 from xeyossr/xeyossr/main
Birtakım yenilikler
2 parents 55cdc1f + 516c159 commit c9ee6b6

File tree

5 files changed

+108
-40
lines changed

5 files changed

+108
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
public/browser/*.txt
2+
anka-browser.spec
23
venv
4+
dist
5+
build

anka-browser.py

Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@
66
from PyQt6.QtGui import *
77
import configparser
88
import json
9+
import re
910

1011

12+
home = os.path.expanduser('~')
13+
config_anka = f"{home}/.config/Anka"
14+
15+
if not os.path.exists(config_anka):
16+
os.makedirs(config_anka)
17+
18+
config_path = f"{config_anka}/config.conf"
19+
20+
if not os.path.exists(config_path):
21+
with open(config_path, 'w') as cf:
22+
cf.write("""[Settings]
23+
search_engine = https://google.com
24+
25+
[Appearance]
26+
tab_color = #2aa1b3
27+
not_selected_tab_color = #22818f
28+
29+
[Language]
30+
language = tr-TR
31+
""")
32+
1133

12-
config_path = "./config/config.conf"
1334
config = configparser.ConfigParser()
1435
config.read(config_path)
1536

@@ -19,28 +40,17 @@
1940
"en-US": "English",
2041
}
2142

22-
with open(f"./public/browser/languages/{language}.json", "r", encoding="UTF-8") as jsonn:
43+
with open(f"{config_anka}/public/browser/languages/{language}.json", "r", encoding="UTF-8") as jsonn:
2344
texts = json.load(jsonn)
2445

2546
tab_name = texts["tab-name"]
26-
history = "./public/browser/history.txt"
27-
bookmarks = "./public/browser/bookmarks.txt"
47+
history = f"{config_anka}/public/browser/history.txt"
48+
bookmarks = f"{config_anka}/public/browser/bookmarks.txt"
2849

2950
if not os.path.exists(history):
3051
with open(history, 'x') as history_file:
3152
pass
32-
if not os.path.exists(config_path):
33-
with open(config_path, 'w') as cf:
34-
cf.write("""[Settings]
35-
search_engine = https://google.com
36-
37-
[Appearance]
38-
tab_color = #2aa1b3
39-
not_selected_tab_color = #22818f
4053

41-
[Language]
42-
language = tr-TR
43-
""")
4454
if not os.path.exists(bookmarks):
4555
with open(bookmarks, 'x') as bf:
4656
pass
@@ -57,6 +67,7 @@ def __init__(self):
5767

5868

5969
self.tabs = QTabWidget()
70+
self.max_tab_text_length = 18
6071
self.tabs.setStyleSheet(f"""
6172
QTabBar::tab{{
6273
background: {notselected_tab_color};
@@ -65,8 +76,6 @@ def __init__(self):
6576
height:25px;
6677
border-radius: 10px;
6778
padding: 5px;
68-
69-
7079
7180
}}
7281
QTabBar::tab::selected{{
@@ -78,7 +87,7 @@ def __init__(self):
7887

7988
self.tabs.tabCloseRequested.connect(self.close_tab)
8089

81-
self.setWindowIcon(QIcon("public/img/logo.ico"))
90+
self.setWindowIcon(QIcon(f"{config_anka}/public/img/logo.ico"))
8291

8392
self.add_new_tab(QUrl(search_engine), tab_name)
8493

@@ -92,52 +101,52 @@ def __init__(self):
92101

93102
self.back_button = QPushButton()
94103
self.back_button.clicked.connect(self.browser_back)
95-
self.back_button.setIcon(QIcon("./public/img/back.png"))
104+
self.back_button.setIcon(QIcon(f"{config_anka}/public/img/back.png"))
96105
self.back_button.setFixedSize(QSize(20, 20))
97106
self.back_button.setIconSize(QSize(20, 20))
98107
self.back_button.setStyleSheet("background-color: transparent; border: none;")
99108
self.back_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
100109

101110
self.forward_button = QPushButton()
102111
self.forward_button.clicked.connect(self.browser_forward)
103-
self.forward_button.setIcon(QIcon("public/img/forward.png"))
112+
self.forward_button.setIcon(QIcon(f"{config_anka}/public/img/forward.png"))
104113
self.forward_button.setFixedSize(QSize(20, 20))
105114
self.forward_button.setIconSize(QSize(20, 20))
106115
self.forward_button.setStyleSheet("background-color: transparent; border: none;")
107116
self.forward_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
108117

109118
self.new_tab_button = QPushButton()
110119
self.new_tab_button.clicked.connect(self.add_new_tab_button)
111-
self.new_tab_button.setIcon(QIcon("public/img/newtab.png"))
120+
self.new_tab_button.setIcon(QIcon(f"{config_anka}/public/img/newtab.png"))
112121
self.new_tab_button.setFixedSize(QSize(20, 20))
113122
self.new_tab_button.setIconSize(QSize(20, 20))
114123
self.new_tab_button.setStyleSheet("background-color: transparent; border: none;")
115124
self.new_tab_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
116125

117126
self.reload_button = QPushButton()
118127
self.reload_button.clicked.connect(self.browser_reload)
119-
self.reload_button.setIcon(QIcon("public/img/reload.png"))
128+
self.reload_button.setIcon(QIcon(f"{config_anka}/public/img/reload.png"))
120129
self.reload_button.setFixedSize(QSize(20, 20))
121130
self.reload_button.setIconSize(QSize(20, 20))
122131
self.reload_button.setStyleSheet("background-color: transparent; border: none;")
123132
self.reload_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
124133

125134
self.bookmark_button = QPushButton()
126135
self.bookmark_button.clicked.connect(self.bookmark)
127-
self.bookmark_button.setIcon(QIcon("public/img/bookmark-regular.png"))
136+
self.bookmark_button.setIcon(QIcon(f"{config_anka}/public/img/bookmark-regular.png"))
128137
self.bookmark_button.setFixedSize(QSize(20,20))
129138
self.bookmark_button.setIconSize(QSize(20,20))
130139
self.bookmark_button.setStyleSheet("background-color: transparent; border: none;")
131140
self.bookmark_button.setCursor(Qt.CursorShape.PointingHandCursor)
132141

133142

134143
self.settings_button = QPushButton()
135-
self.settings_button.clicked.connect(self.open_settings)
136-
self.settings_button.setIcon(QIcon("public/img/settingsbar.png"))
144+
self.settings_button.setIcon(QIcon(f"{config_anka}/public/img/settingsbar.png"))
137145
self.settings_button.setFixedSize(QSize(20, 20))
138146
self.settings_button.setIconSize(QSize(20, 20))
139147
self.settings_button.setStyleSheet("background-color: transparent; border: none; margin-right: 8px;")
140148
self.settings_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
149+
self.settings_button.clicked.connect(self.show_settings_menu)
141150

142151
top_layout = QHBoxLayout()
143152
top_layout.setContentsMargins(0,0,0,0)
@@ -167,16 +176,54 @@ def __init__(self):
167176

168177
self.setWindowTitle("Anka")
169178
self.showMaximized()
170-
self.setWindowIcon(QIcon("public/img/logo.ico"))
179+
self.setWindowIcon(QIcon(f"{config_anka}/public/img/logo.ico"))
171180
self.resize(1920, 1080)
172181

173182
self.tabs.currentChanged.connect(self.update_url_from_tab)
174183

175-
184+
def show_settings_menu(self):
185+
menu = QMenu(self)
186+
history_action = QAction(texts['history'], self)
187+
history_action.triggered.connect(self.show_history)
188+
menu.addAction(history_action)
189+
190+
settings_action = QAction(texts['settings'], self)
191+
settings_action.triggered.connect(self.open_settings)
192+
menu.addAction(settings_action)
193+
194+
button_position = self.settings_button.mapToGlobal(QPoint(0, self.settings_button.height()))
195+
menu.exec(button_position)
196+
197+
def show_history(self):
198+
history_dialog = QDialog(self)
199+
history_dialog.setWindowTitle("History")
200+
history_dialog.setFixedSize(600, 400)
201+
202+
layout = QVBoxLayout(history_dialog)
203+
204+
history_list = QListWidget()
205+
layout.addWidget(history_list)
206+
207+
# Load history from file
208+
if os.path.exists(history):
209+
with open(history, 'r', encoding="utf-8") as file:
210+
lines = file.readlines()
211+
for line in lines:
212+
line = line.strip()
213+
if line:
214+
history_list.addItem(line)
215+
216+
close_button = QPushButton(texts['close'])
217+
close_button.clicked.connect(history_dialog.close)
218+
layout.addWidget(close_button)
219+
220+
history_dialog.exec()
221+
222+
176223
def add_new_tab(self, url, label):
177224
new_browser = QWebEngineView()
178225
new_browser.setUrl(QUrl(search_engine))
179-
self.tabs.addTab(new_browser, label)
226+
self.tabs.addTab(new_browser, self.truncate_tab_text(label))
180227
self.tabs.setCurrentWidget(new_browser)
181228

182229
self.close_tab_button = QPushButton()
@@ -187,6 +234,7 @@ def add_new_tab(self, url, label):
187234
new_browser.urlChanged.connect(lambda q: self.update_url(q))
188235
new_browser.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
189236
new_browser.customContextMenuRequested.connect(self.show_context_menu)
237+
190238
def close_tab(self, index):
191239
if self.tabs.count() == 1:
192240
exit()
@@ -195,7 +243,13 @@ def close_tab(self, index):
195243

196244
def update_title(self, browser, title):
197245
index = self.tabs.indexOf(browser)
198-
self.tabs.setTabText(index, title if title else tab_name)
246+
#self.tabs.setTabText(index, title if title else tab_name)
247+
self.tabs.setTabText(index, self.truncate_tab_text(title if title else tab_name))
248+
249+
def truncate_tab_text(self, text):
250+
if len(text) > self.max_tab_text_length:
251+
return text[:self.max_tab_text_length] + "..."
252+
return text
199253

200254
def add_new_tab_button(self):
201255
self.add_new_tab(search_engine, tab_name)
@@ -221,9 +275,11 @@ def update_url_from_tab(self):
221275
self.url_bar.setText(current_url.toString())
222276

223277
def load_url(self):
224-
url = self.url_bar.text()
225-
if url.startswith("http://") or url.startswith("https://"):
226-
url = url
278+
url = self.url_bar.text().strip()
279+
280+
if re.match(r"^[^\s]+\.[^\s]+$", url):
281+
if not url.startswith("http://") and not url.startswith("https://"):
282+
url = "http://" + url
227283
else:
228284
if search_engine == "https://duckduckgo.com":
229285
url = search_engine + "/?q=" + url
@@ -280,7 +336,7 @@ def browser_save(self):
280336
current_browser.page().toHtml(self.save_html)
281337

282338
def save_html(self, html):
283-
file_name, _ = QFileDialog.getSaveFileName(self, "Kaydet", "", "HTML Dosyası (*.html);;WEBP Dosyası(*.webp);;Tüm Dosyalar (*)")
339+
file_name, _ = QFileDialog.getSaveFileName(self, texts['right-click-save'], "", f"{texts['html_file']} (*.html);;{texts['webp_file']}(*.webp);;{texts['all_files']} (*)")
284340
if file_name:
285341
with open(file_name, 'w', encoding='utf-8') as file:
286342
file.write(html)
@@ -310,9 +366,6 @@ def load_bookmarks(self, top_layout):
310366
bookmark_button.clicked.connect(lambda checked, url=url: self.add_new_tab(QUrl(url), url))
311367
top_layout.addWidget(bookmark_button)
312368

313-
314-
315-
316369

317370
class AnkaBrowserSettings(QDialog):
318371
def __init__(self, parent=None):
@@ -401,13 +454,12 @@ def ok(self):
401454
config["Settings"]["search_engine"] = "https://bing.com"
402455
elif s_engine == "Brave":
403456
config["Settings"]["search_engine"] = "https://search.brave.com"
404-
elif s_engine == "StartPage":
457+
elif s_engine == "Startpage":
405458
config["Settings"]["search_engine"] = "https://startpage.com"
406459

407-
408460
lan = self.language.currentData()
409461
config["Language"]["language"] = lan
410-
with open('config/config.conf', 'w' ) as configfile:
462+
with open(config_path, 'w' ) as configfile:
411463
config.write(configfile)
412464
self.accept()
413465

@@ -438,7 +490,7 @@ def __init__(self, parent=None):
438490
config["Appearance"]["tab_color"] = str(tabColor)
439491
config["Appearance"]["not_selected_tab_color"] = str(not_selected_tab_color)
440492

441-
with open('config/config.conf', 'w' ) as configfile:
493+
with open(config_path, 'w' ) as configfile:
442494
config.write(configfile)
443495

444496

public/browser/languages/en-US.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"right-click-back" : "Back",
88
"right-click-forward" : "Forward",
99
"right-click-reload" : "Reload",
10+
"settings": "Settings",
11+
"html_file": "HTML File",
12+
"webp_file": "WEBP File",
13+
"all_files": "All Files",
1014
"settings-title" : "Anka | Settings",
1115
"settings-search-engine" : "Search Engine: ",
1216
"settings-tab-color-label" : "Select tab color: ",
@@ -15,6 +19,8 @@
1519
"settings-info-msg" : "Please restart the browser for the changes to take effect.",
1620
"settings-button-ok" : "Ok",
1721
"settings-button-cancel" : "Cancel",
22+
"close": "Close",
23+
"history": "History",
1824
"tab-color-dialog-title" : "Anka | Select Color",
1925
"lang": "Language: "
2026
}

public/browser/languages/tr-TR.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"right-click-back" : "Geri",
88
"right-click-forward" : "İleri",
99
"right-click-reload" : "Yeniden Yükle",
10+
"settings": "Ayarlar",
11+
"html_file": "HTML Dosyası",
12+
"webp_file": "WEBP Dosyası",
13+
"all_files": "Tüm Dosyalar",
1014
"settings-title" : "Anka | Ayarlar",
1115
"settings-search-engine" : "Arama Motoru: ",
1216
"settings-tab-color-label" : "Sekme rengi seçin: ",
@@ -15,6 +19,8 @@
1519
"settings-info-msg" : "Değişikliklerin etkili olması için lütfen tarayıcıyı yeniden başlatın.",
1620
"settings-button-ok" : "Tamam",
1721
"settings-button-cancel" : "İptal",
22+
"close": "Kapat",
23+
"history": "Geçmiş",
1824
"tab-color-dialog-title" : "Anka | Renk Seçin",
1925
"lang": "Dil: "
2026
}

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
PyQt6
22
PyQt6-WebEngine
3+
pyinstaller

0 commit comments

Comments
 (0)