Tue, 18 Oct 2022 16:06:21 +0200
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
6695 | 1 | # -*- coding: utf-8 -*- |
2 | ||
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8605
diff
changeset
|
3 | # Copyright (c) 2019 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
6695 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a widget to show some site information. | |
8 | """ | |
9 | ||
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
10 | from PyQt6.QtCore import pyqtSlot, Qt, QPoint |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
11 | from PyQt6.QtWidgets import ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
12 | QMenu, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
13 | QGridLayout, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
14 | QHBoxLayout, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
15 | QLabel, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
16 | QFrame, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
17 | QSizePolicy, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | QPushButton, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
19 | QSpacerItem, |
7269
0c63ea7f94bd
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
20 | ) |
6695 | 21 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
22 | from eric7.EricGui import EricPixmapCache |
6695 | 23 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
24 | from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
6695 | 25 | |
26 | ||
27 | class SiteInfoWidget(QMenu): | |
28 | """ | |
8556
766e1566cb74
Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
29 | Class implementing a widget to show site related infos. |
6695 | 30 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
31 | |
6695 | 32 | def __init__(self, browser, parent=None): |
33 | """ | |
34 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
6695 | 36 | @param browser reference to the browser view |
37 | @type WebBrowserView | |
38 | @param parent reference to the parent object | |
39 | @type QWidget | |
40 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
41 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
42 | |
6695 | 43 | self.__browser = browser |
44 | url = browser.url() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
6695 | 46 | self.setMinimumWidth(400) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | |
6695 | 48 | layout = QGridLayout(self) |
49 | rows = 0 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
6695 | 51 | titleLabel = QLabel(self) |
52 | titleLabel.setText(self.tr("<b>Site {0}</b>").format(url.host())) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
53 | layout.addWidget(titleLabel, rows, 0, 1, -1, Qt.AlignmentFlag.AlignCenter) |
6695 | 54 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
6695 | 56 | line = QFrame(self) |
57 | line.setLineWidth(1) | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
58 | line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) |
6695 | 59 | layout.addWidget(line, rows, 0, 1, -1) |
60 | rows += 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | |
6695 | 62 | secureIcon = QLabel() |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
63 | layout.addWidget(secureIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) |
6695 | 64 | secureLabel = QLabel() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | secureLabel.setSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | ) |
6695 | 68 | layout.addWidget(secureLabel, rows, 1) |
69 | if url.scheme() in ["https"]: | |
7565
928373562e36
Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
70 | if WebBrowserWindow.networkManager().isInsecureHost(url.host()): |
928373562e36
Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
71 | secureLabel.setText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | self.tr("Your connection to this site " "<b>may not be secure</b>.") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
73 | ) |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
74 | secureIcon.setPixmap(EricPixmapCache.getPixmap("securityMedium")) |
7565
928373562e36
Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
75 | else: |
928373562e36
Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7533
diff
changeset
|
76 | secureLabel.setText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | self.tr("Your connection to this site is <b>secure</b>.") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | ) |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
79 | secureIcon.setPixmap(EricPixmapCache.getPixmap("securityHigh")) |
6695 | 80 | else: |
81 | secureLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | self.tr("Your connection to this site is <b>not secure</b>.") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
83 | ) |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
84 | secureIcon.setPixmap(EricPixmapCache.getPixmap("securityLow")) |
6695 | 85 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | |
6695 | 87 | visits = WebBrowserWindow.historyManager().siteVisitsCount( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
88 | url.scheme(), url.host() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | ) |
6695 | 90 | historyIcon = QLabel() |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
91 | layout.addWidget(historyIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) |
6695 | 92 | historyLabel = QLabel() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | historyLabel.setSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
95 | ) |
6695 | 96 | layout.addWidget(historyLabel, rows, 1) |
97 | if visits > 3: | |
98 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
99 | self.tr("This is your <b>{0}.</b> visit of this site.").format(visits) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
100 | ) |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
101 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagGreen")) |
6695 | 102 | elif visits == 0: |
103 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
104 | self.tr("You have <b>never</b> visited this site before.").format( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | visits |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
107 | ) |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
108 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagBlack")) |
6695 | 109 | else: |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9384
diff
changeset
|
110 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagYellow")) |
6695 | 111 | if visits == 1: |
112 | visitStr = self.tr("first") | |
113 | elif visits == 2: | |
114 | visitStr = self.tr("second") | |
115 | else: | |
116 | visitStr = self.tr("third") | |
117 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | self.tr("This is your <b>{0}</b> visit of this site.").format(visitStr) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
119 | ) |
6695 | 120 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | |
6695 | 122 | line = QFrame(self) |
123 | line.setLineWidth(1) | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
124 | line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) |
6695 | 125 | layout.addWidget(line, rows, 0, 1, -1) |
126 | rows += 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
127 | |
6695 | 128 | horizontalLayout = QHBoxLayout() |
129 | spacerItem = QSpacerItem( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
130 | 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | ) |
6695 | 132 | horizontalLayout.addItem(spacerItem) |
133 | moreButton = QPushButton(self.tr("More..."), self) | |
134 | horizontalLayout.addWidget(moreButton) | |
135 | moreButton.clicked.connect(self.__showSiteInfo) | |
136 | layout.addLayout(horizontalLayout, rows, 0, 1, -1) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
137 | |
8561
641304b46f08
Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8556
diff
changeset
|
138 | layout.activate() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
139 | |
6695 | 140 | def showAt(self, pos): |
141 | """ | |
142 | Public method to show the widget. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | |
6695 | 144 | @param pos position to show at |
145 | @type QPoint | |
146 | """ | |
147 | self.adjustSize() | |
148 | xpos = pos.x() - self.width() // 2 | |
149 | if xpos < 0: | |
150 | xpos = 10 | |
151 | p = QPoint(xpos, pos.y() + 10) | |
152 | self.move(p) | |
153 | self.show() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
154 | |
6695 | 155 | def accept(self): |
156 | """ | |
157 | Public method to accept the widget. | |
158 | """ | |
159 | self.close() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | |
6695 | 161 | @pyqtSlot() |
162 | def __showSiteInfo(self): | |
163 | """ | |
164 | Private slot to show the site info dialog. | |
165 | """ | |
166 | from .SiteInfoDialog import SiteInfoDialog | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
168 | siteinfoDialog = SiteInfoDialog(self.__browser, self.__browser.mainWindow()) |
6695 | 169 | siteinfoDialog.show() |