20 import shutil |
20 import shutil |
21 import tempfile |
21 import tempfile |
22 import sys |
22 import sys |
23 |
23 |
24 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QSize, QThread |
24 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QSize, QThread |
|
25 from PyQt5.QtGui import QCursor |
25 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, \ |
26 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, \ |
26 QSizePolicy |
27 QSizePolicy, QToolTip |
27 |
28 |
28 from E5Gui.E5Application import e5App |
29 from E5Gui.E5Application import e5App |
29 |
30 |
30 import Utilities |
31 import Utilities |
31 import Preferences |
32 import Preferences |
51 self.__layout.addWidget(self.titleLabel) |
52 self.__layout.addWidget(self.titleLabel) |
52 |
53 |
53 try: |
54 try: |
54 from PyQt5.QtWebEngineWidgets import QWebEngineView |
55 from PyQt5.QtWebEngineWidgets import QWebEngineView |
55 self.previewView = QWebEngineView(self) |
56 self.previewView = QWebEngineView(self) |
|
57 self.previewView.page().linkHovered.connect(self.__showLink) |
56 self.__usesWebKit = False |
58 self.__usesWebKit = False |
57 except ImportError: |
59 except ImportError: |
58 from PyQt5.QtWebKitWidgets import QWebPage, QWebView |
60 from PyQt5.QtWebKitWidgets import QWebPage, QWebView |
59 self.previewView = QWebView(self) |
61 self.previewView = QWebView(self) |
60 self.previewView.page().setLinkDelegationPolicy( |
62 self.previewView.page().setLinkDelegationPolicy( |
140 |
142 |
141 @param checked state of the checkbox (boolean) |
143 @param checked state of the checkbox (boolean) |
142 """ |
144 """ |
143 Preferences.setUI("ShowFilePreviewSSI", checked) |
145 Preferences.setUI("ShowFilePreviewSSI", checked) |
144 self.processEditor() |
146 self.processEditor() |
|
147 |
|
148 @pyqtSlot(str) |
|
149 def __showLink(self, urlStr): |
|
150 """ |
|
151 Private slot to show the hovered link in a tooltip. |
|
152 |
|
153 @param urlStr hovered URL |
|
154 @type str |
|
155 """ |
|
156 QToolTip.showText(QCursor.pos(), urlStr, self.previewView) |
145 |
157 |
146 def processEditor(self, editor=None): |
158 def processEditor(self, editor=None): |
147 """ |
159 """ |
148 Public slot to process an editor's text. |
160 Public slot to process an editor's text. |
149 |
161 |
194 Preferences.getEditor("PreviewRestUseSphinx"), |
206 Preferences.getEditor("PreviewRestUseSphinx"), |
195 Preferences.getEditor("PreviewMarkdownNLtoBR"), |
207 Preferences.getEditor("PreviewMarkdownNLtoBR"), |
196 Preferences.getEditor("PreviewMarkdownHTMLFormat"), |
208 Preferences.getEditor("PreviewMarkdownHTMLFormat"), |
197 Preferences.getEditor("PreviewRestDocutilsHTMLFormat")) |
209 Preferences.getEditor("PreviewRestDocutilsHTMLFormat")) |
198 |
210 |
199 def __setHtml(self, filePath, html): |
211 def __setHtml(self, filePath, html, rootPath): |
200 """ |
212 """ |
201 Private method to set the HTML to the view and restore the scroll bars |
213 Private method to set the HTML to the view and restore the scroll bars |
202 positions. |
214 positions. |
203 |
215 |
204 @param filePath file path of the previewed editor (string) |
216 @param filePath file path of the previewed editor |
205 @param html processed HTML text ready to be shown (string) |
217 @type str |
|
218 @param html processed HTML text ready to be shown |
|
219 @type str |
|
220 @param rootPath path of the web site root |
|
221 @type str |
206 """ |
222 """ |
207 self.__previewedPath = Utilities.normcasepath( |
223 self.__previewedPath = Utilities.normcasepath( |
208 Utilities.fromNativeSeparators(filePath)) |
224 Utilities.fromNativeSeparators(filePath)) |
209 self.__saveScrollBarPositions() |
225 self.__saveScrollBarPositions() |
210 if self.__usesWebKit: |
226 if self.__usesWebKit: |
213 else: |
229 else: |
214 self.previewView.page().loadFinished.connect( |
230 self.previewView.page().loadFinished.connect( |
215 self.__restoreScrollBarPositions) |
231 self.__restoreScrollBarPositions) |
216 if not filePath: |
232 if not filePath: |
217 filePath = "/" |
233 filePath = "/" |
218 self.previewView.setHtml(html, baseUrl=QUrl.fromLocalFile(filePath)) |
234 if rootPath: |
|
235 baseUrl = QUrl.fromLocalFile(rootPath + "/index.html") |
|
236 else: |
|
237 baseUrl = QUrl.fromLocalFile(filePath) |
|
238 self.previewView.setHtml(html, baseUrl=baseUrl) |
219 if self.__previewedEditor: |
239 if self.__previewedEditor: |
220 self.__previewedEditor.setFocus() |
240 self.__previewedEditor.setFocus() |
221 |
241 |
222 @pyqtSlot(str) |
242 @pyqtSlot(str) |
223 def on_previewView_titleChanged(self, title): |
243 def on_previewView_titleChanged(self, title): |
341 class PreviewProcessingThread(QThread): |
361 class PreviewProcessingThread(QThread): |
342 """ |
362 """ |
343 Class implementing a thread to process some text into HTML usable by the |
363 Class implementing a thread to process some text into HTML usable by the |
344 previewer view. |
364 previewer view. |
345 |
365 |
346 @signal htmlReady(str,str) emitted with the file name and processed HTML |
366 @signal htmlReady(str, str, str) emitted with the file name, the processed |
347 to signal the availability of the processed HTML |
367 HTML and the web site root path to signal the availability of the |
|
368 processed HTML |
348 """ |
369 """ |
349 htmlReady = pyqtSignal(str, str) |
370 htmlReady = pyqtSignal(str, str, str) |
350 |
371 |
351 def __init__(self, parent=None): |
372 def __init__(self, parent=None): |
352 """ |
373 """ |
353 Constructor |
374 Constructor |
354 |
375 |
416 rootPath, useSphinx, convertNewLineToBreak, |
437 rootPath, useSphinx, convertNewLineToBreak, |
417 markdownHtmlFormat, restDocutilsHtmlFormat) |
438 markdownHtmlFormat, restDocutilsHtmlFormat) |
418 |
439 |
419 with self.__lock: |
440 with self.__lock: |
420 if not self.__haveData: |
441 if not self.__haveData: |
421 self.htmlReady.emit(filePath, html) |
442 self.htmlReady.emit(filePath, html, rootPath) |
422 break |
443 break |
423 # else - next iteration |
444 # else - next iteration |
424 |
445 |
425 def __getHtml(self, language, text, ssiEnabled, filePath, rootPath, |
446 def __getHtml(self, language, text, ssiEnabled, filePath, rootPath, |
426 useSphinx, convertNewLineToBreak, markdownHtmlFormat, |
447 useSphinx, convertNewLineToBreak, markdownHtmlFormat, |