src/eric7/WebBrowser/SafeBrowsing/SafeBrowsingLabel.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2017 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the label to show some SSL info.
8 """
9
10 from PyQt6.QtCore import Qt, pyqtSlot, pyqtSignal, QPoint
11 from PyQt6.QtWidgets import QLabel
12
13
14 class SafeBrowsingLabel(QLabel):
15 """
16 Class implementing a label to show some Safe Browsing info.
17
18 @signal clicked(pos) emitted to indicate a click of the label (QPoint)
19 """
20 clicked = pyqtSignal(QPoint)
21
22 nokStyle = "QLabel { color : white; background-color : red; }"
23
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent reference to the parent widget (QWidget)
29 """
30 super().__init__(parent)
31
32 self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
33 self.setCursor(Qt.CursorShape.PointingHandCursor)
34
35 self.setStyleSheet(SafeBrowsingLabel.nokStyle)
36
37 self.__threatType = ""
38 self.__threatMessages = ""
39
40 self.__deafultText = self.tr("Malicious Site")
41 self.__updateLabel()
42
43 def mouseReleaseEvent(self, evt):
44 """
45 Protected method to handle mouse release events.
46
47 @param evt reference to the mouse event (QMouseEvent)
48 """
49 if evt.button() == Qt.MouseButton.LeftButton:
50 self.clicked.emit(evt.globalPosition().toPoint())
51 else:
52 super().mouseReleaseEvent(evt)
53
54 def mouseDoubleClickEvent(self, evt):
55 """
56 Protected method to handle mouse double click events.
57
58 @param evt reference to the mouse event (QMouseEvent)
59 """
60 if evt.button() == Qt.MouseButton.LeftButton:
61 self.clicked.emit(evt.globalPosition().toPoint())
62 else:
63 super().mouseDoubleClickEvent(evt)
64
65 @pyqtSlot()
66 def __updateLabel(self):
67 """
68 Private slot to update the label text.
69 """
70 if self.__threatType:
71 self.setText(self.__threatType)
72 else:
73 self.setText(self.__deafultText)
74
75 @pyqtSlot(str, str)
76 def setThreatInfo(self, threatType, threatMessages):
77 """
78 Public slot to set threat information.
79
80 @param threatType threat type
81 @type str
82 @param threatMessages more verbose info about detected threats
83 @type str
84 """
85 self.__threatType = threatType
86 self.__threatMessages = threatMessages
87
88 self.__updateLabel()
89
90 def getThreatInfo(self):
91 """
92 Public method to get the threat info text.
93
94 @return threat info text
95 @rtype str
96 """
97 return self.__threatMessages

eric ide

mercurial