Fri, 11 May 2012 18:48:10 +0200
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
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 | |
1509
c0b5e693b0eb
Updated copyright for 2012.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1474
diff
changeset
|
3 | # Copyright (c) 2011 - 2012 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 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | import os |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | from PyQt4.QtCore import pyqtSlot, QUrl, Qt, QFile |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | from PyQt4.QtGui import QDialog, QTreeWidgetItem, QPixmap, QGraphicsScene, QMenu, \ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | QCursor, QApplication, QFileDialog |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | from PyQt4.QtWebKit import QWebSettings |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | 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
|
18 | |
1861
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
19 | try: |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
20 | from .Ui_SiteInfoDialog import Ui_SiteInfoDialog # __IGNORE_WARNING__ |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
21 | SSL = True |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
22 | except ImportError: |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
23 | from .Ui_SiteInfoNoSslDialog import Ui_SiteInfoDialog # __IGNORE_WARNING__ |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
24 | SSL = False |
1427
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 | from ..Download.DownloadUtilities import dataString |
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 | import Helpviewer.HelpWindow |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | import UI.PixmapCache |
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 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | 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
|
34 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | 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
|
36 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | 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
|
38 | 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
|
39 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | 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
|
41 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | Constructor |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | @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
|
45 | @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
|
46 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | super().__init__(parent) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | self.setupUi(self) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | # put icons |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.tabWidget.setTabIcon(0, UI.PixmapCache.getIcon("siteinfo-general.png")) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | self.tabWidget.setTabIcon(1, UI.PixmapCache.getIcon("siteinfo-media.png")) |
1861
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
53 | if SSL: |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
54 | self.tabWidget.setTabIcon(2, UI.PixmapCache.getIcon("siteinfo-security.png")) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | frame = browser.page().mainFrame() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | title = browser.title() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | sslInfo = browser.page().getSslInfo() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | # populate General tab |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | self.heading.setText("<b>{0}</b>".format(title)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | self.siteAddressLabel.setText(frame.baseUrl().toString()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | self.sizeLabel.setText(dataString(browser.page().totalBytes())) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | encoding = "" |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | # populate Meta tags |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | meta = frame.findAllElements("meta") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | for element in meta: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | content = element.attribute("content") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | name = element.attribute("name") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | if not name: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | name = element.attribute("http-equiv") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | if element.attribute("charset"): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | encoding = element.attribute("charset") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | if "charset=" in content: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | encoding = content[content.index("charset=") + 8:] |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | if not content or not name: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | continue |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | QTreeWidgetItem(self.tagsTree, [name, content]) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | for col in range(self.tagsTree.columnCount()): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | self.tagsTree.resizeColumnToContents(col) |
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 | if not encoding: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | encoding = QWebSettings.globalSettings().defaultTextEncoding() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | self.encodingLabel.setText(encoding) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | # populate the Security info and the Security tab |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | if sslInfo is not None and sslInfo.isValid(): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | 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
|
92 | self.securityLabel.setText('<b>Connection is encrypted.</b>') |
1861
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
93 | if SSL: |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
94 | self.sslWidget.showCertificate(sslInfo) |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
95 | self.securityDetailsButton.setEnabled(True) |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
96 | else: |
6e8f19ebda9d
Changed the logic of the site info dialog to be able to cope with Qt installations without SSL support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
97 | self.securityDetailsButton.setEnabled(False) |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | else: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | 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
|
100 | self.securityLabel.setText('<b>Connection is not encrypted.</b>') |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | self.securityDetailsButton.setEnabled(False) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | # populate Media tab |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | images = frame.findAllElements("img") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | for element in images: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | src = element.attribute("src") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | alt = element.attribute("alt") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | if src and src.startswith("data:"): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | continue |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | if not alt: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | 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
|
112 | alt = src |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | else: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | pos = src.find("/") |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | 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
|
116 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | 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
|
118 | continue |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | QTreeWidgetItem(self.imagesTree, [alt, src]) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | 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
|
122 | 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
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | self.__imagesTreeContextMenuRequested) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | @pyqtSlot() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | def on_securityDetailsButton_clicked(self): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | Private slot to show security details. |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | self.tabWidget.setCurrentIndex(2) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | 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
|
139 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | 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
|
141 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | @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
|
143 | @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
|
144 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | 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
|
146 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | imageUrl = QUrl(current.text(1)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | if not imageUrl.host(): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | imageUrl.setHost(QUrl(self.siteAddressLabel.text()).host()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | imageUrl.setScheme(QUrl(self.siteAddressLabel.text()).scheme()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | cache = Helpviewer.HelpWindow.HelpWindow.networkAccessManager().cache() |
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
|
154 | if cache: |
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
|
155 | cacheData = cache.data(imageUrl) |
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
|
156 | else: |
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
|
157 | cacheData = None |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | pixmap = QPixmap() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | invalidPixmap = False |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | scene = QGraphicsScene(self.imagePreview) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | if not cacheData: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | invalidPixmap = True |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | else: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | pixmap.loadFromData(cacheData.readAll()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | if pixmap.isNull(): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | invalidPixmap = True |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | if invalidPixmap: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | scene.addText(self.trUtf8("Preview not available.")) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | else: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | scene.addPixmap(pixmap) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | 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
|
172 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | 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
|
174 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | 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
|
176 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | @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
|
178 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | 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
|
180 | 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
|
181 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | menu = QMenu() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | act = menu.addAction(self.trUtf8("Copy Image Location to Clipboard"), |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | self.__copyAction) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | act.setData(itm.text(1)) |
1474
1eaec11a0078
Fixed a few PEP-8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1433
diff
changeset
|
187 | act = menu.addAction(self.trUtf8("Copy Image Name to Clipboard"), |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | self.__copyAction) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | act.setData(itm.text(0)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | menu.addSeparator() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | act = menu.addAction(self.trUtf8("Save Image"), self.__saveImage) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | act.setData(self.imagesTree.indexOfTopLevelItem(itm)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | menu.exec_(QCursor.pos()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | def __copyAction(self): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | 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
|
198 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | act = self.sender() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | 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
|
201 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | def __saveImage(self): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | Private slot to 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
|
205 | """ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | act = self.sender() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | index = act.data() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | 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
|
209 | 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
|
210 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | imageUrl = QUrl(itm.text(1)) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | if not imageUrl.host(): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | imageUrl.setHost(QUrl(self.siteAddressLabel.text()).host()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | imageUrl.setScheme(QUrl(self.siteAddressLabel.text()).scheme()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | cache = Helpviewer.HelpWindow.HelpWindow.networkAccessManager().cache() |
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
|
218 | if cache: |
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
|
219 | cacheData = cache.data(imageUrl) |
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
|
220 | else: |
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
|
221 | cacheData = None |
1427
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | if not cacheData: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | E5MessageBox.critical(self, |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | self.trUtf8("Save Image"), |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | self.trUtf8("""This image is not available.""")) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | downloadDirectory = Helpviewer.HelpWindow.HelpWindow\ |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | .downloadManager().downloadDirectory() |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | fn = os.path.join(downloadDirectory, os.path.basename(itm.text(1))) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | filename = E5FileDialog.getSaveFileName( |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | self, |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | self.trUtf8("Save Image"), |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | fn, |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | self.trUtf8("All Files (*)"), |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | QFileDialog.Options(QFileDialog.DontConfirmOverwrite)) |
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 | if not filename: |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | f = QFile(filename) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | if not f.open(QFile.WriteOnly): |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | E5MessageBox.critical(self, |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | self.trUtf8("Save Image"), |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | self.trUtf8( |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | """<p>Cannot write to file <b>{0}</b>.</p>""".format(filename))) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | return |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | f.write(cacheData.readAll()) |
09d6731b73ad
Added a dialog to show some information about the current site.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | f.close() |