This repository was archived by the owner on May 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.py
More file actions
94 lines (71 loc) · 3.09 KB
/
Copy pathbrowser.py
File metadata and controls
94 lines (71 loc) · 3.09 KB
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
from PyQt6.QtGui import QIcon
from PyQt6.QtCore import QUrl
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QLineEdit, QPushButton, QHBoxLayout, QTabWidget, QTabBar
from PyQt6.QtWebEngineWidgets import QWebEngineView
import sys
class SimpleBrowser(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("VloBrowser")
self.setGeometry(100, 100, 800, 600)
# Setăm icon-ul
self.setWindowIcon(QIcon("favicon.ico"))
# Tab widget pentru taburi
self.tabs = QTabWidget()
self.setCentralWidget(self.tabs)
# Creăm un tab inițial
self.create_new_tab()
# Buton pentru a deschide un tab nou
self.new_tab_btn = QPushButton("New Tab")
self.new_tab_btn.clicked.connect(self.create_new_tab)
# Layout pentru bara de URL și butoane
self.url_bar = QLineEdit()
self.url_bar.setPlaceholderText("Enter URL...")
self.url_bar.returnPressed.connect(self.load_url)
self.back_btn = QPushButton("⬅")
self.back_btn.clicked.connect(self.browser.back)
self.forward_btn = QPushButton("➡")
self.forward_btn.clicked.connect(self.browser.forward)
top_layout = QHBoxLayout()
top_layout.addWidget(self.back_btn)
top_layout.addWidget(self.forward_btn)
top_layout.addWidget(self.url_bar)
top_layout.addWidget(self.new_tab_btn)
# Adăugăm bara de navigație în fereastra principală
container = QWidget()
layout = QVBoxLayout()
layout.addLayout(top_layout)
container.setLayout(layout)
self.setMenuWidget(container)
# Conectăm schimbarea de tab la actualizarea barei de URL
self.tabs.currentChanged.connect(self.update_url_bar)
def create_new_tab(self):
# Creăm o nouă instanță a browserului pentru tab
browser = QWebEngineView()
browser.setUrl(QUrl("https://www.google.com"))
# Creăm un tab pentru browserul nostru
tab_index = self.tabs.addTab(browser, "New Tab")
self.tabs.setCurrentIndex(tab_index)
# Creăm și un buton de închidere pentru acest tab
close_button = QPushButton("X")
close_button.clicked.connect(lambda: self.close_tab(tab_index))
self.tabs.tabBar().setTabButton(tab_index, QTabBar.ButtonPosition.RightSide, close_button) # Corectat aici
# Setăm browserul ca fiind activ pentru a actualiza bara de URL
self.browser = browser
def load_url(self):
url = self.url_bar.text()
if not url.startswith("http"):
url = "https://" + url
self.browser.setUrl(QUrl(url))
def update_url_bar(self):
# Actualizăm bara de URL pentru tab-ul activ
current_browser = self.tabs.currentWidget()
if current_browser:
self.url_bar.setText(current_browser.url().toString())
def close_tab(self, index):
# Închidem tabul la indexul dat
self.tabs.removeTab(index)
app = QApplication(sys.argv)
window = SimpleBrowser()
window.show()
sys.exit(app.exec())