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

Commit 0439815

Browse files
authored
Update navegador.py
1 parent e039d30 commit 0439815

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

navegador.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def __init__(self):
6161

6262

6363
self.add_new_tab(QUrl("https://www.google.com"), "Página Inicial") # Adiciona a primeira guia
64+
# Após adicionar a primeira aba, garantimos que os botões sejam atualizados
65+
self.update_buttons_state()
66+
6467

6568
# Ocultar a barra de status por enquanto (pode ser adicionada depois se necessário)
6669
self.statusBar().hide()
@@ -144,13 +147,22 @@ def update_urlbar(self, q, browser=None):
144147
def update_buttons_state(self):
145148
"""Atualiza o estado (habilitado/desabilitado) dos botões de navegação."""
146149
browser = self.current_browser()
147-
# Itera sobre as ações da toolbar para encontrar os botões e atualizar seus estados
150+
if browser:
151+
# Acessa o histórico para verificar se pode voltar/avançar
152+
history = browser.history()
153+
can_go_back = history.canGoBack()
154+
can_go_forward = history.canGoForward()
155+
else:
156+
# Se não houver navegador, desabilita tudo
157+
can_go_back = False
158+
can_go_forward = False
159+
148160
for action in self.toolbar.actions():
149161
if action.text() == "⬅️ Voltar":
150-
# Habilita "Voltar" se houver um navegador e puder voltar, e não estiver na página inicial
151-
action.setEnabled(browser is not None and browser.canGoBack() and browser.url() != QUrl("https://www.google.com"))
162+
# Habilita "Voltar" se houver um navegador, puder voltar e não estiver na página inicial
163+
action.setEnabled(browser is not None and can_go_back and browser.url() != QUrl("https://www.google.com"))
152164
elif action.text() == "➡️ Avançar":
153-
action.setEnabled(browser is not None and browser.canGoForward())
165+
action.setEnabled(browser is not None and can_go_forward)
154166
elif action.text() == "🔄 Recarregar":
155167
action.setEnabled(browser is not None) # Recarregar sempre que houver um navegador
156168
elif action.text() == "🏠 Início":

0 commit comments

Comments
 (0)