15 import sys |
15 import sys |
16 import io |
16 import io |
17 import contextlib |
17 import contextlib |
18 |
18 |
19 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QThread |
19 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QThread |
20 from PyQt6.QtGui import QCursor |
20 from PyQt6.QtGui import QCursor, QGuiApplication |
21 from PyQt6.QtWidgets import ( |
21 from PyQt6.QtWidgets import ( |
22 QWidget, |
22 QWidget, |
23 QVBoxLayout, |
23 QVBoxLayout, |
24 QLabel, |
24 QLabel, |
25 QCheckBox, |
25 QCheckBox, |
26 QSizePolicy, |
26 QSizePolicy, |
27 QToolTip, |
27 QToolTip, |
|
28 QGridLayout, |
|
29 QPushButton, |
28 ) |
30 ) |
29 |
31 |
30 from eric7.EricWidgets.EricApplication import ericApp |
32 from eric7.EricWidgets.EricApplication import ericApp |
31 |
33 |
32 from eric7 import Preferences, Utilities |
34 from eric7 import Preferences, Utilities |
82 self.previewView.setSizePolicy(sizePolicy) |
84 self.previewView.setSizePolicy(sizePolicy) |
83 self.previewView.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu) |
85 self.previewView.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu) |
84 self.previewView.setUrl(QUrl("about:blank")) |
86 self.previewView.setUrl(QUrl("about:blank")) |
85 self.__layout.addWidget(self.previewView) |
87 self.__layout.addWidget(self.previewView) |
86 |
88 |
|
89 self.__footerLayout = QGridLayout() |
|
90 sizePolicy = QSizePolicy( |
|
91 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred |
|
92 ) |
87 self.jsCheckBox = QCheckBox(self.tr("Enable JavaScript"), self) |
93 self.jsCheckBox = QCheckBox(self.tr("Enable JavaScript"), self) |
88 self.jsCheckBox.setToolTip( |
94 self.jsCheckBox.setToolTip( |
89 self.tr("Select to enable JavaScript for HTML previews") |
95 self.tr("Select to enable JavaScript for HTML previews") |
90 ) |
96 ) |
91 self.__layout.addWidget(self.jsCheckBox) |
97 self.jsCheckBox.setSizePolicy(sizePolicy) |
|
98 self.__footerLayout.addWidget(self.jsCheckBox, 0, 0) |
92 |
99 |
93 self.ssiCheckBox = QCheckBox(self.tr("Enable Server Side Includes"), self) |
100 self.ssiCheckBox = QCheckBox(self.tr("Enable Server Side Includes"), self) |
94 self.ssiCheckBox.setToolTip( |
101 self.ssiCheckBox.setToolTip( |
95 self.tr("Select to enable support for Server Side Includes") |
102 self.tr("Select to enable support for Server Side Includes") |
96 ) |
103 ) |
97 self.__layout.addWidget(self.ssiCheckBox) |
104 self.ssiCheckBox.setSizePolicy(sizePolicy) |
|
105 self.__footerLayout.addWidget(self.ssiCheckBox, 1, 0) |
|
106 self.__htmlButton = QPushButton(self.tr("Copy HTML"), self) |
|
107 self.__htmlButton.setToolTip( |
|
108 self.tr("Press to copy the HTML text of the preview to the clipboard") |
|
109 ) |
|
110 self.__htmlButton.setEnabled(False) |
|
111 self.__footerLayout.addWidget(self.__htmlButton, 1, 1) |
|
112 self.__layout.addLayout(self.__footerLayout) |
98 |
113 |
99 self.jsCheckBox.clicked[bool].connect(self.on_jsCheckBox_clicked) |
114 self.jsCheckBox.clicked[bool].connect(self.on_jsCheckBox_clicked) |
100 self.ssiCheckBox.clicked[bool].connect(self.on_ssiCheckBox_clicked) |
115 self.ssiCheckBox.clicked[bool].connect(self.on_ssiCheckBox_clicked) |
101 self.previewView.titleChanged.connect(self.on_previewView_titleChanged) |
116 self.previewView.titleChanged.connect(self.on_previewView_titleChanged) |
|
117 self.__htmlButton.clicked.connect(self.on_htmlButton_clicked) |
102 |
118 |
103 self.jsCheckBox.setChecked(Preferences.getUI("ShowFilePreviewJS")) |
119 self.jsCheckBox.setChecked(Preferences.getUI("ShowFilePreviewJS")) |
104 self.ssiCheckBox.setChecked(Preferences.getUI("ShowFilePreviewSSI")) |
120 self.ssiCheckBox.setChecked(Preferences.getUI("ShowFilePreviewSSI")) |
105 |
121 |
106 self.__scrollBarPositions = {} |
122 self.__scrollBarPositions = {} |
246 baseUrl = ( |
263 baseUrl = ( |
247 QUrl.fromLocalFile(rootPath + "/index.html") |
264 QUrl.fromLocalFile(rootPath + "/index.html") |
248 if rootPath |
265 if rootPath |
249 else QUrl.fromLocalFile(filePath) |
266 else QUrl.fromLocalFile(filePath) |
250 ) |
267 ) |
|
268 self.__previewedHtml = html |
|
269 self.__htmlButton.setEnabled(bool(html)) |
251 self.previewView.setHtml(html, baseUrl=baseUrl) |
270 self.previewView.setHtml(html, baseUrl=baseUrl) |
252 if self.__previewedEditor: |
271 if self.__previewedEditor: |
253 self.__previewedEditor.setFocus() |
272 self.__previewedEditor.setFocus() |
254 |
273 |
255 @pyqtSlot(str) |
274 @pyqtSlot(str) |
322 |
341 |
323 self.previewView.page().runJavaScript(script, resultCallback) |
342 self.previewView.page().runJavaScript(script, resultCallback) |
324 |
343 |
325 loop.exec() |
344 loop.exec() |
326 return resultDict["res"] |
345 return resultDict["res"] |
|
346 |
|
347 @pyqtSlot() |
|
348 def on_htmlButton_clicked(self): |
|
349 """ |
|
350 Private slot to copy the HTML contents to the clipboard. |
|
351 """ |
|
352 if self.__previewedHtml: |
|
353 QGuiApplication.clipboard().setText(self.__previewedHtml) |
327 |
354 |
328 |
355 |
329 class PreviewProcessingThread(QThread): |
356 class PreviewProcessingThread(QThread): |
330 """ |
357 """ |
331 Class implementing a thread to process some text into HTML usable by the |
358 Class implementing a thread to process some text into HTML usable by the |