@@ -27,7 +27,6 @@ def __init__(self):
27
27
28
28
self .setCentralWidget (self .tabs )
29
29
30
- # Agora que self.tabs existe e tem uma guia, podemos conectar os botões
31
30
# Botões da barra de navegação
32
31
back_btn = QAction ("⬅️ Voltar" , self )
33
32
back_btn .setStatusTip ("Voltar para a página anterior" )
@@ -53,17 +52,21 @@ def __init__(self):
53
52
self .url_bar .returnPressed .connect (self .navigate_to_url )
54
53
self .toolbar .addWidget (self .url_bar )
55
54
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
+
56
61
# Botão para adicionar nova guia
57
62
new_tab_btn = QAction ("➕ Nova Guia" , self )
58
63
new_tab_btn .setStatusTip ("Abrir uma nova guia" )
59
64
new_tab_btn .triggered .connect (lambda : self .add_new_tab ())
60
65
self .toolbar .addAction (new_tab_btn )
61
66
62
-
63
67
self .add_new_tab (QUrl ("https://www.google.com" ), "Página Inicial" )
64
68
self .update_buttons_state ()
65
69
66
-
67
70
self .statusBar ().hide ()
68
71
69
72
def current_browser (self ):
@@ -83,13 +86,15 @@ def add_new_tab(self, qurl=None, label="Nova Guia"):
83
86
i = self .tabs .addTab (browser , label )
84
87
self .tabs .setCurrentIndex (i )
85
88
89
+ # Conecta o sinal loadProgress DO OBJETO browser criado AGORA
90
+ browser .loadProgress .connect (self .update_progress_bar )
91
+
86
92
browser .urlChanged .connect (lambda qurl_obj , browser = browser : self .update_urlbar (qurl_obj , browser ))
87
93
browser .loadStarted .connect (lambda : self .update_buttons_state ())
88
94
browser .loadFinished .connect (lambda success : self .update_buttons_state ())
89
95
90
96
browser .titleChanged .connect (lambda title , browser = browser : self .tabs .setTabText (self .tabs .indexOf (browser ), title ))
91
97
92
-
93
98
def tab_open_doubleclick (self , index ):
94
99
"""Abre uma nova guia ao dar clique duplo na barra de abas."""
95
100
if index == - 1 :
@@ -152,7 +157,8 @@ def update_buttons_state(self):
152
157
153
158
for action in self .toolbar .actions ():
154
159
if action .text () == "⬅️ Voltar" :
155
- action .setEnabled (browser is not None and can_go_back and browser .url () != QUrl ("https://www.google.com" ))
160
+ # Modificado para desabilitar "Voltar" apenas se não houver histórico REAL, não só se for Google.
161
+ action .setEnabled (browser is not None and can_go_back )
156
162
elif action .text () == "➡️ Avançar" :
157
163
action .setEnabled (browser is not None and can_go_forward )
158
164
elif action .text () == "🔄 Recarregar" :
@@ -162,6 +168,16 @@ def update_buttons_state(self):
162
168
elif action .text () == "➕ Nova Guia" :
163
169
action .setEnabled (True )
164
170
171
+ def update_progress_bar (self , progress ):
172
+ """Atualiza a barra de progresso e a mostra/esconde."""
173
+ if progress < 100 and progress > 0 :
174
+ self .progress_bar .setValue (progress )
175
+ self .progress_bar .setVisible (True )
176
+ elif progress == 100 :
177
+ self .progress_bar .setVisible (False )
178
+ else : # progress == 0 (quando o carregamento começa)
179
+ self .progress_bar .setValue (0 )
180
+ self .progress_bar .setVisible (True )
165
181
166
182
if __name__ == "__main__" :
167
183
app = QApplication (sys .argv )
0 commit comments