Thu, 10 Jan 2019 14:18:48 +0100
Updated copyright for 2019.
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__ |
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
|
14 | except (ImportError, NameError): |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
15 | import io # __IGNORE_WARNING__ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
16 | |
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
|
17 | 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
|
18 | 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
|
19 | import re |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
20 | import shutil |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
21 | import tempfile |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
22 | 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
|
23 | |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
24 | 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
|
25 | 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
|
26 | 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
|
27 | 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
|
28 | |
64bbac483843
Refactored the previewer 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 | 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
|
30 | |
64bbac483843
Refactored the previewer 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 | 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
|
32 | 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
|
33 | |
64bbac483843
Refactored the previewer 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 | |
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
|
35 | 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
|
36 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
38 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
40 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
42 | |
64bbac483843
Refactored the previewer 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 | @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
|
44 | """ |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
45 | 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
|
46 | |
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 | 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
|
48 | |
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 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | |
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
|
54 | 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
|
55 | |
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
|
56 | 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
|
57 | 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
|
58 | self.previewView = QWebEngineView(self) |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
59 | 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
|
60 | 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
|
61 | 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
|
62 | 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
|
63 | 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
|
64 | 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
|
65 | 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
|
66 | 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
|
67 | 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
|
68 | 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
|
69 | 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
|
70 | 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
|
71 | "<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
|
72 | "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
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | |
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 | 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
|
78 | 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
|
79 | 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
|
80 | 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
|
81 | 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
|
82 | 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
|
83 | 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
|
84 | 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
|
85 | 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
|
86 | |
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 | 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
|
88 | 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
|
89 | "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
|
90 | 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
|
91 | |
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 | 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
|
93 | 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
|
94 | 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
|
95 | "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
|
96 | 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
|
97 | |
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 | 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
|
99 | 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
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | |
64bbac483843
Refactored the previewer 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 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | |
64bbac483843
Refactored the previewer 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 | 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
|
111 | 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
|
112 | 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
|
113 | |
64bbac483843
Refactored the previewer 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 | 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
|
115 | 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
|
116 | |
64bbac483843
Refactored the previewer 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 | 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
|
118 | 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
|
119 | |
64bbac483843
Refactored the previewer 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 | 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
|
121 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
123 | """ |
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
|
124 | 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
|
125 | 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
|
126 | |
64bbac483843
Refactored the previewer 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 | @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
|
128 | 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
|
129 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
131 | |
64bbac483843
Refactored the previewer 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 | @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
|
133 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
135 | 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
|
136 | |
64bbac483843
Refactored the previewer 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 | 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
|
138 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
140 | |
64bbac483843
Refactored the previewer 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 | @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
|
142 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
144 | |
64bbac483843
Refactored the previewer 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 | 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
|
146 | 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
|
147 | |
64bbac483843
Refactored the previewer 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 | 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
|
149 | |
64bbac483843
Refactored the previewer 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 | @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
|
151 | 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
|
152 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
154 | |
64bbac483843
Refactored the previewer 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 | @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
|
156 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
158 | 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
|
159 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
160 | @pyqtSlot(str) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
161 | def __showLink(self, urlStr): |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
162 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
163 | 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
|
164 | |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
165 | @param urlStr hovered URL |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
166 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
167 | """ |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
168 | 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
|
169 | |
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
|
170 | 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
|
171 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
172 | 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
|
173 | |
64bbac483843
Refactored the previewer 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 | @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
|
175 | """ |
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
|
176 | 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
|
177 | 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
|
178 | |
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
|
179 | 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
|
180 | 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
|
181 | 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
|
182 | 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
|
183 | |
64bbac483843
Refactored the previewer 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 | 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
|
185 | 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
|
186 | |
64bbac483843
Refactored the previewer 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 | 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
|
188 | 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
|
189 | 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
|
190 | 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
|
191 | 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
|
192 | Preferences.getEditor("PreviewHtmlFileNameExtensions") or \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
193 | 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
|
194 | 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
|
195 | elif extension in \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
196 | Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \ |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
197 | 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
|
198 | 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
|
199 | elif extension in \ |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
200 | Preferences.getEditor("PreviewRestFileNameExtensions") or \ |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
201 | 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
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | "<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
|
206 | 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
|
207 | |
64bbac483843
Refactored the previewer 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 | 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
|
209 | 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
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | 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
|
215 | 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
|
216 | |
5396
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
217 | if bool(editor.text()): |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
218 | self.__processingThread.process( |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
219 | fn, language, editor.text(), |
8d8940307e44
Little enhancement to the previewers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5394
diff
changeset
|
220 | self.ssiCheckBox.isChecked(), rootPath, |
5837 | 221 | Preferences.getEditor("PreviewRestUseSphinx"), |
222 | Preferences.getEditor("PreviewMarkdownNLtoBR"), | |
223 | Preferences.getEditor("PreviewMarkdownHTMLFormat"), | |
224 | 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
|
225 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
226 | 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
|
227 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
229 | 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
|
230 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
231 | @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
|
232 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
233 | @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
|
234 | @type str |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
235 | @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
|
236 | @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
|
237 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
239 | 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
|
240 | 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
|
241 | 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
|
242 | 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
|
243 | 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
|
244 | 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
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | filePath = "/" |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
249 | if rootPath: |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
250 | baseUrl = QUrl.fromLocalFile(rootPath + "/index.html") |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
251 | else: |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
252 | baseUrl = QUrl.fromLocalFile(filePath) |
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
253 | 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
|
254 | 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
|
255 | 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
|
256 | |
64bbac483843
Refactored the previewer 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 | @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
|
258 | 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
|
259 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
261 | |
64bbac483843
Refactored the previewer 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 | @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
|
263 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
265 | 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
|
266 | 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
|
267 | 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
|
268 | |
64bbac483843
Refactored the previewer 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 | 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
|
270 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
272 | """ |
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
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | 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
|
277 | |
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 | 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
|
279 | 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
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | 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
|
284 | 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
|
285 | 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
|
286 | try: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
287 | pos = self.previewView.scrollPosition() |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
288 | except AttributeError: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
289 | pos = self.__execJavaScript( |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
290 | "(function() {" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
291 | "var res = {" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
292 | " x: 0," |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
293 | " y: 0," |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
294 | "};" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
295 | "res.x = window.scrollX;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
296 | "res.y = window.scrollY;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
297 | "return res;" |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
298 | "})()" |
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 | 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
|
301 | 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
|
302 | else: |
d3548bec88d1
Adjustment of the HTML previewer to newer QWebEngine releases.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5774
diff
changeset
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | 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
|
307 | |
64bbac483843
Refactored the previewer 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 | 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
|
309 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
311 | """ |
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
|
312 | 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
|
313 | 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
|
314 | 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
|
315 | 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
|
316 | 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
|
317 | # 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
|
318 | 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
|
319 | |
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 | 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
|
321 | 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
|
322 | |
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 | 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
|
324 | 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
|
325 | 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
|
326 | |
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 | 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
|
328 | 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
|
329 | 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
|
330 | |
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 | 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
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | 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
|
336 | 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
|
337 | |
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 | 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
|
339 | 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
|
340 | "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
|
341 | |
64bbac483843
Refactored the previewer 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 | @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
|
343 | 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
|
344 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
346 | |
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
|
347 | @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
|
348 | @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
|
349 | """ |
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
|
350 | 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
|
351 | |
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 | 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
|
353 | """ |
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 | 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
|
355 | |
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 | @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
|
357 | @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
|
358 | @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
|
359 | @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
|
360 | """ |
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 | 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
|
362 | 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
|
363 | 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
|
364 | |
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 | 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
|
366 | 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
|
367 | 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
|
368 | 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
|
369 | |
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 | 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
|
371 | 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
|
372 | |
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 | 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
|
374 | 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
|
375 | |
64bbac483843
Refactored the previewer 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 | 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
|
378 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
380 | 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
|
381 | |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
382 | @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
|
383 | 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
|
384 | 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
|
385 | """ |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
386 | 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
|
387 | |
64bbac483843
Refactored the previewer 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 | 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
|
389 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
391 | |
64bbac483843
Refactored the previewer 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 | @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
|
393 | """ |
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3459
diff
changeset
|
394 | 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
|
395 | |
64bbac483843
Refactored the previewer 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 | 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
|
397 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
398 | def process(self, filePath, language, text, ssiEnabled, rootPath, |
5837 | 399 | useSphinx, convertNewLineToBreak, markdownHtmlFormat, |
400 | 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
|
401 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
402 | 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
|
403 | |
64bbac483843
Refactored the previewer 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 | @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
|
405 | @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
|
406 | @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
|
407 | @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
|
408 | (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
|
409 | @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
|
410 | @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
|
411 | ReST preview (boolean) |
5837 | 412 | @param convertNewLineToBreak flag indicating to convert new lines |
413 | to HTML break (Markdown only) (boolean) | |
414 | @param markdownHtmlFormat HTML format to be generated by markdown | |
415 | (string) | |
416 | @param restDocutilsHtmlFormat HTML format to be generated by docutils | |
417 | (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
|
418 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
420 | 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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | 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
|
425 | self.__haveData = True |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
426 | self.__useSphinx = useSphinx |
5837 | 427 | self.__convertNewLineToBreak = convertNewLineToBreak |
428 | self.__markdownHtmlFormat = markdownHtmlFormat | |
429 | 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
|
430 | 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
|
431 | 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
|
432 | |
64bbac483843
Refactored the previewer 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 | 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
|
434 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3539
diff
changeset
|
435 | 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
|
436 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
438 | # 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
|
439 | 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
|
440 | 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
|
441 | 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
|
442 | 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
|
443 | 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
|
444 | rootPath = self.__rootPath |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
445 | useSphinx = self.__useSphinx |
5837 | 446 | convertNewLineToBreak = self.__convertNewLineToBreak |
447 | markdownHtmlFormat = self.__markdownHtmlFormat | |
448 | 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
|
449 | |
5837 | 450 | self.__haveData = False |
451 | ||
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
|
452 | html = self.__getHtml(language, text, ssiEnabled, filePath, |
5837 | 453 | rootPath, useSphinx, convertNewLineToBreak, |
454 | 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
|
455 | |
64bbac483843
Refactored the previewer 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 | 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
|
457 | if not self.__haveData: |
5845
f3d2172d663e
Some slight improvements for the HTML previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5837
diff
changeset
|
458 | 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
|
459 | 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
|
460 | # 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
|
461 | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
462 | def __getHtml(self, language, text, ssiEnabled, filePath, rootPath, |
5837 | 463 | useSphinx, convertNewLineToBreak, markdownHtmlFormat, |
464 | 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
|
465 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
467 | 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
|
468 | |
64bbac483843
Refactored the previewer 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 | @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
|
470 | @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
|
471 | @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
|
472 | (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
|
473 | @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
|
474 | @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
|
475 | @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
|
476 | ReST preview (boolean) |
5837 | 477 | @param convertNewLineToBreak flag indicating to convert new lines |
478 | to HTML break (Markdown only) (boolean) | |
479 | @param markdownHtmlFormat HTML format to be generated by markdown | |
480 | (string) | |
481 | @param restDocutilsHtmlFormat HTML format to be generated by docutils | |
482 | (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
|
483 | @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
|
484 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
486 | 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
|
487 | 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
|
488 | 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
|
489 | 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
|
490 | 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
|
491 | elif language == "Markdown": |
5837 | 492 | return self.__convertMarkdown(text, convertNewLineToBreak, |
493 | 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
|
494 | elif language == "ReST": |
5837 | 495 | 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
|
496 | 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
|
497 | 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
|
498 | "<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
|
499 | |
64bbac483843
Refactored the previewer 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 | 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
|
501 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
503 | |
64bbac483843
Refactored the previewer 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 | 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
|
505 | |
64bbac483843
Refactored the previewer 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 | @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
|
507 | @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
|
508 | (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
|
509 | @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
|
510 | @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
|
511 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
513 | 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
|
514 | |
64bbac483843
Refactored the previewer 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 | # 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
|
516 | 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
|
517 | 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
|
518 | 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
|
519 | 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
|
520 | 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
|
521 | 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
|
522 | 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
|
523 | 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
|
524 | 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
|
525 | |
64bbac483843
Refactored the previewer 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 | 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
|
527 | 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
|
528 | 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
|
529 | 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
|
530 | 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
|
531 | 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
|
532 | 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
|
533 | 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
|
534 | 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
|
535 | 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
|
536 | 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
|
537 | 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
|
538 | # 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
|
539 | 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
|
540 | 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
|
541 | # 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
|
542 | 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
|
543 | 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
|
544 | |
64bbac483843
Refactored the previewer 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 | 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
|
546 | |
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
|
547 | 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
|
548 | """ |
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 | 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
|
550 | |
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 | @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
|
552 | @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
|
553 | @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
|
554 | @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
|
555 | @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
|
556 | @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
|
557 | """ |
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 | 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
|
559 | 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
|
560 | |
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 | 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
|
562 | 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
|
563 | 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
|
564 | 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
|
565 | |
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 | 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
|
567 | 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
|
568 | 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
|
569 | 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
|
570 | 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
|
571 | 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
|
572 | 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
|
573 | 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
|
574 | |
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 | 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
|
576 | 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
|
577 | 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
|
578 | |
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 | 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
|
580 | |
5837 | 581 | 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
|
582 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
584 | |
64bbac483843
Refactored the previewer 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 | @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
|
586 | @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
|
587 | ReST preview (boolean) |
5837 | 588 | @param restDocutilsHtmlFormat HTML format to be generated by docutils |
589 | (string) | |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
590 | @return processed HTML (string) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
591 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
592 | if useSphinx: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
593 | return self.__convertReSTSphinx(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
594 | else: |
5837 | 595 | 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
|
596 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
597 | def __convertReSTSphinx(self, text): |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
598 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
599 | 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
|
600 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
601 | @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
|
602 | @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
|
603 | """ |
64bbac483843
Refactored the previewer 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 | try: |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
605 | 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
|
606 | except ImportError: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
607 | return self.tr( |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
608 | """<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
|
609 | """ <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
|
610 | """ 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
|
611 | """ <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
|
612 | """this page.</a></p>""" |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
613 | """<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
|
614 | """ 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
|
615 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
616 | 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
|
617 | try: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
618 | filename = 'sphinx_preview' |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
619 | 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
|
620 | 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
|
621 | fh.write(text) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
622 | fh.close() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
623 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
624 | 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
|
625 | 'html_copy_source': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
626 | 'html_title': 'Sphinx preview', |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
627 | 'html_use_index': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
628 | 'html_use_modindex': False, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
629 | 'html_use_smartypants': True, |
3991
73731c4bf5bd
Corrected some coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3981
diff
changeset
|
630 | 'master_doc': filename} |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
631 | 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
|
632 | doctreedir=tempDir, buildername='html', |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
633 | confoverrides=overrides, status=None, |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
634 | warning=io.StringIO()) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
635 | 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
|
636 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
637 | 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
|
638 | html = fh.read() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
639 | fh.close() |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
640 | finally: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
641 | shutil.rmtree(tempDir) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
642 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
643 | return html |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
644 | |
5837 | 645 | 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
|
646 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
647 | 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
|
648 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
649 | @param text text to be processed (string) |
5837 | 650 | @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
|
651 | @return processed HTML (string) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
652 | """ |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
653 | 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
|
654 | # 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
|
655 | 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
|
656 | 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
|
657 | for key in unloadKeys: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
658 | sys.modules.pop(key) |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
659 | |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
660 | try: |
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
661 | import docutils.core # __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
|
662 | 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
|
663 | 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
|
664 | """<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
|
665 | """ <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
|
666 | """ 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
|
667 | """ <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
|
668 | """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
|
669 | |
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
|
670 | # 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
|
671 | 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
|
672 | sys.stderr = io.StringIO() |
5837 | 673 | html = docutils.core.publish_string( |
674 | text, writer_name=htmlFormat.lower()).decode("utf-8") | |
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
|
675 | 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
|
676 | 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
|
677 | |
5837 | 678 | 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
|
679 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
680 | 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
|
681 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
682 | @param text text to be processed (string) |
5837 | 683 | @param convertNewLineToBreak flag indicating to convert new lines |
684 | to HTML break (Markdown only) (boolean) | |
685 | @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
|
686 | @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
|
687 | """ |
64bbac483843
Refactored the previewer 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 | try: |
3979
307b09aae43b
Added capability to use 'Sphinx' to preview ReST files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
689 | 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
|
690 | 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
|
691 | return self.tr( |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
692 | """<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
|
693 | """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
|
694 | """ '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
|
695 | """<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
|
696 | """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
|
697 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
698 | 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
|
699 | 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
|
700 | 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
|
701 | # 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
|
702 | # 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
|
703 | pass |
5837 | 704 | |
705 | if convertNewLineToBreak: | |
706 | extensions = ['fenced_code', 'nl2br', 'extra'] | |
707 | else: | |
708 | 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
|
709 | |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
710 | # 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
|
711 | 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
|
712 | (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
|
713 | 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
|
714 | 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
|
715 | """ |
64bbac483843
Refactored the previewer code to allow to add more previewers and started adding support for a QSS previewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
716 | 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
|
717 | 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
|
718 | |
5912
b6643d36dddd
Added the rich text view to the documentation viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5905
diff
changeset
|
719 | (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
|
720 | 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
|
721 | """ |
64bbac483843
Refactored the previewer 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 | 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
|
723 | |
64bbac483843
Refactored the previewer 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 | 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
|
725 | # 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
|
726 | 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
|
727 | 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
|
728 | # 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
|
729 | 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
|
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 | 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
|
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 | try: |
5837 | 734 | return markdown.markdown(text, extensions=extensions + ['mathjax'], |
735 | 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
|
736 | 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
|
737 | # 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
|
738 | # 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
|
739 | # errors. So keep going without mathjax. |
5837 | 740 | return markdown.markdown(text, extensions=extensions, |
741 | output_format=htmlFormat.lower()) |