eric6/WebBrowser/Tools/WebIconLoader.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8218
7c09585bd960
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an object to load web site icons.
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt5.QtGui import QIcon, QPixmap, QImage
7764
1804cdcedac7 WebBrowser: started to implement retrieval of SSL data as a by-product of loading a site icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
12 from PyQt5.QtNetwork import QNetworkRequest, QSslConfiguration
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
14 try:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
15 from PyQt5.QtNetwork import QSslConfiguration # __IGNORE_WARNING__
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
16 SSL_AVAILABLE = True
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
17 except ImportError:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
18 SSL_AVAILABLE = False
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
19
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import WebBrowser.WebBrowserWindow
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class WebIconLoader(QObject):
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing a loader for web site icons.
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
27 @signal iconLoaded(icon) emitted when the icon has been loaded
7764
1804cdcedac7 WebBrowser: started to implement retrieval of SSL data as a by-product of loading a site icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
28 @signal sslConfiguration(config) emitted to pass the SSL data
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
29 @signal clearSslConfiguration() emitted to clear stored SSL data
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 iconLoaded = pyqtSignal(QIcon)
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
32 if SSL_AVAILABLE:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
33 sslConfiguration = pyqtSignal(QSslConfiguration)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
34 clearSslConfiguration = pyqtSignal()
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def __init__(self, url, parent=None):
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Constructor
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @param url URL to fetch the icon from
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @type QUrl
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @param parent reference to the parent object
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @type QObject
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 super(WebIconLoader, self).__init__(parent)
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
47 networkManager = (
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager()
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
49 )
4902
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
50 self.__reply = networkManager.get(QNetworkRequest(url))
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.__reply.finished.connect(self.__finished)
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @pyqtSlot()
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def __finished(self):
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Private slot handling the downloaded icon.
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 # ignore any errors and emit an empty icon in this case
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 data = self.__reply.readAll()
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 icon = QIcon(QPixmap.fromImage(QImage.fromData(data)))
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.iconLoaded.emit(icon)
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
63 if SSL_AVAILABLE:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
64 if self.__reply.url().scheme().lower() == "https":
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
65 sslConfiguration = self.__reply.sslConfiguration()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
66 self.sslConfiguration.emit(sslConfiguration)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
67 else:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7764
diff changeset
68 self.clearSslConfiguration.emit()
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
69
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__reply.deleteLater()
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__reply = None

eric ide

mercurial