WebBrowser/SiteInfo/SiteInfoDialog.py

Thu, 14 Apr 2016 19:54:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 14 Apr 2016 19:54:12 +0200
changeset 4941
b0e4e7a65872
parent 4939
98ef487d00eb
child 5001
08eaee907686
permissions
-rw-r--r--

Improved the imagge preview in the new web browser site info dialog.

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

eric ide

mercurial