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

Commit df6ca2a

Browse files
authored
Update navegador.py
1 parent 5aa2a38 commit df6ca2a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

navegador.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def __init__(self):
2727

2828
self.setCentralWidget(self.tabs)
2929

30-
# Agora que self.tabs existe e tem uma guia, podemos conectar os botões
3130
# Botões da barra de navegação
3231
back_btn = QAction("⬅️ Voltar", self)
3332
back_btn.setStatusTip("Voltar para a página anterior")
@@ -53,17 +52,21 @@ def __init__(self):
5352
self.url_bar.returnPressed.connect(self.navigate_to_url)
5453
self.toolbar.addWidget(self.url_bar)
5554

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+
5661
# Botão para adicionar nova guia
5762
new_tab_btn = QAction("➕ Nova Guia", self)
5863
new_tab_btn.setStatusTip("Abrir uma nova guia")
5964
new_tab_btn.triggered.connect(lambda: self.add_new_tab())
6065
self.toolbar.addAction(new_tab_btn)
6166

62-
6367
self.add_new_tab(QUrl("https://www.google.com"), "Página Inicial")
6468
self.update_buttons_state()
6569

66-
6770
self.statusBar().hide()
6871

6972
def current_browser(self):
@@ -83,13 +86,15 @@ def add_new_tab(self, qurl=None, label="Nova Guia"):
8386
i = self.tabs.addTab(browser, label)
8487
self.tabs.setCurrentIndex(i)
8588

89+
# Conecta o sinal loadProgress DO OBJETO browser criado AGORA
90+
browser.loadProgress.connect(self.update_progress_bar)
91+
8692
browser.urlChanged.connect(lambda qurl_obj, browser=browser: self.update_urlbar(qurl_obj, browser))
8793
browser.loadStarted.connect(lambda: self.update_buttons_state())
8894
browser.loadFinished.connect(lambda success: self.update_buttons_state())
8995

9096
browser.titleChanged.connect(lambda title, browser=browser: self.tabs.setTabText(self.tabs.indexOf(browser), title))
9197

92-
9398
def tab_open_doubleclick(self, index):
9499
"""Abre uma nova guia ao dar clique duplo na barra de abas."""
95100
if index == -1:
@@ -152,7 +157,8 @@ def update_buttons_state(self):
152157

153158
for action in self.toolbar.actions():
154159
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)
156162
elif action.text() == "➡️ Avançar":
157163
action.setEnabled(browser is not None and can_go_forward)
158164
elif action.text() == "🔄 Recarregar":
@@ -162,6 +168,16 @@ def update_buttons_state(self):
162168
elif action.text() == "➕ Nova Guia":
163169
action.setEnabled(True)
164170

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)
165181

166182
if __name__ == "__main__":
167183
app = QApplication(sys.argv)

0 commit comments

Comments
 (0)