12 try: |
12 try: |
13 str = unicode # __IGNORE_EXCEPTION__ |
13 str = unicode # __IGNORE_EXCEPTION__ |
14 except NameError: |
14 except NameError: |
15 pass |
15 pass |
16 |
16 |
|
17 import os |
|
18 |
17 from PyQt5.QtCore import pyqtSignal, QUrl, QFileInfo, Qt, QTimer, QEvent, \ |
19 from PyQt5.QtCore import pyqtSignal, QUrl, QFileInfo, Qt, QTimer, QEvent, \ |
18 QPoint, QDateTime |
20 QPoint, QDateTime, qVersion |
19 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ |
21 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ |
20 QContextMenuEvent, QPixmap |
22 QContextMenuEvent, QPixmap |
21 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication |
23 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication |
22 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage |
24 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage |
23 |
25 |
32 from . import WebInspector |
34 from . import WebInspector |
33 from .Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl |
35 from .Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl |
34 |
36 |
35 import Preferences |
37 import Preferences |
36 import UI.PixmapCache |
38 import UI.PixmapCache |
|
39 import Utilities |
37 |
40 |
38 |
41 |
39 class WebBrowserView(QWebEngineView): |
42 class WebBrowserView(QWebEngineView): |
40 """ |
43 """ |
41 Class implementing the web browser view widget. |
44 Class implementing the web browser view widget. |
162 if newTab: |
165 if newTab: |
163 # open in a new tab |
166 # open in a new tab |
164 self.__mw.newTab(name) |
167 self.__mw.newTab(name) |
165 return |
168 return |
166 |
169 |
167 if not name.scheme(): |
170 if not name.scheme() and not os.path.exists(name.toString()): |
168 name.setUrl(Preferences.getWebBrowser("DefaultScheme") + |
171 name.setScheme(Preferences.getWebBrowser("DefaultScheme")) |
169 name.toString()) |
172 else: |
|
173 if Utilities.isWindowsPlatform(): |
|
174 name.setUrl("file:///" + Utilities.fromNativeSeparators( |
|
175 name.toString())) |
|
176 else: |
|
177 name.setUrl("file://" + name.toString()) |
170 |
178 |
171 if len(name.scheme()) == 1 or \ |
179 if len(name.scheme()) == 1 or \ |
172 name.scheme() == "file": |
180 name.scheme() == "file": |
173 # name is a local file |
181 # name is a local file |
174 if name.scheme() and len(name.scheme()) == 1: |
182 if name.scheme() and len(name.scheme()) == 1: |
182 self.tr( |
190 self.tr( |
183 """<p>The file <b>{0}</b> does not exist.</p>""") |
191 """<p>The file <b>{0}</b> does not exist.</p>""") |
184 .format(name.toLocalFile())) |
192 .format(name.toLocalFile())) |
185 return |
193 return |
186 |
194 |
187 if name.toLocalFile().endswith(".pdf") or \ |
195 if name.toLocalFile().lower().endswith((".pdf", ".chm")): |
188 name.toLocalFile().endswith(".PDF") or \ |
|
189 name.toLocalFile().endswith(".chm") or \ |
|
190 name.toLocalFile().endswith(".CHM"): |
|
191 started = QDesktopServices.openUrl(name) |
196 started = QDesktopServices.openUrl(name) |
192 if not started: |
197 if not started: |
193 E5MessageBox.critical( |
198 E5MessageBox.critical( |
194 self, |
199 self, |
195 self.tr("eric6 Web Browser"), |
200 self.tr("eric6 Web Browser"), |
208 """<p>Could not start an application""" |
213 """<p>Could not start an application""" |
209 """ for URL <b>{0}</b>.</p>""") |
214 """ for URL <b>{0}</b>.</p>""") |
210 .format(name.toString())) |
215 .format(name.toString())) |
211 return |
216 return |
212 else: |
217 else: |
213 if name.toString().endswith(".pdf") or \ |
218 if name.toString().lower().endswith((".pdf", ".chm")): |
214 name.toString().endswith(".PDF") or \ |
|
215 name.toString().endswith(".chm") or \ |
|
216 name.toString().endswith(".CHM"): |
|
217 started = QDesktopServices.openUrl(name) |
219 started = QDesktopServices.openUrl(name) |
218 if not started: |
220 if not started: |
219 E5MessageBox.critical( |
221 E5MessageBox.critical( |
220 self, |
222 self, |
221 self.tr("eric6 Web Browser"), |
223 self.tr("eric6 Web Browser"), |
315 |
317 |
316 def unselect(self): |
318 def unselect(self): |
317 """ |
319 """ |
318 Public slot to clear the current selection. |
320 Public slot to clear the current selection. |
319 """ |
321 """ |
320 self.triggerPageAction(QWebEnginePage.Unselect) |
322 if qVersion() >= "5.7.0": |
|
323 self.triggerPageAction(QWebEnginePage.Unselect) |
|
324 else: |
|
325 self.page().runJavaScript( |
|
326 "window.getSelection().empty()", |
|
327 WebBrowserPage.SafeJsWorld) |
321 |
328 |
322 def isForwardAvailable(self): |
329 def isForwardAvailable(self): |
323 """ |
330 """ |
324 Public method to determine, if a forward move in history is possible. |
331 Public method to determine, if a forward move in history is possible. |
325 |
332 |