WebBrowserView: Added a custom title() method.

Tue, 13 Feb 2018 19:54:17 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 13 Feb 2018 19:54:17 +0100
changeset 6147
0ea1f1e72463
parent 6146
94a4e8d1ac4f
child 6148
6c7af1e85e49

WebBrowserView: Added a custom title() method.

WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
--- a/WebBrowser/WebBrowserView.py	Tue Feb 13 19:53:35 2018 +0100
+++ b/WebBrowser/WebBrowserView.py	Tue Feb 13 19:54:17 2018 +0100
@@ -1638,6 +1638,29 @@
         from .Tools import WebIconProvider
         return WebIconProvider.instance().iconForUrl(self.url())
     
+    def title(self):
+        """
+        Public method to get the view title.
+        
+        @return view title
+        @rtype str
+        """
+        titleStr = super(WebBrowserView, self).title()
+        if not titleStr:
+            if self.url().isEmpty():
+                url = self.__page.requestedUrl()
+            else:
+                url = self.url()
+            
+            titleStr = url.host()
+            if not titleStr:
+                titleStr = url.toString(QUrl.RemoveFragment)
+            
+        if not titleStr or titleStr == "about:blank":
+            titleStr = self.tr("Empty Page")
+        
+        return titleStr
+    
     def __linkHovered(self, link):
         """
         Private slot to handle the linkHovered signal.

eric ide

mercurial