8 Module implementing the web browser using QWebEngineView. |
8 Module implementing the web browser using QWebEngineView. |
9 """ |
9 """ |
10 |
10 |
11 import os |
11 import os |
12 import functools |
12 import functools |
|
13 import contextlib |
13 |
14 |
14 from PyQt5.QtCore import ( |
15 from PyQt5.QtCore import ( |
15 pyqtSignal, pyqtSlot, Qt, QUrl, QFileInfo, QTimer, QEvent, QPoint, |
16 pyqtSignal, pyqtSlot, Qt, QUrl, QFileInfo, QTimer, QEvent, QPoint, |
16 QPointF, QDateTime, QStandardPaths, QByteArray, QIODevice, QDataStream |
17 QPointF, QDateTime, QStandardPaths, QByteArray, QIODevice, QDataStream |
17 ) |
18 ) |
147 self.setPage(self.__page) |
148 self.setPage(self.__page) |
148 |
149 |
149 self.__page.safeBrowsingAbort.connect(self.safeBrowsingAbort) |
150 self.__page.safeBrowsingAbort.connect(self.safeBrowsingAbort) |
150 self.__page.safeBrowsingBad.connect(self.safeBrowsingBad) |
151 self.__page.safeBrowsingBad.connect(self.safeBrowsingBad) |
151 self.__page.printPageRequested.connect(self.__printPage) |
152 self.__page.printPageRequested.connect(self.__printPage) |
152 try: |
153 self.__page.quotaRequested.connect(self.__quotaRequested) |
153 self.__page.quotaRequested.connect(self.__quotaRequested) |
154 # The registerProtocolHandlerRequested signal is handled in |
154 # The registerProtocolHandlerRequested signal is handled in |
155 # WebBrowserPage. |
155 # WebBrowserPage. |
156 self.__page.selectClientCertificate.connect( |
156 except AttributeError: |
157 self.__selectClientCertificate) |
157 # pre Qt 5.11 |
158 with contextlib.suppress(AttributeError, ImportError): |
158 pass |
159 #- Qt >= 5.14 |
159 try: |
|
160 self.__page.selectClientCertificate.connect( |
|
161 self.__selectClientCertificate) |
|
162 except AttributeError: |
|
163 # pre Qt 5.12 |
|
164 pass |
|
165 try: |
|
166 from PyQt5.QtWebEngineCore import QWebEngineFindTextResult |
160 from PyQt5.QtWebEngineCore import QWebEngineFindTextResult |
167 # __IGNORE_WARNING__ |
161 # __IGNORE_WARNING__ |
168 |
162 |
169 self.__page.findTextFinished.connect( |
163 self.__page.findTextFinished.connect( |
170 self.__findTextFinished) |
164 self.__findTextFinished) |
171 except (AttributeError, ImportError): |
|
172 # pre Qt 5.14 |
|
173 pass |
|
174 |
165 |
175 def __setRwhvqt(self): |
166 def __setRwhvqt(self): |
176 """ |
167 """ |
177 Private slot to set widget that receives input events. |
168 Private slot to set widget that receives input events. |
178 """ |
169 """ |
1678 self.__siteIcon = QIcon() |
1669 self.__siteIcon = QIcon() |
1679 if self.__siteIconLoader is not None: |
1670 if self.__siteIconLoader is not None: |
1680 self.__siteIconLoader.deleteLater() |
1671 self.__siteIconLoader.deleteLater() |
1681 self.__siteIconLoader = WebIconLoader(url, self) |
1672 self.__siteIconLoader = WebIconLoader(url, self) |
1682 self.__siteIconLoader.iconLoaded.connect(self.__iconLoaded) |
1673 self.__siteIconLoader.iconLoaded.connect(self.__iconLoaded) |
1683 try: |
1674 with contextlib.suppress(AttributeError): |
1684 self.__siteIconLoader.sslConfiguration.connect( |
1675 self.__siteIconLoader.sslConfiguration.connect( |
1685 self.page().setSslConfiguration) |
1676 self.page().setSslConfiguration) |
1686 self.__siteIconLoader.clearSslConfiguration.connect( |
1677 self.__siteIconLoader.clearSslConfiguration.connect( |
1687 self.page().clearSslConfiguration) |
1678 self.page().clearSslConfiguration) |
1688 except AttributeError: |
|
1689 # no SSL available |
|
1690 pass |
|
1691 |
1679 |
1692 def __iconLoaded(self, icon): |
1680 def __iconLoaded(self, icon): |
1693 """ |
1681 """ |
1694 Private slot handling the loaded web site icon. |
1682 Private slot handling the loaded web site icon. |
1695 |
1683 |