Web Browser: implemented a fix for QtWebEngine not sending the loadFinished signal when navigating on the same page.

Tue, 05 May 2020 18:18:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 05 May 2020 18:18:27 +0200
changeset 7578
13b2c2167c93
parent 7577
6eaa43d3786e
child 7579
7cf1eb7687be

Web Browser: implemented a fix for QtWebEngine not sending the loadFinished signal when navigating on the same page.

eric6/WebBrowser/Navigation/NavigationBar.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserTabWidget.py file | annotate | diff | comparison | revisions
--- a/eric6/WebBrowser/Navigation/NavigationBar.py	Tue May 05 18:17:20 2020 +0200
+++ b/eric6/WebBrowser/Navigation/NavigationBar.py	Tue May 05 18:18:27 2020 +0200
@@ -233,7 +233,7 @@
         for index in range(len(backItems) - 1, -1, -1):
             item = backItems[index]
             act = QAction(self)
-            act.setData(-1 * (index + 1))
+            act.setData(item)
             icon = WebBrowserWindow.icon(item.url())
             act.setIcon(icon)
             act.setText(item.title())
@@ -260,7 +260,7 @@
         for index in range(len(forwardItems)):
             item = forwardItems[index]
             act = QAction(self)
-            act.setData(index + 1)
+            act.setData(item)
             icon = WebBrowserWindow.icon(item.url())
             act.setIcon(icon)
             act.setText(item.title())
@@ -281,18 +281,10 @@
         @param act reference to the action selected in the navigation menu
             (QAction)
         """
-        offset = act.data()
-        if offset is not None:
+        historyItem = act.data()
+        if historyItem is not None:
             history = self.__mw.currentBrowser().history()
-            historyCount = history.count()
-            if offset < 0:
-                # go back
-                history.goToItem(
-                    history.backItems(historyCount)[-1 * offset - 1])
-            else:
-                # go forward
-                history.goToItem(
-                    history.forwardItems(historyCount)[offset - 1])
+            history.goToItem(historyItem)
     
     def __goBack(self):
         """
--- a/eric6/WebBrowser/WebBrowserTabWidget.py	Tue May 05 18:17:20 2020 +0200
+++ b/eric6/WebBrowser/WebBrowserTabWidget.py	Tue May 05 18:18:27 2020 +0200
@@ -428,8 +428,8 @@
         browser.backwardAvailable.connect(
             self.__mainWindow.setBackwardAvailable)
         browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable)
-        browser.loadStarted.connect(
-            lambda: self.__loadStarted(browser))
+        browser.loadProgress.connect(
+            lambda progress: self.__loadProgress(progress, browser))
         browser.loadFinished.connect(
             lambda ok: self.__loadFinished(ok, browser))
         browser.faviconChanged.connect(
@@ -874,25 +874,6 @@
         for urlbar in self.__stackedUrlBar.urlBars():
             urlbar.preferencesChanged()
     
-    def __loadStarted(self, browser):
-        """
-        Private method to handle the loadStarted signal.
-        
-        @param browser reference to the web browser
-        @type WebBrowserView
-        """
-        index = self.indexOf(browser)
-        anim = self.animationLabel(index, "loadingAnimation", 40)
-        if not anim:
-            self.setTabIcon(index, UI.PixmapCache.getIcon("loading"))
-        else:
-            self.setTabIcon(index, QIcon())
-        self.setTabText(index, self.tr("Loading..."))
-        self.setTabToolTip(index, self.tr("Loading..."))
-        self.showMessage.emit(self.tr("Loading..."))
-        
-        self.__mainWindow.setLoadingActions(True)
-    
     def __loadFinished(self, ok, browser):
         """
         Private method to handle the loadFinished signal.
@@ -902,18 +883,45 @@
         @param browser reference to the web browser
         @type WebBrowserView
         """
-        import WebBrowser.WebBrowserWindow
-        index = self.indexOf(browser)
-        self.resetAnimation(index)
-        self.setTabIcon(
-            index, WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(
-                browser.url()))
         if ok:
             self.showMessage.emit(self.tr("Finished loading"))
         else:
             self.showMessage.emit(self.tr("Failed to load"))
+    
+    def __loadProgress(self, progress, browser):
+        """
+        Private method to handle the loadProgress signal.
         
-        self.__mainWindow.setLoadingActions(False)
+        Note: This works around wegengine not sending a loadFinished
+        signal for navigation on the same page.
+        
+        @param progress load progress in percent
+        @type int
+        @param browser reference to the web browser
+        @type WebBrowserView
+        """
+        index = self.indexOf(browser)
+        if progress == 0:
+            # page loading has started
+            anim = self.animationLabel(index, "loadingAnimation", 40)
+            if not anim:
+                self.setTabIcon(index, UI.PixmapCache.getIcon("loading"))
+            else:
+                self.setTabIcon(index, QIcon())
+            self.setTabText(index, self.tr("Loading..."))
+            self.setTabToolTip(index, self.tr("Loading..."))
+            self.showMessage.emit(self.tr("Loading..."))
+            
+            self.__mainWindow.setLoadingActions(True)
+        elif progress == 100:
+            import WebBrowser.WebBrowserWindow
+            self.resetAnimation(index)
+            self.setTabIcon(
+                index, WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(
+                    browser.url()))
+            self.showMessage.emit(self.tr("Finished loading"))
+            
+            self.__mainWindow.setLoadingActions(False)
     
     def __iconChanged(self, browser):
         """

eric ide

mercurial