Some slight improvements for the HTML previewer.

Fri, 11 Aug 2017 17:50:49 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 11 Aug 2017 17:50:49 +0200
changeset 5845
f3d2172d663e
parent 5844
1294772ac8e6
child 5846
b3cc692e3bfe

Some slight improvements for the HTML previewer.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.UI.Previewers.PreviewerHTML.html file | annotate | diff | comparison | revisions
UI/Previewers/PreviewerHTML.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Fri Aug 11 14:41:23 2017 +0200
+++ b/Documentation/Help/source.qhp	Fri Aug 11 17:50:49 2017 +0200
@@ -11044,6 +11044,7 @@
       <keyword name="PreviewerHTML.__saveScrollBarPositions" id="PreviewerHTML.__saveScrollBarPositions" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.__saveScrollBarPositions" />
       <keyword name="PreviewerHTML.__setHtml" id="PreviewerHTML.__setHtml" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.__setHtml" />
       <keyword name="PreviewerHTML.__setJavaScriptEnabled" id="PreviewerHTML.__setJavaScriptEnabled" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.__setJavaScriptEnabled" />
+      <keyword name="PreviewerHTML.__showLink" id="PreviewerHTML.__showLink" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.__showLink" />
       <keyword name="PreviewerHTML.on_jsCheckBox_clicked" id="PreviewerHTML.on_jsCheckBox_clicked" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.on_jsCheckBox_clicked" />
       <keyword name="PreviewerHTML.on_previewView_linkClicked" id="PreviewerHTML.on_previewView_linkClicked" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.on_previewView_linkClicked" />
       <keyword name="PreviewerHTML.on_previewView_titleChanged" id="PreviewerHTML.on_previewView_titleChanged" ref="eric6.UI.Previewers.PreviewerHTML.html#PreviewerHTML.on_previewView_titleChanged" />
--- a/Documentation/Source/eric6.UI.Previewers.PreviewerHTML.html	Fri Aug 11 14:41:23 2017 +0200
+++ b/Documentation/Source/eric6.UI.Previewers.PreviewerHTML.html	Fri Aug 11 17:50:49 2017 +0200
@@ -52,10 +52,11 @@
     previewer view.
 </p><h3>Signals</h3>
 <dl>
-<dt>htmlReady(str,str)</dt>
+<dt>htmlReady(str, str, str)</dt>
 <dd>
-emitted with the file name and processed HTML
-        to signal the availability of the processed HTML
+emitted with the file name, the processed
+        HTML and the web site root path to signal the availability of the
+        processed HTML
 </dd>
 </dl>
 <h3>Derived from</h3>
@@ -343,6 +344,9 @@
 <td><a href="#PreviewerHTML.__setJavaScriptEnabled">__setJavaScriptEnabled</a></td>
 <td>Private method to enable/disable JavaScript.</td>
 </tr><tr>
+<td><a href="#PreviewerHTML.__showLink">__showLink</a></td>
+<td>Private slot to show the hovered link in a tooltip.</td>
+</tr><tr>
 <td><a href="#PreviewerHTML.on_jsCheckBox_clicked">on_jsCheckBox_clicked</a></td>
 <td>Private slot to enable/disable JavaScript.</td>
 </tr><tr>
@@ -411,17 +415,20 @@
         Private method to save scroll bar positions for a previewed editor.
 </p><a NAME="PreviewerHTML.__setHtml" ID="PreviewerHTML.__setHtml"></a>
 <h4>PreviewerHTML.__setHtml</h4>
-<b>__setHtml</b>(<i>filePath, html</i>)
+<b>__setHtml</b>(<i>filePath, html, rootPath</i>)
 <p>
         Private method to set the HTML to the view and restore the scroll bars
         positions.
 </p><dl>
-<dt><i>filePath</i></dt>
+<dt><i>filePath</i> (str)</dt>
+<dd>
+file path of the previewed editor
+</dd><dt><i>html</i> (str)</dt>
 <dd>
-file path of the previewed editor (string)
-</dd><dt><i>html</i></dt>
+processed HTML text ready to be shown
+</dd><dt><i>rootPath</i> (str)</dt>
 <dd>
-processed HTML text ready to be shown (string)
+path of the web site root
 </dd>
 </dl><a NAME="PreviewerHTML.__setJavaScriptEnabled" ID="PreviewerHTML.__setJavaScriptEnabled"></a>
 <h4>PreviewerHTML.__setJavaScriptEnabled</h4>
@@ -433,6 +440,16 @@
 <dd>
 flag indicating the enable state (boolean)
 </dd>
+</dl><a NAME="PreviewerHTML.__showLink" ID="PreviewerHTML.__showLink"></a>
+<h4>PreviewerHTML.__showLink</h4>
+<b>__showLink</b>(<i>urlStr</i>)
+<p>
+        Private slot to show the hovered link in a tooltip.
+</p><dl>
+<dt><i>urlStr</i> (str)</dt>
+<dd>
+hovered URL
+</dd>
 </dl><a NAME="PreviewerHTML.on_jsCheckBox_clicked" ID="PreviewerHTML.on_jsCheckBox_clicked"></a>
 <h4>PreviewerHTML.on_jsCheckBox_clicked</h4>
 <b>on_jsCheckBox_clicked</b>(<i>checked</i>)
--- a/UI/Previewers/PreviewerHTML.py	Fri Aug 11 14:41:23 2017 +0200
+++ b/UI/Previewers/PreviewerHTML.py	Fri Aug 11 17:50:49 2017 +0200
@@ -22,8 +22,9 @@
 import sys
 
 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QSize, QThread
+from PyQt5.QtGui import QCursor
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, \
-    QSizePolicy
+    QSizePolicy, QToolTip
 
 from E5Gui.E5Application import e5App
 
@@ -53,6 +54,7 @@
         try:
             from PyQt5.QtWebEngineWidgets import QWebEngineView
             self.previewView = QWebEngineView(self)
+            self.previewView.page().linkHovered.connect(self.__showLink)
             self.__usesWebKit = False
         except ImportError:
             from PyQt5.QtWebKitWidgets import QWebPage, QWebView
@@ -143,6 +145,16 @@
         Preferences.setUI("ShowFilePreviewSSI", checked)
         self.processEditor()
     
+    @pyqtSlot(str)
+    def __showLink(self, urlStr):
+        """
+        Private slot to show the hovered link in a tooltip.
+        
+        @param urlStr hovered URL
+        @type str
+        """
+        QToolTip.showText(QCursor.pos(), urlStr, self.previewView)
+    
     def processEditor(self, editor=None):
         """
         Public slot to process an editor's text.
@@ -196,13 +208,17 @@
                     Preferences.getEditor("PreviewMarkdownHTMLFormat"),
                     Preferences.getEditor("PreviewRestDocutilsHTMLFormat"))
 
-    def __setHtml(self, filePath, html):
+    def __setHtml(self, filePath, html, rootPath):
         """
         Private method to set the HTML to the view and restore the scroll bars
         positions.
         
-        @param filePath file path of the previewed editor (string)
-        @param html processed HTML text ready to be shown (string)
+        @param filePath file path of the previewed editor
+        @type str
+        @param html processed HTML text ready to be shown
+        @type str
+        @param rootPath path of the web site root
+        @type str
         """
         self.__previewedPath = Utilities.normcasepath(
             Utilities.fromNativeSeparators(filePath))
@@ -215,7 +231,11 @@
                 self.__restoreScrollBarPositions)
             if not filePath:
                 filePath = "/"
-        self.previewView.setHtml(html, baseUrl=QUrl.fromLocalFile(filePath))
+        if rootPath:
+            baseUrl = QUrl.fromLocalFile(rootPath + "/index.html")
+        else:
+            baseUrl = QUrl.fromLocalFile(filePath)
+        self.previewView.setHtml(html, baseUrl=baseUrl)
         if self.__previewedEditor:
             self.__previewedEditor.setFocus()
     
@@ -343,10 +363,11 @@
     Class implementing a thread to process some text into HTML usable by the
     previewer view.
     
-    @signal htmlReady(str,str) emitted with the file name and processed HTML
-        to signal the availability of the processed HTML
+    @signal htmlReady(str, str, str) emitted with the file name, the processed
+        HTML and the web site root path to signal the availability of the
+        processed HTML
     """
-    htmlReady = pyqtSignal(str, str)
+    htmlReady = pyqtSignal(str, str, str)
     
     def __init__(self, parent=None):
         """
@@ -418,7 +439,7 @@
             
             with self.__lock:
                 if not self.__haveData:
-                    self.htmlReady.emit(filePath, html)
+                    self.htmlReady.emit(filePath, html, rootPath)
                     break
                 # else - next iteration
     

eric ide

mercurial