eric6/WebBrowser/SiteInfo/SiteInfoDialog.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7937
181d1160f617
child 8218
7c09585bd960
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2011 - 2021 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
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
10 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
11 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
12 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
13 from PyQt5.QtWidgets import (
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, QApplication,
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 QGraphicsPixmapItem
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 )
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
17 try:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
18 from PyQt5.QtNetwork import QSslCertificate # __IGNORE_WARNING__
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
19 SSL = True
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
20 except ImportError:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
21 SSL = False
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
25 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
26
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
27 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
28 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
29
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 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
31 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
32
6eaa43d3786e SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
33 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
34
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 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
37 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 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
39 """
7577
6eaa43d3786e SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
40 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
41
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Constructor
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @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
47 @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
48 """
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
49 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
50 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
51 self.setWindowFlags(Qt.WindowType.Window)
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 # put icons
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
54 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
55 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
56 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
57 1, UI.PixmapCache.getIcon("siteinfo-media"))
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
58 if SSL:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
59 self.tabWidget.setTabIcon(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
60 2, UI.PixmapCache.getIcon("siteinfo-security"))
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
61
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
62 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
63
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
64 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
65 title = browser.title()
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
66 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
67
4941
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
68 #prepare background of image preview
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
69 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
70 self.imagePreview.backgroundBrush()
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
71 )
4941
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 # populate General tab
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 self.siteAddressLabel.setText(self.__baseUrl.toString())
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
84 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
85 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
86 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
87 ):
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(
6eaa43d3786e SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
89 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
90 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
91 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
92 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
93 )
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 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
96 '<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
97 else:
6eaa43d3786e SiteInfoDialog: added a security icon and an indication for potentially insecure sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
98 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
99 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
100 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
101 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
102 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
103 )
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 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
106 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
107 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
108 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
109 UI.PixmapCache.getPixmap("securityLow"))
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
110 self.securityLabel.setText(
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
111 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(
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
113 "document.charset", WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114 lambda res: self.encodingLabel.setText(res))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
115
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
116 # populate the Security tab
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
117 if sslInfo:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
118 if SSL:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
119 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
120 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
121 self.securityDetailsButton.setEnabled(SSL and bool(sslInfo))
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
122
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
123 # populate Meta tags
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
124 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
125 WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 self.__processMetaAttributes)
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # populate Media tab
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
129 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
130 WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 self.__processImageTags)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
133 self.tabWidget.setCurrentIndex(0)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
134
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
135 @pyqtSlot()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
136 def on_securityDetailsButton_clicked(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
137 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
138 Private slot to show security details.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
139 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
140 self.tabWidget.setCurrentIndex(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
141 self.tabWidget.indexOf(self.securityTab))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
142
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 def __processImageTags(self, res):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
145 Private method to process the image tags.
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 @param res result of the JavaScript script
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
148 @type list of dict
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
150 for img in res:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
151 src = img["src"]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
152 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
153 if not alt:
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 alt = src
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 else:
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
157 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
158 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
159
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 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
161 continue
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 QTreeWidgetItem(self.imagesTree, [alt, src])
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
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 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
166 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
167 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
168 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
169 self.imagesTree.setCurrentItem(self.imagesTree.topLevelItem(0))
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
170 self.imagesTree.setContextMenuPolicy(
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
171 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
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 """
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
247 if self.__imageReply.error() != QNetworkReply.NetworkError.NoError:
4783
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()
7937
181d1160f617 Fixed some 'lambda' related issues by converting them to 'functools.partial'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
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

eric ide

mercurial