Sat, 23 Dec 2023 15:48:12 +0100
Updated copyright for 2024.
6695 | 1 | # -*- coding: utf-8 -*- |
2 | ||
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
3 | # Copyright (c) 2019 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
6695 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a widget to show some site information. | |
8 | """ | |
9 | ||
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
10 | from PyQt6.QtCore import QPoint, Qt, pyqtSlot |
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
|
11 | from PyQt6.QtWidgets import ( |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
12 | QFrame, |
9221
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, |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
16 | QMenu, |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
17 | QPushButton, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | QSizePolicy, |
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 |
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
|
23 | from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
6695 | 24 | |
25 | ||
26 | class SiteInfoWidget(QMenu): | |
27 | """ | |
8556
766e1566cb74
Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
28 | Class implementing a widget to show site related infos. |
6695 | 29 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
30 | |
6695 | 31 | def __init__(self, browser, parent=None): |
32 | """ | |
33 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | |
6695 | 35 | @param browser reference to the browser view |
36 | @type WebBrowserView | |
37 | @param parent reference to the parent object | |
38 | @type QWidget | |
39 | """ | |
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
|
40 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
6695 | 42 | self.__browser = browser |
43 | url = browser.url() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | |
6695 | 45 | self.setMinimumWidth(400) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | |
6695 | 47 | layout = QGridLayout(self) |
48 | rows = 0 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | |
6695 | 50 | titleLabel = QLabel(self) |
51 | 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
|
52 | layout.addWidget(titleLabel, rows, 0, 1, -1, Qt.AlignmentFlag.AlignCenter) |
6695 | 53 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
54 | |
6695 | 55 | line = QFrame(self) |
56 | 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
|
57 | line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) |
6695 | 58 | layout.addWidget(line, rows, 0, 1, -1) |
59 | rows += 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | |
6695 | 61 | 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
|
62 | layout.addWidget(secureIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) |
6695 | 63 | secureLabel = QLabel() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
64 | secureLabel.setSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | 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
|
66 | ) |
6695 | 67 | layout.addWidget(secureLabel, rows, 1) |
68 | 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
|
69 | 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
|
70 | secureLabel.setText( |
9576
be9f8e7e42e0
Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
71 | self.tr("Your connection to this site <b>may not be secure</b>.") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
72 | ) |
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
|
73 | 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
|
74 | 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
|
75 | secureLabel.setText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | 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
|
77 | ) |
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
|
78 | secureIcon.setPixmap(EricPixmapCache.getPixmap("securityHigh")) |
6695 | 79 | else: |
80 | secureLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
81 | 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
|
82 | ) |
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
|
83 | secureIcon.setPixmap(EricPixmapCache.getPixmap("securityLow")) |
6695 | 84 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
85 | |
6695 | 86 | visits = WebBrowserWindow.historyManager().siteVisitsCount( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | url.scheme(), url.host() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
88 | ) |
6695 | 89 | 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
|
90 | layout.addWidget(historyIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) |
6695 | 91 | historyLabel = QLabel() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | historyLabel.setSizePolicy( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | 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
|
94 | ) |
6695 | 95 | layout.addWidget(historyLabel, rows, 1) |
96 | if visits > 3: | |
97 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | 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
|
99 | ) |
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
|
100 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagGreen")) |
6695 | 101 | elif visits == 0: |
102 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | 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
|
104 | visits |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | ) |
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
|
107 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagBlack")) |
6695 | 108 | 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
|
109 | historyIcon.setPixmap(EricPixmapCache.getPixmap("flagYellow")) |
6695 | 110 | if visits == 1: |
111 | visitStr = self.tr("first") | |
112 | elif visits == 2: | |
113 | visitStr = self.tr("second") | |
114 | else: | |
115 | visitStr = self.tr("third") | |
116 | historyLabel.setText( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
117 | 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
|
118 | ) |
6695 | 119 | rows += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | |
6695 | 121 | line = QFrame(self) |
122 | 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
|
123 | line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) |
6695 | 124 | layout.addWidget(line, rows, 0, 1, -1) |
125 | rows += 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
126 | |
6695 | 127 | horizontalLayout = QHBoxLayout() |
128 | spacerItem = QSpacerItem( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | 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
|
130 | ) |
6695 | 131 | horizontalLayout.addItem(spacerItem) |
132 | moreButton = QPushButton(self.tr("More..."), self) | |
133 | horizontalLayout.addWidget(moreButton) | |
134 | moreButton.clicked.connect(self.__showSiteInfo) | |
135 | 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
|
136 | |
8561
641304b46f08
Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8556
diff
changeset
|
137 | layout.activate() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
138 | |
6695 | 139 | def showAt(self, pos): |
140 | """ | |
141 | 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
|
142 | |
6695 | 143 | @param pos position to show at |
144 | @type QPoint | |
145 | """ | |
146 | self.adjustSize() | |
147 | xpos = pos.x() - self.width() // 2 | |
148 | if xpos < 0: | |
149 | xpos = 10 | |
150 | p = QPoint(xpos, pos.y() + 10) | |
151 | self.move(p) | |
152 | self.show() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
153 | |
6695 | 154 | def accept(self): |
155 | """ | |
156 | Public method to accept the widget. | |
157 | """ | |
158 | self.close() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
159 | |
6695 | 160 | @pyqtSlot() |
161 | def __showSiteInfo(self): | |
162 | """ | |
163 | Private slot to show the site info dialog. | |
164 | """ | |
165 | from .SiteInfoDialog import SiteInfoDialog | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | siteinfoDialog = SiteInfoDialog(self.__browser, self.__browser.mainWindow()) |
6695 | 168 | siteinfoDialog.show() |