Sun, 14 Apr 2019 15:09:21 +0200
Major restructuring of the source tree to get prepared for a setup.py based installation.
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
6645
ad476851d7e0
Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6372
diff
changeset
|
3 | # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
3459
275cb00c83e2
Continued adding QSS preview support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3458
diff
changeset
|
7 | Module implementing a previewer widget for HTML, Markdown and ReST files. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
10 | from __future__ import unicode_literals |
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
11 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
12 | try: # Only for Py2 |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
13 | import StringIO as io # __IGNORE_EXCEPTION__ |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
14 | str = unicode |
4975
c71c0afee067
Added a few changes to improve the situation where Py2/3 compatibility packages are installed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4929
diff
changeset
|
15 | except (ImportError, NameError): |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
16 | import io # __IGNORE_WARNING__ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
17 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | import os |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | import threading |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | import re |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
21 | import shutil |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
22 | import tempfile |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
23 | import sys |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
25 | from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QSize, QThread |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
26 | from PyQt5.QtGui import QCursor |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
27 | from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, \ |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
28 | QSizePolicy, QToolTip |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | from E5Gui.E5Application import e5App |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | import Utilities |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | import Preferences |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
36 | class PreviewerHTML(QWidget): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | Class implementing a previewer widget for HTML, Markdown and ReST files. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | def __init__(self, parent=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | Constructor |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | @param parent reference to the parent widget (QWidget) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
46 | super(PreviewerHTML, self).__init__(parent) |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
47 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
48 | self.__layout = QVBoxLayout(self) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
49 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
50 | self.titleLabel = QLabel(self) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
51 | self.titleLabel.setWordWrap(True) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
52 | self.titleLabel.setTextInteractionFlags(Qt.NoTextInteraction) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
53 | self.__layout.addWidget(self.titleLabel) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
54 | |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
55 | self.__previewAvailable = True |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
56 | |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
57 | try: |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
58 | from PyQt5.QtWebEngineWidgets import QWebEngineView |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
59 | self.previewView = QWebEngineView(self) |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
60 | self.previewView.page().linkHovered.connect(self.__showLink) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
61 | self.__usesWebKit = False |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
62 | except ImportError: |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
63 | try: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
64 | from PyQt5.QtWebKitWidgets import QWebPage, QWebView |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
65 | self.previewView = QWebView(self) |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
66 | self.previewView.page().setLinkDelegationPolicy( |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
67 | QWebPage.DelegateAllLinks) |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
68 | self.__usesWebKit = True |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
69 | except ImportError: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
70 | self.__previewAvailable = False |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
71 | self.titleLabel.setText(self.tr( |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
72 | "<b>HTML Preview is not available!<br/>" |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
73 | "Install QtWebEngine or QtWebKit.</b>")) |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
74 | self.titleLabel.setAlignment(Qt.AlignHCenter) |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
75 | self.__layout.addStretch() |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
76 | return |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
77 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
78 | sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
79 | sizePolicy.setHorizontalStretch(0) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
80 | sizePolicy.setVerticalStretch(0) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
81 | sizePolicy.setHeightForWidth( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
82 | self.previewView.sizePolicy().hasHeightForWidth()) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
83 | self.previewView.setSizePolicy(sizePolicy) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
84 | self.previewView.setContextMenuPolicy(Qt.NoContextMenu) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
85 | self.previewView.setUrl(QUrl("about:blank")) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
86 | self.__layout.addWidget(self.previewView) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
87 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
88 | self.jsCheckBox = QCheckBox(self.tr("Enable JavaScript"), self) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
89 | self.jsCheckBox.setToolTip(self.tr( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
90 | "Select to enable JavaScript for HTML previews")) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
91 | self.__layout.addWidget(self.jsCheckBox) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
92 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
93 | self.ssiCheckBox = QCheckBox(self.tr("Enable Server Side Includes"), |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
94 | self) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
95 | self.ssiCheckBox.setToolTip(self.tr( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
96 | "Select to enable support for Server Side Includes")) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
97 | self.__layout.addWidget(self.ssiCheckBox) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
98 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
99 | self.jsCheckBox.clicked[bool].connect(self.on_jsCheckBox_clicked) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
100 | self.ssiCheckBox.clicked[bool].connect(self.on_ssiCheckBox_clicked) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
101 | self.previewView.titleChanged.connect(self.on_previewView_titleChanged) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
102 | if self.__usesWebKit: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
103 | self.previewView.linkClicked.connect( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
104 | self.on_previewView_linkClicked) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | self.jsCheckBox.setChecked( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | Preferences.getUI("ShowFilePreviewJS")) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | self.ssiCheckBox.setChecked( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | Preferences.getUI("ShowFilePreviewSSI")) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | self.__scrollBarPositions = {} |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | self.__vScrollBarAtEnd = {} |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | self.__hScrollBarAtEnd = {} |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | self.__processingThread = PreviewProcessingThread() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | self.__processingThread.htmlReady.connect(self.__setHtml) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | self.__previewedPath = None |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | self.__previewedEditor = None |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | def shutdown(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | Public method to perform shutdown actions. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | """ |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
125 | if self.__previewAvailable: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
126 | self.__processingThread.wait() |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @pyqtSlot(bool) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | def on_jsCheckBox_clicked(self, checked): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | Private slot to enable/disable JavaScript. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | @param checked state of the checkbox (boolean) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | Preferences.setUI("ShowFilePreviewJS", checked) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | self.__setJavaScriptEnabled(checked) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | def __setJavaScriptEnabled(self, enable): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | Private method to enable/disable JavaScript. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | @param enable flag indicating the enable state (boolean) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | self.jsCheckBox.setChecked(enable) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | settings = self.previewView.settings() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | settings.setAttribute(settings.JavascriptEnabled, enable) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | self.processEditor() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | @pyqtSlot(bool) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | def on_ssiCheckBox_clicked(self, checked): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | Private slot to enable/disable SSI. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | @param checked state of the checkbox (boolean) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | Preferences.setUI("ShowFilePreviewSSI", checked) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | self.processEditor() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
161 | @pyqtSlot(str) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
162 | def __showLink(self, urlStr): |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
163 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
164 | Private slot to show the hovered link in a tooltip. |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
165 | |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
166 | @param urlStr hovered URL |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
167 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
168 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
169 | QToolTip.showText(QCursor.pos(), urlStr, self.previewView) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
170 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | def processEditor(self, editor=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
173 | Public slot to process an editor's text. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | @param editor editor to be processed (Editor) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | """ |
6372
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
177 | if not self.__previewAvailable: |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
178 | return |
ae44c83fccab
CodeDocumentationViewer, PreviewerHTML: prepared the code for the non-availability of either QtWebEngine or QtWebKit (e.g. in the Win-32 PyQt5 wheels as of 5.11).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6287
diff
changeset
|
179 | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | if editor is None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | editor = self.__previewedEditor |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | self.__previewedEditor = editor |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | if editor is not None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | fn = editor.getFileName() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | if fn: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | extension = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | if extension in \ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | Preferences.getEditor("PreviewHtmlFileNameExtensions") or \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
194 | editor.getLanguage() == "HTML": |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | language = "HTML" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | elif extension in \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
197 | Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \ |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
198 | editor.getLanguage().lower() == "markdown": |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | language = "Markdown" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | elif extension in \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
201 | Preferences.getEditor("PreviewRestFileNameExtensions") or \ |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
202 | editor.getLanguage().lower() == "restructuredtext": |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | language = "ReST" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | self.__setHtml(fn, self.tr( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | "<p>No preview available for this type of file.</p>")) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | return |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | if fn: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | project = e5App().getObject("Project") |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | if project.isProjectFile(fn): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | rootPath = project.getProjectPath() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | rootPath = os.path.dirname(os.path.abspath(fn)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | rootPath = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
218 | if bool(editor.text()): |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
219 | self.__processingThread.process( |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
220 | fn, language, editor.text(), |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
221 | self.ssiCheckBox.isChecked(), rootPath, |
5837 | 222 | Preferences.getEditor("PreviewRestUseSphinx"), |
223 | Preferences.getEditor("PreviewMarkdownNLtoBR"), | |
224 | Preferences.getEditor("PreviewMarkdownHTMLFormat"), | |
225 | Preferences.getEditor("PreviewRestDocutilsHTMLFormat")) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
227 | def __setHtml(self, filePath, html, rootPath): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | Private method to set the HTML to the view and restore the scroll bars |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | positions. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
232 | @param filePath file path of the previewed editor |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
233 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
234 | @param html processed HTML text ready to be shown |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
235 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
236 | @param rootPath path of the web site root |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
237 | @type str |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | self.__previewedPath = Utilities.normcasepath( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | Utilities.fromNativeSeparators(filePath)) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
241 | self.__saveScrollBarPositions() |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
242 | if self.__usesWebKit: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
243 | self.previewView.page().mainFrame().contentsSizeChanged.connect( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
244 | self.__restoreScrollBarPositions) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
245 | else: |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
246 | self.previewView.page().loadFinished.connect( |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
247 | self.__restoreScrollBarPositions) |
5405
2129035cd437
Fixed an issue in the HTML previewer (QWebEngine variant) related to unnamed documents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5396
diff
changeset
|
248 | if not filePath: |
2129035cd437
Fixed an issue in the HTML previewer (QWebEngine variant) related to unnamed documents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5396
diff
changeset
|
249 | filePath = "/" |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
250 | if rootPath: |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
251 | baseUrl = QUrl.fromLocalFile(rootPath + "/index.html") |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
252 | else: |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
253 | baseUrl = QUrl.fromLocalFile(filePath) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
254 | self.previewView.setHtml(html, baseUrl=baseUrl) |
4929
fcab21c80811
Fixed the focus stealing issue with the QtWebEngine based HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
255 | if self.__previewedEditor: |
fcab21c80811
Fixed the focus stealing issue with the QtWebEngine based HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
256 | self.__previewedEditor.setFocus() |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | @pyqtSlot(str) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | def on_previewView_titleChanged(self, title): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | Private slot to handle a change of the title. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | @param title new title (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | if title: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | self.titleLabel.setText(self.tr("Preview - {0}").format(title)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | self.titleLabel.setText(self.tr("Preview")) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | def __saveScrollBarPositions(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | Private method to save scroll bar positions for a previewed editor. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | """ |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
274 | if self.__usesWebKit: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
275 | frame = self.previewView.page().mainFrame() |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
276 | if frame.contentsSize() == QSize(0, 0): |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
277 | return # no valid data, nothing to save |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
278 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
279 | pos = frame.scrollPosition() |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
280 | self.__scrollBarPositions[self.__previewedPath] = pos |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
281 | self.__hScrollBarAtEnd[self.__previewedPath] = \ |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
282 | frame.scrollBarMaximum(Qt.Horizontal) == pos.x() |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
283 | self.__vScrollBarAtEnd[self.__previewedPath] = \ |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
284 | frame.scrollBarMaximum(Qt.Vertical) == pos.y() |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
285 | else: |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
286 | from PyQt5.QtCore import QPoint |
5801
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
287 | try: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
288 | pos = self.previewView.scrollPosition() |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
289 | except AttributeError: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
290 | pos = self.__execJavaScript( |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
291 | "(function() {" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
292 | "var res = {" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
293 | " x: 0," |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
294 | " y: 0," |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
295 | "};" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
296 | "res.x = window.scrollX;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
297 | "res.y = window.scrollY;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
298 | "return res;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
299 | "})()" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
300 | ) |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
301 | if pos is not None: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
302 | pos = QPoint(pos["x"], pos["y"]) |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
303 | else: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
304 | pos = QPoint(0, 0) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
305 | self.__scrollBarPositions[self.__previewedPath] = pos |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
306 | self.__hScrollBarAtEnd[self.__previewedPath] = False |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
307 | self.__vScrollBarAtEnd[self.__previewedPath] = False |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | def __restoreScrollBarPositions(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | Private method to restore scroll bar positions for a previewed editor. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | """ |
4615
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
313 | if self.__usesWebKit: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
314 | try: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
315 | self.previewView.page().mainFrame().contentsSizeChanged.\ |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
316 | disconnect(self.__restoreScrollBarPositions) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
317 | except TypeError: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
318 | # not connected, simply ignore it |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
319 | pass |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
320 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
321 | if self.__previewedPath not in self.__scrollBarPositions: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
322 | return |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
323 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
324 | frame = self.previewView.page().mainFrame() |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
325 | frame.setScrollPosition( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
326 | self.__scrollBarPositions[self.__previewedPath]) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
327 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
328 | if self.__hScrollBarAtEnd[self.__previewedPath]: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
329 | frame.setScrollBarValue( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
330 | Qt.Horizontal, frame.scrollBarMaximum(Qt.Horizontal)) |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
331 | |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
332 | if self.__vScrollBarAtEnd[self.__previewedPath]: |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
333 | frame.setScrollBarValue( |
7c090c9d389d
Changed the HTML Previewer to use a QWebEngineView, if QtWebKit is not available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
334 | Qt.Vertical, frame.scrollBarMaximum(Qt.Vertical)) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
335 | else: |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
336 | if self.__previewedPath not in self.__scrollBarPositions: |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
337 | return |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
338 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
339 | pos = self.__scrollBarPositions[self.__previewedPath] |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
340 | self.previewView.page().runJavaScript( |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
341 | "window.scrollTo({0}, {1});".format(pos.x(), pos.y())) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | @pyqtSlot(QUrl) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | def on_previewView_linkClicked(self, url): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | Private slot handling the clicking of a link. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | |
6287
9a193ff6d24a
URL handling: redirected the URL handling for 'http' and 'https' URLs to the main user interface and the man web browser interface (for standalone web browsers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
348 | @param url URL of the clicked link |
9a193ff6d24a
URL handling: redirected the URL handling for 'http' and 'https' URLs to the main user interface and the man web browser interface (for standalone web browsers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
349 | @type QUrl |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | """ |
6287
9a193ff6d24a
URL handling: redirected the URL handling for 'http' and 'https' URLs to the main user interface and the man web browser interface (for standalone web browsers).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
351 | e5App().getObject("UserInterface").launchHelpViewer(url) |
4625
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
352 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
353 | def __execJavaScript(self, script): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
354 | """ |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
355 | Private function to execute a JavaScript function Synchroneously. |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
356 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
357 | @param script JavaScript script source to be executed |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
358 | @type str |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
359 | @return result of the script |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
360 | @rtype depending upon script result |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
361 | """ |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
362 | from PyQt5.QtCore import QEventLoop |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
363 | loop = QEventLoop() |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
364 | resultDict = {"res": None} |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
365 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
366 | def resultCallback(res, resDict=resultDict): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
367 | if loop and loop.isRunning(): |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
368 | resDict["res"] = res |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
369 | loop.quit() |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
370 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
371 | self.previewView.page().runJavaScript( |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
372 | script, resultCallback) |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
373 | |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
374 | loop.exec_() |
ac72a3d8f89e
Improved the QtWebEngine based HTML previewer variant by including JavaScript to save and restore the current scrollbar positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4615
diff
changeset
|
375 | return resultDict["res"] |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | class PreviewProcessingThread(QThread): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | Class implementing a thread to process some text into HTML usable by the |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | previewer view. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
383 | @signal htmlReady(str, str, str) emitted with the file name, the processed |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
384 | HTML and the web site root path to signal the availability of the |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
385 | processed HTML |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | """ |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
387 | htmlReady = pyqtSignal(str, str, str) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | def __init__(self, parent=None): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | Constructor |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | @param parent reference to the parent object (QObject) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | """ |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
395 | super(PreviewProcessingThread, self).__init__() |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | self.__lock = threading.Lock() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
399 | def process(self, filePath, language, text, ssiEnabled, rootPath, |
5837 | 400 | useSphinx, convertNewLineToBreak, markdownHtmlFormat, |
401 | restDocutilsHtmlFormat): | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
403 | Public method to convert the given text to HTML. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | @param filePath file path of the text (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | @param language language of the text (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | @param text text to be processed (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | @param ssiEnabled flag indicating to do some (limited) SSI processing |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | (boolean) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | @param rootPath root path to be used for SSI processing (str) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
411 | @param useSphinx flag indicating to use Sphinx to generate the |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
412 | ReST preview (boolean) |
5837 | 413 | @param convertNewLineToBreak flag indicating to convert new lines |
414 | to HTML break (Markdown only) (boolean) | |
415 | @param markdownHtmlFormat HTML format to be generated by markdown | |
416 | (string) | |
417 | @param restDocutilsHtmlFormat HTML format to be generated by docutils | |
418 | (string) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | self.__filePath = filePath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | self.__language = language |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | self.__text = text |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | self.__ssiEnabled = ssiEnabled |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | self.__rootPath = rootPath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | self.__haveData = True |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
427 | self.__useSphinx = useSphinx |
5837 | 428 | self.__convertNewLineToBreak = convertNewLineToBreak |
429 | self.__markdownHtmlFormat = markdownHtmlFormat | |
430 | self.__restDocutilsHtmlFormat = restDocutilsHtmlFormat | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | if not self.isRunning(): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | self.start(QThread.LowPriority) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | def run(self): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
436 | Public thread method to convert the stored data. |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | while True: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | # exits with break |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | filePath = self.__filePath |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | language = self.__language |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | text = self.__text |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | ssiEnabled = self.__ssiEnabled |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | rootPath = self.__rootPath |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
446 | useSphinx = self.__useSphinx |
5837 | 447 | convertNewLineToBreak = self.__convertNewLineToBreak |
448 | markdownHtmlFormat = self.__markdownHtmlFormat | |
449 | restDocutilsHtmlFormat = self.__restDocutilsHtmlFormat | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | |
5837 | 451 | self.__haveData = False |
452 | ||
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | html = self.__getHtml(language, text, ssiEnabled, filePath, |
5837 | 454 | rootPath, useSphinx, convertNewLineToBreak, |
455 | markdownHtmlFormat, restDocutilsHtmlFormat) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | with self.__lock: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | if not self.__haveData: |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
459 | self.htmlReady.emit(filePath, html, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | break |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | # else - next iteration |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
463 | def __getHtml(self, language, text, ssiEnabled, filePath, rootPath, |
5837 | 464 | useSphinx, convertNewLineToBreak, markdownHtmlFormat, |
465 | restDocutilsHtmlFormat): | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | Private method to process the given text depending upon the given |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | language. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | @param language language of the text (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | @param text to be processed (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | @param ssiEnabled flag indicating to do some (limited) SSI processing |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | (boolean) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | @param filePath file path of the text (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | @param rootPath root path to be used for SSI processing (str) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
476 | @param useSphinx flag indicating to use Sphinx to generate the |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
477 | ReST preview (boolean) |
5837 | 478 | @param convertNewLineToBreak flag indicating to convert new lines |
479 | to HTML break (Markdown only) (boolean) | |
480 | @param markdownHtmlFormat HTML format to be generated by markdown | |
481 | (string) | |
482 | @param restDocutilsHtmlFormat HTML format to be generated by docutils | |
483 | (string) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | @return processed HTML text (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | if language == "HTML": |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | if ssiEnabled: |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
488 | html = self.__processSSI(text, filePath, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | else: |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
490 | html = text |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
491 | return self.__processRootPath(html, rootPath) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | elif language == "Markdown": |
5837 | 493 | return self.__convertMarkdown(text, convertNewLineToBreak, |
494 | markdownHtmlFormat) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | elif language == "ReST": |
5837 | 496 | return self.__convertReST(text, useSphinx, restDocutilsHtmlFormat) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | return self.tr( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | "<p>No preview available for this type of file.</p>") |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
500 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | def __processSSI(self, txt, filename, root): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
502 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | Private method to process the given text for SSI statements. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | Note: Only a limited subset of SSI statements are supported. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | @param txt text to be processed (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | @param filename name of the file associated with the given text |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | @param root directory of the document root (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | @return processed HTML (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
512 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | if not filename: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
514 | return txt |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | # SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | incRe = re.compile( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
518 | r"""<!--#include[ \t]+(virtual|file)=[\"']([^\"']+)[\"']\s*-->""", |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
519 | re.IGNORECASE) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | baseDir = os.path.dirname(os.path.abspath(filename)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
521 | docRoot = root if root != "" else baseDir |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | while True: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
523 | incMatch = incRe.search(txt) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | if incMatch is None: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | break |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | if incMatch.group(1) == "virtual": |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | incFile = Utilities.normjoinpath(docRoot, incMatch.group(2)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | elif incMatch.group(1) == "file": |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | incFile = Utilities.normjoinpath(baseDir, incMatch.group(2)) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
531 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | incFile = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | if os.path.exists(incFile): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | try: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
535 | f = open(incFile, "r") |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | incTxt = f.read() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | f.close() |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | except (IOError, OSError): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
539 | # remove SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | incTxt = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
541 | else: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | # remove SSI include |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | incTxt = "" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | txt = txt[:incMatch.start(0)] + incTxt + txt[incMatch.end(0):] |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
545 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | return txt |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
547 | |
5846
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
548 | def __processRootPath(self, txt, root): |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
549 | """ |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
550 | Private method to adjust absolute references to the given root path. |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
551 | |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
552 | @param txt text to be processed |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
553 | @type str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
554 | @param root directory of the document root |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
555 | @type str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
556 | @return processed HTML |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
557 | @rtype str |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
558 | """ |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
559 | if not root: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
560 | return txt |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
561 | |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
562 | root = Utilities.fromNativeSeparators(root) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
563 | if not root.endswith("/"): |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
564 | root += "/" |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
565 | rootLen = len(root) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
566 | |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
567 | refRe = re.compile( |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
568 | r"""(href|src)=[\\"']/([^\\"']+)[\\"']""", |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
569 | re.IGNORECASE) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
570 | pos = 0 |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
571 | while True: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
572 | refMatch = refRe.search(txt, pos) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
573 | if refMatch is None: |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
574 | break |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
575 | |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
576 | txt = (txt[:refMatch.start(0)] + refMatch.group(1) + '="' + root + |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
577 | refMatch.group(2) + '"' + txt[refMatch.end(0):]) |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
578 | pos = refMatch.end(0) + rootLen |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
579 | |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
580 | return txt |
b3cc692e3bfe
Some additional improvements for the HTML previewer to be able to cope with absolute URLs. These get rewritten with respect to the project directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5845
diff
changeset
|
581 | |
5837 | 582 | def __convertReST(self, text, useSphinx, restDocutilsHtmlFormat): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
583 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
584 | Private method to convert ReST text into HTML. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
586 | @param text text to be processed (string) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
587 | @param useSphinx flag indicating to use Sphinx to generate the |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
588 | ReST preview (boolean) |
5837 | 589 | @param restDocutilsHtmlFormat HTML format to be generated by docutils |
590 | (string) | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
591 | @return processed HTML (string) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
592 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
593 | if useSphinx: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
594 | return self.__convertReSTSphinx(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
595 | else: |
5837 | 596 | return self.__convertReSTDocutils(text, restDocutilsHtmlFormat) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
597 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
598 | def __convertReSTSphinx(self, text): |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
599 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
600 | Private method to convert ReST text into HTML using 'sphinx'. |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
601 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
602 | @param text text to be processed (string) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
603 | @return processed HTML (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
604 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | try: |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
606 | from sphinx.application import Sphinx # __IGNORE_EXCEPTION__ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
607 | except ImportError: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
608 | return self.tr( |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
609 | """<p>ReStructuredText preview requires the""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
610 | """ <b>sphinx</b> package.<br/>Install it with""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
611 | """ your package manager,'pip install Sphinx' or see""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
612 | """ <a href="http://pypi.python.org/pypi/Sphinx">""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
613 | """this page.</a></p>""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
614 | """<p>Alternatively you may disable Sphinx usage""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
615 | """ on the Editor, Filehandling configuration page.</p>""") |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
616 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
617 | tempDir = tempfile.mkdtemp(prefix='eric-rest-') |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
618 | try: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
619 | filename = 'sphinx_preview' |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
620 | basePath = os.path.join(tempDir, filename) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
621 | fh = open(basePath + '.rst', 'w', encoding='utf-8') |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
622 | fh.write(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
623 | fh.close() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
624 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
625 | overrides = {'html_add_permalinks': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
626 | 'html_copy_source': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
627 | 'html_title': 'Sphinx preview', |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
628 | 'html_use_index': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
629 | 'html_use_modindex': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
630 | 'html_use_smartypants': True, |
3991
73731c4bf5bd
Corrected some coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3981
diff
changeset
|
631 | 'master_doc': filename} |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
632 | app = Sphinx(srcdir=tempDir, confdir=None, outdir=tempDir, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
633 | doctreedir=tempDir, buildername='html', |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
634 | confoverrides=overrides, status=None, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
635 | warning=io.StringIO()) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
636 | app.build(force_all=True, filenames=None) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
637 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
638 | fh = open(basePath + '.html', 'r', encoding='utf-8') |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
639 | html = fh.read() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
640 | fh.close() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
641 | finally: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
642 | shutil.rmtree(tempDir) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
643 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
644 | return html |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
645 | |
5837 | 646 | def __convertReSTDocutils(self, text, htmlFormat): |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
647 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
648 | Private method to convert ReST text into HTML using 'docutils'. |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
649 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
650 | @param text text to be processed (string) |
5837 | 651 | @param htmlFormat HTML format to be generated (string) |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
652 | @return processed HTML (string) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
653 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
654 | if 'sphinx' in sys.modules: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
655 | # Make sure any Sphinx polution of docutils has been removed. |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
656 | unloadKeys = [k for k in sys.modules.keys() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
657 | if k.startswith(('docutils', 'sphinx'))] |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
658 | for key in unloadKeys: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
659 | sys.modules.pop(key) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
660 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
661 | try: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
662 | import docutils.core # __IGNORE_EXCEPTION__ |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
663 | import docutils.utils # __IGNORE_EXCEPTION__ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
664 | except ImportError: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
665 | return self.tr( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
666 | """<p>ReStructuredText preview requires the""" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | """ <b>python-docutils</b> package.<br/>Install it with""" |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
668 | """ your package manager, 'pip install docutils' or see""" |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
669 | """ <a href="http://pypi.python.org/pypi/docutils">""" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
670 | """this page.</a></p>""") |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
671 | |
3981
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
672 | # redirect sys.stderr because we are not interested in it here |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
673 | origStderr = sys.stderr |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
674 | sys.stderr = io.StringIO() |
6794
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
675 | try: |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
676 | html = docutils.core.publish_string( |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
677 | text, writer_name=htmlFormat.lower()).decode("utf-8") |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
678 | except docutils.utils.SystemMessage as err: |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
679 | errStr = str(err).split(":")[-1].replace("\n", "<br/>") |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
680 | return self.tr( |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
681 | """<p>Docutils returned an error:</p><p>{0}</p>""" |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
682 | ).format(errStr) |
10c368c9c02b
PreviewerHTML: added a error handler for docutils SystemMessage exceptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
683 | |
3981
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
684 | sys.stderr = origStderr |
5cd283505cfa
A little change to the ReST previewer to discard errors generated by the docutils converter and sent to sys.stderr.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3979
diff
changeset
|
685 | return html |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
686 | |
5837 | 687 | def __convertMarkdown(self, text, convertNewLineToBreak, htmlFormat): |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
688 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
689 | Private method to convert Markdown text into HTML. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
690 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
691 | @param text text to be processed (string) |
5837 | 692 | @param convertNewLineToBreak flag indicating to convert new lines |
693 | to HTML break (Markdown only) (boolean) | |
694 | @param htmlFormat HTML format to be generated by markdown (string) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
695 | @return processed HTML (string) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
696 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
697 | try: |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
698 | import markdown # __IGNORE_EXCEPTION__ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
699 | except ImportError: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | return self.tr( |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
701 | """<p>Markdown preview requires the <b>Markdown</b> """ |
5394
b2c6179184f6
Started implementing a format button bar and provider classes for various markup languages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
702 | """package.<br/>Install it with your package manager,""" |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
703 | """ 'pip install Markdown' or see """ |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
704 | """<a href="http://pythonhosted.org/Markdown/install.html">""" |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
705 | """installation instructions.</a></p>""") |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
706 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
707 | try: |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
708 | import mdx_mathjax # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
709 | except ImportError: |
5905
f31960634997
Continued implementing a viewer for source code documentation extracted by providers to be implemented by plug-ins (like rope and jedi).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5846
diff
changeset
|
710 | # mathjax doesn't require import statement if installed |
f31960634997
Continued implementing a viewer for source code documentation extracted by providers to be implemented by plug-ins (like rope and jedi).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5846
diff
changeset
|
711 | # as extension |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
712 | pass |
5837 | 713 | |
714 | if convertNewLineToBreak: | |
715 | extensions = ['fenced_code', 'nl2br', 'extra'] | |
716 | else: | |
717 | extensions = ['fenced_code', 'extra'] | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
718 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
719 | # version 2.0 supports only extension names, not instances |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
720 | if markdown.version_info[0] > 2 or \ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
721 | (markdown.version_info[0] == 2 and |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
722 | markdown.version_info[1] > 0): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
723 | class _StrikeThroughExtension(markdown.Extension): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
724 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
725 | Class is placed here, because it depends on imported markdown, |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
726 | and markdown import is lazy. |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
727 | |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
728 | (see https://pythonhosted.org/Markdown/extensions/api.html |
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
729 | this page for details) |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
730 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
731 | DEL_RE = r'(~~)(.*?)~~' |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
732 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
733 | def extendMarkdown(self, md, md_globals): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
734 | # Create the del pattern |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
735 | del_tag = markdown.inlinepatterns.SimpleTagPattern( |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
736 | self.DEL_RE, 'del') |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
737 | # Insert del pattern into markdown parser |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
738 | md.inlinePatterns.add('del', del_tag, '>not_strong') |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
739 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
740 | extensions.append(_StrikeThroughExtension()) |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
741 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
742 | try: |
5837 | 743 | return markdown.markdown(text, extensions=extensions + ['mathjax'], |
744 | output_format=htmlFormat.lower()) | |
3458
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
745 | except (ImportError, ValueError): |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
746 | # markdown raises ValueError or ImportError, depends on version |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
747 | # It is not clear, how to distinguish missing mathjax from other |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
748 | # errors. So keep going without mathjax. |
5837 | 749 | return markdown.markdown(text, extensions=extensions, |
750 | output_format=htmlFormat.lower()) |