Assuming you're using WebKit. You'll have to connect to the load-status
property signal to see if a new page is being requested and change the netry accordingly.
Here's a bit of code from an old project of mine.
# Snipped init and stuff...
self._webview = WebKit.WebView()
self._webview.connect('notify::load-status', self.on_load_status)
def on_load_status(self, webview, status):
status = webview.get_load_status()
if status == WebKit.LoadStatus.COMMITTED:
self._set_loading(True)
self._entry.set_text(webview.get_uri())
elif status == WebKit.LoadStatus.FINISHED:
self._set_loading(False)
def _set_loading(self, loading):
self._stop.set_sensitive(loading)
self._reload.set_sensitive(not loading)
self._back.set_sensitive(self._webview.can_go_back())
self._forward.set_sensitive(self._webview.can_go_forward())
The _set_loading()
method is used to enable/disable the stop/reload/back/forward buttons on the toolbar. If you don't have those, leave it out (otherwise, change the names to your needs ofcourse).