Wed, 07 Oct 2020 19:14:36 +0200
Web Browser
-- added a SSL information page to the site info dialog
-- added a clickable SSL info label to the URL entry
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 | |
7360
9190402e4505
Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7269
diff
changeset
|
3 | # Copyright (c) 2011 - 2020 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 | |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2432
diff
changeset
|
10 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
11 | from PyQt5.QtCore import pyqtSlot, QUrl, Qt |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
12 | from PyQt5.QtGui import QPixmap, QImage, QPainter, QColor, QBrush |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
13 | from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
14 | from PyQt5.QtWidgets import ( |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
15 | QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, QApplication, |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
16 | QGraphicsPixmapItem |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
17 | ) |
7766 | 18 | try: |
19 | from PyQt5.QtNetwork import QSslCertificate # __IGNORE_WARNING__ | |
20 | SSL = True | |
21 | except ImportError: | |
22 | SSL = False | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | from E5Gui import E5MessageBox, E5FileDialog |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
26 | 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
|
27 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
28 | 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
|
29 | 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
|
30 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | 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
|
32 | 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
|
33 | |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
34 | 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
|
35 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | 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
|
38 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | 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
|
40 | """ |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
41 | securityStyleFormat = "QLabel {{ background-color : {0}; }}" |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | 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
|
44 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | Constructor |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @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
|
48 | @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
|
49 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2432
diff
changeset
|
50 | super(SiteInfoDialog, self).__init__(parent) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.setupUi(self) |
4278
ccd1e13cb9bd
Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
52 | self.setWindowFlags(Qt.Window) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | # put icons |
3002
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2432
diff
changeset
|
55 | self.tabWidget.setTabIcon( |
7533
88261c96484b
Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
56 | 0, UI.PixmapCache.getIcon("siteinfo-general")) |
3002
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2432
diff
changeset
|
57 | self.tabWidget.setTabIcon( |
7533
88261c96484b
Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
58 | 1, UI.PixmapCache.getIcon("siteinfo-media")) |
7766 | 59 | if SSL: |
60 | self.tabWidget.setTabIcon( | |
61 | 2, UI.PixmapCache.getIcon("siteinfo-security")) | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
62 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
63 | self.__imageReply = None |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
65 | 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
|
66 | title = browser.title() |
7766 | 67 | sslInfo = browser.page().getSslCertificateChain() |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
69 | #prepare background of image preview |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
70 | self.__imagePreviewStandardBackground = ( |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
71 | self.imagePreview.backgroundBrush() |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
72 | ) |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | 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
|
77 | 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
|
78 | 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
|
79 | 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
|
80 | tilePainter.end() |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
81 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | # populate General tab |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | 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
|
84 | self.siteAddressLabel.setText(self.__baseUrl.toString()) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
85 | if self.__baseUrl.scheme() in ["https"]: |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
86 | if WebBrowserWindow.networkManager().isInsecureHost( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
87 | self.__baseUrl.host() |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
88 | ): |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
89 | self.securityIconLabel.setPixmap( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
90 | UI.PixmapCache.getPixmap("securityMedium")) |
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 | ) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
96 | self.securityLabel.setText(self.tr( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
97 | '<b>Connection is encrypted but may be insecure.</b>')) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
98 | else: |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
99 | self.securityIconLabel.setPixmap( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
100 | UI.PixmapCache.getPixmap("securityHigh")) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | ) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
105 | ) |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
106 | self.securityLabel.setText( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
107 | 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
|
108 | else: |
7577
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
109 | self.securityIconLabel.setPixmap( |
6eaa43d3786e
SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
110 | UI.PixmapCache.getPixmap("securityLow")) |
6695
0a51887c13cd
Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
111 | self.securityLabel.setText( |
0a51887c13cd
Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6645
diff
changeset
|
112 | 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
|
113 | browser.page().runJavaScript( |
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
|
114 | "document.charset", WebBrowserPage.SafeJsWorld, |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
115 | lambda res: self.encodingLabel.setText(res)) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
116 | |
7766 | 117 | # populate the Security tab |
118 | if sslInfo: | |
119 | if SSL: | |
120 | self.sslWidget.showCertificateChain(sslInfo) | |
121 | self.tabWidget.setTabEnabled(2, SSL) | |
122 | self.securityDetailsButton.setEnabled(SSL) | |
123 | ||
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
124 | # populate Meta tags |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
125 | browser.page().runJavaScript(Scripts.getAllMetaAttributes(), |
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
|
126 | WebBrowserPage.SafeJsWorld, |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
127 | self.__processMetaAttributes) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | # populate Media tab |
4917
682750cc7bd5
Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4783
diff
changeset
|
130 | browser.page().runJavaScript(Scripts.getAllImages(), |
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
|
131 | WebBrowserPage.SafeJsWorld, |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
132 | self.__processImageTags) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
133 | |
7766 | 134 | self.tabWidget.setCurrentIndex(0) |
135 | ||
136 | @pyqtSlot() | |
137 | def on_securityDetailsButton_clicked(self): | |
138 | """ | |
139 | Private slot to show security details. | |
140 | """ | |
141 | self.tabWidget.setCurrentIndex( | |
142 | self.tabWidget.indexOf(self.securityTab)) | |
143 | ||
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
144 | def __processImageTags(self, res): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
145 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
146 | Private method to process the image tags. |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
147 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
148 | @param res result of the JavaScript script |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
149 | @type list of dict |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
150 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
151 | for img in res: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
152 | src = img["src"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
153 | 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
|
154 | if not alt: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | 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
|
156 | alt = src |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | else: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
158 | pos = src.rfind("/") |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | alt = src[pos + 1:] |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | 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
|
162 | continue |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | QTreeWidgetItem(self.imagesTree, [alt, src]) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
165 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | 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
|
167 | 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
|
168 | 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
|
169 | 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
|
170 | self.imagesTree.setCurrentItem(self.imagesTree.topLevelItem(0)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | self.imagesTree.setContextMenuPolicy(Qt.CustomContextMenu) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | self.imagesTree.customContextMenuRequested.connect( |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | self.__imagesTreeContextMenuRequested) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
174 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
175 | def __processMetaAttributes(self, res): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
176 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
177 | Private method to process the meta attributes. |
1780
f42757fd021b
Added a page to the site info dialog to show web databases of the site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
178 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
179 | @param res result of the JavaScript script |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
180 | @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
|
181 | """ |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
182 | for meta in res: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
183 | content = meta["content"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
184 | name = meta["name"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
185 | if not name: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
186 | name = meta["httpequiv"] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
187 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
188 | if not name or not content: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
189 | continue |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
190 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
191 | if meta["charset"]: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
192 | self.encodingLabel.setText(meta["charset"]) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
193 | if "charset=" in content: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
194 | self.encodingLabel.setText( |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
195 | content[content.index("charset=") + 8:]) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
196 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
197 | QTreeWidgetItem(self.tagsTree, [name, content]) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
198 | for col in range(self.tagsTree.columnCount()): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
199 | self.tagsTree.resizeColumnToContents(col) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | 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
|
203 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | Private slot to show a preview of the selected image. |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | @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
|
207 | @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
|
208 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | 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
|
210 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | imageUrl = QUrl(current.text(1)) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
213 | if imageUrl.isRelative(): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
214 | imageUrl = self.__baseUrl.resolved(imageUrl) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
215 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
216 | pixmap = QPixmap() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
217 | loading = False |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
219 | if imageUrl.scheme() == "data": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
220 | encodedUrl = current.text(1).encode("utf-8") |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
221 | imageData = encodedUrl[encodedUrl.find(b",") + 1:] |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
222 | pixmap = WebBrowserTools.pixmapFromByteArray(imageData) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
223 | elif imageUrl.scheme() == "file": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
224 | pixmap = QPixmap(imageUrl.toLocalFile()) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
225 | elif imageUrl.scheme() == "qrc": |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
226 | 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
|
227 | else: |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
228 | if self.__imageReply is not None: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
229 | self.__imageReply.deleteLater() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
230 | self.__imageReply = None |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
231 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
232 | from WebBrowser.WebBrowserWindow import WebBrowserWindow |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
233 | self.__imageReply = WebBrowserWindow.networkManager().get( |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
234 | QNetworkRequest(imageUrl)) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
235 | self.__imageReply.finished.connect(self.__imageReplyFinished) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
236 | loading = True |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
237 | self.__showLoadingText() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
238 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
239 | if not loading: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
240 | self.__showPixmap(pixmap) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
241 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
242 | @pyqtSlot() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
243 | def __imageReplyFinished(self): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
244 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
245 | Private slot handling the loading of an image. |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
246 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
247 | if self.__imageReply.error() != QNetworkReply.NoError: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
248 | return |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
249 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
250 | data = self.__imageReply.readAll() |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
251 | self.__showPixmap(QPixmap.fromImage(QImage.fromData(data))) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
252 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
253 | def __showPixmap(self, pixmap): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
254 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
255 | Private method to show a pixmap in the preview pane. |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
256 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
257 | @param pixmap pixmap to be shown |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
258 | @type QPixmap |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
259 | """ |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | scene = QGraphicsScene(self.imagePreview) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
261 | if pixmap.isNull(): |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
262 | self.imagePreview.setBackgroundBrush( |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
263 | 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
|
264 | 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
|
265 | 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
|
266 | 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
|
267 | scene.addPixmap(pixmap) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | self.imagePreview.setScene(scene) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
270 | def __showLoadingText(self): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
271 | """ |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
272 | 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
|
273 | """ |
4941
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
274 | self.imagePreview.setBackgroundBrush( |
b0e4e7a65872
Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4939
diff
changeset
|
275 | self.__imagePreviewStandardBackground) |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
276 | scene = QGraphicsScene(self.imagePreview) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
277 | scene.addText(self.tr("Loading...")) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
278 | self.imagePreview.setScene(scene) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
279 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | 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
|
281 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | Private slot to show a context menu for the images list. |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | @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
|
285 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | 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
|
287 | 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
|
288 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | menu = QMenu() |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
291 | act = menu.addAction(self.tr("Copy Image Location to Clipboard")) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
292 | act.setData(itm.text(1)) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
293 | act.triggered.connect(lambda: self.__copyAction(act)) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
294 | act = menu.addAction(self.tr("Copy Image Name to Clipboard")) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
295 | act.setData(itm.text(0)) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
296 | act.triggered.connect(lambda: self.__copyAction(act)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | menu.addSeparator() |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
298 | act = menu.addAction(self.tr("Save Image")) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
299 | act.setData(self.imagesTree.indexOfTopLevelItem(itm)) |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
300 | act.triggered.connect(lambda: self.__saveImage(act)) |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7577
diff
changeset
|
301 | menu.exec(self.imagesTree.viewport().mapToGlobal(pos)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
303 | 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
|
304 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | Private slot to copy the image URL or the image name to the clipboard. |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
306 | |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
307 | @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
|
308 | @type QAction |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | QApplication.clipboard().setText(act.data()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
312 | 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
|
313 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | Private slot to save the selected image to disk. |
6121
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
315 | |
d3d64f3128b3
Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
316 | @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
|
317 | @type QAction |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | index = act.data() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | 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
|
321 | 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
|
322 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
324 | if ( |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
325 | not self.imagePreview.scene() or |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
326 | len(self.imagePreview.scene().items()) == 0 |
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
327 | ): |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
328 | return |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
330 | pixmapItem = self.imagePreview.scene().items()[0] |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
331 | if not isinstance(pixmapItem, QGraphicsPixmapItem): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
332 | return |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
333 | |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
334 | if pixmapItem.pixmap().isNull(): |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
335 | E5MessageBox.warning( |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
336 | self, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
337 | self.tr("Save Image"), |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
338 | self.tr( |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
339 | """<p>This preview is not available.</p>""")) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
342 | imageFileName = WebBrowserTools.getFileNameFromUrl(QUrl(itm.text(1))) |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
343 | index = imageFileName.rfind(".") |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
344 | if index != -1: |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
345 | imageFileName = imageFileName[:index] + ".png" |
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
346 | |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | filename = E5FileDialog.getSaveFileName( |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | self, |
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("Save Image"), |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
350 | imageFileName, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
351 | self.tr("All Files (*)"), |
1780
f42757fd021b
Added a page to the site info dialog to show web databases of the site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
352 | E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | if not filename: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | |
4783
7de17766a5df
Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4631
diff
changeset
|
357 | if not pixmapItem.pixmap().save(filename, "PNG"): |
3020
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
358 | E5MessageBox.critical( |
542e97d4ecb3
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
359 | self, |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
360 | self.tr("Save Image"), |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
361 | self.tr( |
3002
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2432
diff
changeset
|
362 | """<p>Cannot write to file <b>{0}</b>.</p>""") |
3035
36e9f388958b
Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3034
diff
changeset
|
363 | .format(filename)) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | return |