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