1
1
import sys
2
- from PyQt5 .QtCore import *
3
- from PyQt5 .QtWidgets import *
4
- from PyQt5 .QtWebEngineWidgets import *
2
+ from PyQt6 .QtCore import QUrl , Qt # Alterado para PyQt6
3
+ from PyQt6 .QtWidgets import QApplication , QMainWindow , QToolBar , QLineEdit , QAction , QTabWidget , QProgressBar # Alterado para PyQt6
4
+ from PyQt6 .QtWebEngineWidgets import QWebEngineView # Alterado para PyQt6
5
+
5
6
6
7
class BrowserTab (QWebEngineView ):
7
8
def __init__ (self , parent = None ):
@@ -19,6 +20,12 @@ def __init__(self):
19
20
self .toolbar = QToolBar ("Navegação" )
20
21
self .addToolBar (self .toolbar )
21
22
23
+ # Barra de progresso - INCLUSÃO DO PROGRESS BAR
24
+ self .progress_bar = QProgressBar ()
25
+ self .progress_bar .setMaximumWidth (150 )
26
+ self .progress_bar .setVisible (False )
27
+ self .toolbar .addWidget (self .progress_bar )
28
+
22
29
# --- Suporte a Guias ---
23
30
self .tabs = QTabWidget () # Primeiro, inicialize o QTabWidget
24
31
self .tabs .setDocumentMode (True ) # Modo de documento (aparência mais moderna)
@@ -52,12 +59,6 @@ def __init__(self):
52
59
self .url_bar .returnPressed .connect (self .navigate_to_url )
53
60
self .toolbar .addWidget (self .url_bar )
54
61
55
- # Adiciona a barra de progresso aqui
56
- self .progress_bar = QProgressBar ()
57
- self .progress_bar .setMaximumWidth (150 ) # Opcional: Define uma largura máxima
58
- self .progress_bar .setVisible (False ) # Começa invisível
59
- self .toolbar .addWidget (self .progress_bar )
60
-
61
62
# Botão para adicionar nova guia
62
63
new_tab_btn = QAction ("➕ Nova Guia" , self )
63
64
new_tab_btn .setStatusTip ("Abrir uma nova guia" )
@@ -86,12 +87,10 @@ def add_new_tab(self, qurl=None, label="Nova Guia"):
86
87
i = self .tabs .addTab (browser , label )
87
88
self .tabs .setCurrentIndex (i )
88
89
89
- # Conecta o sinal loadProgress DO OBJETO browser criado AGORA
90
- browser .loadProgress .connect (self .update_progress_bar )
91
-
92
90
browser .urlChanged .connect (lambda qurl_obj , browser = browser : self .update_urlbar (qurl_obj , browser ))
93
91
browser .loadStarted .connect (lambda : self .update_buttons_state ())
94
92
browser .loadFinished .connect (lambda success : self .update_buttons_state ())
93
+ browser .loadProgress .connect (self .update_progress_bar ) # Conecta o sinal de progresso
95
94
96
95
browser .titleChanged .connect (lambda title , browser = browser : self .tabs .setTabText (self .tabs .indexOf (browser ), title ))
97
96
@@ -128,12 +127,9 @@ def navigate_to_url(self):
128
127
if "." in url and not " " in url :
129
128
url = "https://" + url
130
129
else :
131
- # --- AQUI ESTÁ A CORREÇÃO ---
132
- # Codifica o termo de busca para bytes e depois o decodifica para string normal antes de usar
133
130
search_query_bytes = QUrl .toPercentEncoding (url )
134
- search_query_str = search_query_bytes .data ().decode ('utf-8' ) # Converte QByteArray para string UTF-8
131
+ search_query_str = search_query_bytes .data ().decode ('utf-8' )
135
132
url = f"https://www.google.com/search?q={ search_query_str } "
136
- # ----------------------------
137
133
138
134
browser .setUrl (QUrl (url ))
139
135
self .update_buttons_state ()
@@ -157,7 +153,7 @@ def update_buttons_state(self):
157
153
158
154
for action in self .toolbar .actions ():
159
155
if action .text () == "⬅️ Voltar" :
160
- # Modificado para desabilitar "Voltar" apenas se não houver histórico REAL, não só se for Google.
156
+ # A condição foi simplificada para apenas 'can_go_back', pois o browser.url() != Google.com é muito restritivo para o botão Voltar
161
157
action .setEnabled (browser is not None and can_go_back )
162
158
elif action .text () == "➡️ Avançar" :
163
159
action .setEnabled (browser is not None and can_go_forward )
0 commit comments