Wed, 13 Jul 2022 14:55:47 +0200
Reformatted the source code using the 'Black' utility.
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
3 | # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a dialog to show some information about a site. |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
10 | from PyQt6.QtCore import pyqtSlot, QUrl, Qt |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
11 | from PyQt6.QtGui import QPixmap, QImage, QPainter, QColor, QBrush |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
12 | from PyQt6.QtNetwork import QNetworkRequest, QNetworkReply |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtWidgets import ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
14 | QDialog, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
15 | QTreeWidgetItem, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
16 | QGraphicsScene, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
17 | QMenu, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | QApplication, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
19 | QGraphicsPixmapItem, |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
20 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
21 | |
7766 | 22 | try: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
23 | from PyQt6.QtNetwork import QSslCertificate # __IGNORE_WARNING__ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
7766 | 25 | SSL = True |
26 | except ImportError: | |
27 | SSL = False | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | |
8358
144a6b854f70
Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8356
diff
changeset
|
29 | from EricWidgets import EricMessageBox, EricFileDialog |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
31 | from .Ui_SiteInfoDialog import Ui_SiteInfoDialog |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
33 | from ..Tools import Scripts, WebBrowserTools |
5001
08eaee907686
Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4941
diff
changeset
|
34 | from ..WebBrowserPage import WebBrowserPage |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | import UI.PixmapCache |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
37 | import Preferences |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
38 | |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
39 | from WebBrowser.WebBrowserWindow import WebBrowserWindow |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | class SiteInfoDialog(QDialog, Ui_SiteInfoDialog): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | Class implementing a dialog to show some information about a site. |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
47 | securityStyleFormat = "QLabel {{ background-color : {0}; }}" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | def __init__(self, browser, parent=None): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | @param browser reference to the browser window (HelpBrowser) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | @param parent reference to the parent widget (QWidget) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
56 | super().__init__(parent) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | self.setupUi(self) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7937
diff
changeset
|
58 | self.setWindowFlags(Qt.WindowType.Window) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
59 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | # put icons |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | self.tabWidget.setTabIcon(0, UI.PixmapCache.getIcon("siteinfo-general")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
62 | self.tabWidget.setTabIcon(1, UI.PixmapCache.getIcon("siteinfo-media")) |
7766 | 63 | if SSL: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
64 | self.tabWidget.setTabIcon(2, UI.PixmapCache.getIcon("siteinfo-security")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
66 | self.__imageReply = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
68 | self.__baseUrl = browser.url() |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | title = browser.title() |
7766 | 70 | sslInfo = browser.page().getSslCertificateChain() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
71 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | # prepare background of image preview |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
73 | self.__imagePreviewStandardBackground = self.imagePreview.backgroundBrush() |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
74 | color1 = QColor(220, 220, 220) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
75 | color2 = QColor(160, 160, 160) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
76 | self.__tilePixmap = QPixmap(8, 8) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
77 | self.__tilePixmap.fill(color1) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
78 | tilePainter = QPainter(self.__tilePixmap) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
79 | tilePainter.fillRect(0, 0, 4, 4, color2) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
80 | tilePainter.fillRect(4, 4, 4, 4, color2) |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
81 | tilePainter.end() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | # populate General tab |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | self.heading.setText("<b>{0}</b>".format(title)) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
85 | self.siteAddressLabel.setText(self.__baseUrl.toString()) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
86 | if self.__baseUrl.scheme() in ["https"]: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | if WebBrowserWindow.networkManager().isInsecureHost(self.__baseUrl.host()): |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
88 | self.securityIconLabel.setPixmap( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | UI.PixmapCache.getPixmap("securityMedium") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
90 | ) |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
91 | self.securityLabel.setStyleSheet( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
92 | SiteInfoDialog.securityStyleFormat.format( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
93 | Preferences.getWebBrowser("InsecureUrlColor").name() |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
94 | ) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
95 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | self.securityLabel.setText( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
97 | self.tr("<b>Connection is encrypted but may be insecure.</b>") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | ) |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
99 | else: |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
100 | self.securityIconLabel.setPixmap( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | UI.PixmapCache.getPixmap("securityHigh") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | ) |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
103 | self.securityLabel.setStyleSheet( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
104 | SiteInfoDialog.securityStyleFormat.format( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
105 | Preferences.getWebBrowser("SecureUrlColor").name() |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
106 | ) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
107 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
108 | self.securityLabel.setText(self.tr("<b>Connection is encrypted.</b>")) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | self.securityIconLabel.setPixmap(UI.PixmapCache.getPixmap("securityLow")) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | self.securityLabel.setText(self.tr("<b>Connection is not encrypted.</b>")) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
112 | browser.page().runJavaScript( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
113 | "document.charset", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | WebBrowserPage.SafeJsWorld, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
115 | lambda res: self.encodingLabel.setText(res), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
117 | |
7766 | 118 | # populate the Security tab |
8227
349308e84eeb
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
119 | if sslInfo and SSL: |
349308e84eeb
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
120 | self.sslWidget.showCertificateChain(sslInfo) |
7768
6aec9032afad
SiteInfoDialog: fixed an issue setting the enabled state of the security tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7766
diff
changeset
|
121 | self.tabWidget.setTabEnabled(2, SSL and bool(sslInfo)) |
6aec9032afad
SiteInfoDialog: fixed an issue setting the enabled state of the security tab.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7766
diff
changeset
|
122 | self.securityDetailsButton.setEnabled(SSL and bool(sslInfo)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
124 | # populate Meta tags |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
125 | browser.page().runJavaScript( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
126 | Scripts.getAllMetaAttributes(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
127 | WebBrowserPage.SafeJsWorld, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
128 | self.__processMetaAttributes, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
130 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | # populate Media tab |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | browser.page().runJavaScript( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | Scripts.getAllImages(), WebBrowserPage.SafeJsWorld, self.__processImageTags |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
134 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | |
7766 | 136 | self.tabWidget.setCurrentIndex(0) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
137 | |
7766 | 138 | @pyqtSlot() |
139 | def on_securityDetailsButton_clicked(self): | |
140 | """ | |
141 | Private slot to show security details. | |
142 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | self.tabWidget.setCurrentIndex(self.tabWidget.indexOf(self.securityTab)) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
144 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
145 | def __processImageTags(self, res): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
146 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
147 | Private method to process the image tags. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
148 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
149 | @param res result of the JavaScript script |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
150 | @type list of dict |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
151 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
152 | for img in res: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
153 | src = img["src"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
154 | alt = img["alt"] |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | if not alt: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | if src.find("/") == -1: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | alt = src |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | else: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
159 | pos = src.rfind("/") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | alt = src[pos + 1 :] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | if not src or not alt: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | continue |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
164 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | QTreeWidgetItem(self.imagesTree, [alt, src]) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | for col in range(self.imagesTree.columnCount()): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | self.imagesTree.resizeColumnToContents(col) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | if self.imagesTree.columnWidth(0) > 300: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | self.imagesTree.setColumnWidth(0, 300) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | self.imagesTree.setCurrentItem(self.imagesTree.topLevelItem(0)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
172 | self.imagesTree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | self.imagesTree.customContextMenuRequested.connect( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
174 | self.__imagesTreeContextMenuRequested |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
175 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
176 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
177 | def __processMetaAttributes(self, res): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
178 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
179 | Private method to process the meta attributes. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
180 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
181 | @param res result of the JavaScript script |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
182 | @type list of dict |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | """ |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
184 | for meta in res: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
185 | content = meta["content"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
186 | name = meta["name"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
187 | if not name: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
188 | name = meta["httpequiv"] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
190 | if not name or not content: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
191 | continue |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
192 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
193 | if meta["charset"]: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
194 | self.encodingLabel.setText(meta["charset"]) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
195 | if "charset=" in content: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
196 | self.encodingLabel.setText(content[content.index("charset=") + 8 :]) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
197 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
198 | QTreeWidgetItem(self.tagsTree, [name, content]) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
199 | for col in range(self.tagsTree.columnCount()): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
200 | self.tagsTree.resizeColumnToContents(col) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
201 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | def on_imagesTree_currentItemChanged(self, current, previous): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | Private slot to show a preview of the selected image. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
206 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | @param current current image entry (QTreeWidgetItem) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | @param previous old current entry (QTreeWidgetItem) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | if current is None: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
212 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | imageUrl = QUrl(current.text(1)) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
214 | if imageUrl.isRelative(): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
215 | imageUrl = self.__baseUrl.resolved(imageUrl) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
216 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
217 | pixmap = QPixmap() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
218 | loading = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
219 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
220 | if imageUrl.scheme() == "data": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
221 | encodedUrl = current.text(1).encode("utf-8") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
222 | imageData = encodedUrl[encodedUrl.find(b",") + 1 :] |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
223 | pixmap = WebBrowserTools.pixmapFromByteArray(imageData) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
224 | elif imageUrl.scheme() == "file": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
225 | pixmap = QPixmap(imageUrl.toLocalFile()) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
226 | elif imageUrl.scheme() == "qrc": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
227 | pixmap = QPixmap(imageUrl.toString()[3:]) |
1433
cb6507f68b16
Fixed an issue in the site info dialog causing it to fail, if no disk cache was enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1427
diff
changeset
|
228 | else: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
229 | if self.__imageReply is not None: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
230 | self.__imageReply.deleteLater() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
231 | self.__imageReply = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
232 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
233 | from WebBrowser.WebBrowserWindow import WebBrowserWindow |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
234 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
235 | self.__imageReply = WebBrowserWindow.networkManager().get( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
236 | QNetworkRequest(imageUrl) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
237 | ) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
238 | self.__imageReply.finished.connect(self.__imageReplyFinished) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
239 | loading = True |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
240 | self.__showLoadingText() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
241 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
242 | if not loading: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
243 | self.__showPixmap(pixmap) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
244 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
245 | @pyqtSlot() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
246 | def __imageReplyFinished(self): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
247 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
248 | Private slot handling the loading of an image. |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
249 | """ |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7937
diff
changeset
|
250 | if self.__imageReply.error() != QNetworkReply.NetworkError.NoError: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
251 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
252 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
253 | data = self.__imageReply.readAll() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
254 | self.__showPixmap(QPixmap.fromImage(QImage.fromData(data))) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
255 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
256 | def __showPixmap(self, pixmap): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
257 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
258 | Private method to show a pixmap in the preview pane. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
259 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
260 | @param pixmap pixmap to be shown |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
261 | @type QPixmap |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
262 | """ |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | scene = QGraphicsScene(self.imagePreview) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
264 | if pixmap.isNull(): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
265 | self.imagePreview.setBackgroundBrush(self.__imagePreviewStandardBackground) |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
266 | scene.addText(self.tr("Preview not available.")) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | else: |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
268 | self.imagePreview.setBackgroundBrush(QBrush(self.__tilePixmap)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | scene.addPixmap(pixmap) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | self.imagePreview.setScene(scene) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
271 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
272 | def __showLoadingText(self): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
273 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
274 | Private method to show some text while loading an image. |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
275 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
276 | self.imagePreview.setBackgroundBrush(self.__imagePreviewStandardBackground) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
277 | scene = QGraphicsScene(self.imagePreview) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
278 | scene.addText(self.tr("Loading...")) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
279 | self.imagePreview.setScene(scene) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
280 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | def __imagesTreeContextMenuRequested(self, pos): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | Private slot to show a context menu for the images list. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
284 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | @param pos position for the menu (QPoint) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | itm = self.imagesTree.itemAt(pos) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | if itm is None: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
290 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | menu = QMenu() |
7937
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
292 | act1 = menu.addAction(self.tr("Copy Image Location to Clipboard")) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
293 | act1.setData(itm.text(1)) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
294 | act1.triggered.connect(lambda: self.__copyAction(act1)) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
295 | act2 = menu.addAction(self.tr("Copy Image Name to Clipboard")) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
296 | act2.setData(itm.text(0)) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
297 | act2.triggered.connect(lambda: self.__copyAction(act2)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | menu.addSeparator() |
7937
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
299 | act3 = menu.addAction(self.tr("Save Image")) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
300 | act3.setData(self.imagesTree.indexOfTopLevelItem(itm)) |
181d1160f617
Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
301 | act3.triggered.connect(lambda: self.__saveImage(act3)) |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7577
diff
changeset
|
302 | menu.exec(self.imagesTree.viewport().mapToGlobal(pos)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
303 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
304 | def __copyAction(self, act): |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | Private slot to copy the image URL or the image name to the clipboard. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
307 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
308 | @param act reference to the action that triggered |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
309 | @type QAction |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | QApplication.clipboard().setText(act.data()) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
313 | def __saveImage(self, act): |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | Private slot to save the selected image to disk. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
316 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
317 | @param act reference to the action that triggered |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
318 | @type QAction |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | index = act.data() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | itm = self.imagesTree.topLevelItem(index) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | if itm is None: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
324 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
325 | if not self.imagePreview.scene() or len(self.imagePreview.scene().items()) == 0: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
326 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
328 | pixmapItem = self.imagePreview.scene().items()[0] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
329 | if not isinstance(pixmapItem, QGraphicsPixmapItem): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
330 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
331 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
332 | if pixmapItem.pixmap().isNull(): |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8322
diff
changeset
|
333 | EricMessageBox.warning( |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
334 | self, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
335 | self.tr("Save Image"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
336 | self.tr("""<p>This preview is not available.</p>"""), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
337 | ) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
339 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
340 | imageFileName = WebBrowserTools.getFileNameFromUrl(QUrl(itm.text(1))) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
341 | index = imageFileName.rfind(".") |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
342 | if index != -1: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
343 | imageFileName = imageFileName[:index] + ".png" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
344 | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8322
diff
changeset
|
345 | filename = EricFileDialog.getSaveFileName( |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | self, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
347 | self.tr("Save Image"), |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
348 | imageFileName, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
349 | self.tr("All Files (*)"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
350 | EricFileDialog.DontConfirmOverwrite, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
351 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
352 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | if not filename: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
355 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
356 | if not pixmapItem.pixmap().save(filename, "PNG"): |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8322
diff
changeset
|
357 | EricMessageBox.critical( |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
358 | self, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
359 | self.tr("Save Image"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
360 | self.tr("""<p>Cannot write to file <b>{0}</b>.</p>""").format(filename), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
361 | ) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | return |