WebBrowser/SiteInfo/SiteInfoDialog.py

Wed, 07 Feb 2018 20:14:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 07 Feb 2018 20:14:09 +0100
changeset 6121
d3d64f3128b3
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
permissions
-rw-r--r--

Continued removing the use of QObject.sender().

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
3 # Copyright (c) 2011 - 2018 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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
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
11
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
12 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
13 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
14 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
15 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, \
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
16 QApplication, QGraphicsPixmapItem
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 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
19
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
20 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
21
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
22 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
23 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
24
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import UI.PixmapCache
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 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
29 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 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
31 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 okStyle = "QLabel { color : white; background-color : green; }"
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 nokStyle = "QLabel { color : white; background-color : red; }"
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 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
36 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Constructor
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 @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
40 @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
41 """
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
42 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
43 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
44 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
45
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 # put icons
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
47 self.tabWidget.setTabIcon(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
48 0, UI.PixmapCache.getIcon("siteinfo-general.png"))
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
49 self.tabWidget.setTabIcon(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
50 1, UI.PixmapCache.getIcon("siteinfo-media.png"))
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
51
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
52 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
53
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
54 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
55 title = browser.title()
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
4941
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
57 #prepare background of image preview
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
58 self.__imagePreviewStandardBackground = \
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
59 self.imagePreview.backgroundBrush()
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 # populate General tab
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 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
71 self.siteAddressLabel.setText(self.__baseUrl.toString())
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
72 if self.__baseUrl.scheme() in ["https"]:
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.securityLabel.setStyleSheet(SiteInfoDialog.okStyle)
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.securityLabel.setText('<b>Connection is encrypted.</b>')
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 else:
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.securityLabel.setStyleSheet(SiteInfoDialog.nokStyle)
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.securityLabel.setText('<b>Connection is not encrypted.</b>')
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
78 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
79 "document.charset", WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
80 lambda res: self.encodingLabel.setText(res))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
81
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
82 # populate Meta tags
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
83 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
84 WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
85 self.__processMetaAttributes)
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 # populate Media tab
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4783
diff changeset
88 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
89 WebBrowserPage.SafeJsWorld,
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
90 self.__processImageTags)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
91
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
92 def __processImageTags(self, res):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
93 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
94 Private method to process the image tags.
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
95
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
96 @param res result of the JavaScript script
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
97 @type list of dict
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
98 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
99 for img in res:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
100 src = img["src"]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
101 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
102 if not alt:
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 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
104 alt = src
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 else:
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
106 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
107 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
108
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 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
110 continue
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 QTreeWidgetItem(self.imagesTree, [alt, src])
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
113
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 self.__imagesTreeContextMenuRequested)
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
122
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
123 def __processMetaAttributes(self, res):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
124 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
125 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
126
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 @param res result of the JavaScript script
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 @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
129 """
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130 for meta in res:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 content = meta["content"]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 name = meta["name"]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 if not name:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 name = meta["httpequiv"]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136 if not name or not content:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 continue
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
139 if meta["charset"]:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 self.encodingLabel.setText(meta["charset"])
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141 if "charset=" in content:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
142 self.encodingLabel.setText(
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 content[content.index("charset=") + 8:])
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 QTreeWidgetItem(self.tagsTree, [name, content])
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
146 for col in range(self.tagsTree.columnCount()):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 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
148
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 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
151 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @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
155 @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
156 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 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
158 return
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 imageUrl = QUrl(current.text(1))
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
161 if imageUrl.isRelative():
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
162 imageUrl = self.__baseUrl.resolved(imageUrl)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
163
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
164 pixmap = QPixmap()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
165 loading = False
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
167 if imageUrl.scheme() == "data":
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168 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
169 imageData = encodedUrl[encodedUrl.find(b",") + 1:]
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
170 pixmap = WebBrowserTools.pixmapFromByteArray(imageData)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
171 elif imageUrl.scheme() == "file":
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
172 pixmap = QPixmap(imageUrl.toLocalFile())
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
173 elif imageUrl.scheme() == "qrc":
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
174 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
175 else:
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
176 if self.__imageReply is not None:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
177 self.__imageReply.deleteLater()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
178 self.__imageReply = None
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
180 from WebBrowser.WebBrowserWindow import WebBrowserWindow
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
181 self.__imageReply = WebBrowserWindow.networkManager().get(
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 QNetworkRequest(imageUrl))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
183 self.__imageReply.finished.connect(self.__imageReplyFinished)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
184 loading = True
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
185 self.__showLoadingText()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
186
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
187 if not loading:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
188 self.__showPixmap(pixmap)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
189
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
190 @pyqtSlot()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 def __imageReplyFinished(self):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
192 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
193 Private slot handling the loading of an image.
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
194 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
195 if self.__imageReply.error() != QNetworkReply.NoError:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
196 return
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
197
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
198 data = self.__imageReply.readAll()
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
199 self.__showPixmap(QPixmap.fromImage(QImage.fromData(data)))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
200
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
201 def __showPixmap(self, pixmap):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
202 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
203 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
204
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
205 @param pixmap pixmap to be shown
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
206 @type QPixmap
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
207 """
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 scene = QGraphicsScene(self.imagePreview)
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
209 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
210 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
211 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
212 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
213 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
214 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
215 scene.addPixmap(pixmap)
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 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
217
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
218 def __showLoadingText(self):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
219 """
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
220 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
221 """
4941
b0e4e7a65872 Improved the imagge preview in the new web browser site info dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4939
diff changeset
222 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
223 self.__imagePreviewStandardBackground)
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
224 scene = QGraphicsScene(self.imagePreview)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
225 scene.addText(self.tr("Loading..."))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
226 self.imagePreview.setScene(scene)
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
227
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 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
229 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 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
231
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 @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
233 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 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
235 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
236 return
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 menu = QMenu()
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
239 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
240 act.setData(itm.text(1))
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
241 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
242 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
243 act.setData(itm.text(0))
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
244 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
245 menu.addSeparator()
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
246 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
247 act.setData(self.imagesTree.indexOfTopLevelItem(itm))
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
248 act.triggered.connect(lambda: self.__saveImage(act))
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
249 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
250
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
251 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
252 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 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
254
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
255 @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
256 @type QAction
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 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
259
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
260 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
261 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 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
263
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
264 @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
265 @type QAction
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 index = act.data()
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 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
269 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
270 return
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
272 if not self.imagePreview.scene() or \
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
273 len(self.imagePreview.scene().items()) == 0:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
274 return
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
276 pixmapItem = self.imagePreview.scene().items()[0]
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
277 if not isinstance(pixmapItem, QGraphicsPixmapItem):
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
278 return
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
279
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
280 if pixmapItem.pixmap().isNull():
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
281 E5MessageBox.warning(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
282 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
283 self.tr("Save Image"),
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
284 self.tr(
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285 """<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
286 return
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
288 imageFileName = WebBrowserTools.getFileNameFromUrl(QUrl(itm.text(1)))
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
289 index = imageFileName.rfind(".")
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
290 if index != -1:
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
291 imageFileName = imageFileName[:index] + ".png"
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
292
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 filename = E5FileDialog.getSaveFileName(
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
295 self.tr("Save Image"),
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
296 imageFileName,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
297 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
298 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
299
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 if not filename:
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 return
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
4783
7de17766a5df Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
303 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
304 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
305 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
306 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
307 self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2432
diff changeset
308 """<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
309 .format(filename))
1427
09d6731b73ad Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 return

eric ide

mercurial