src/eric7/Preferences/ConfigurationPages/WebBrowserVirusTotalPage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
13 from .Ui_WebBrowserVirusTotalPage import Ui_WebBrowserVirusTotalPage 13 from .Ui_WebBrowserVirusTotalPage import Ui_WebBrowserVirusTotalPage
14 14
15 import Preferences 15 import Preferences
16 16
17 17
18 class WebBrowserVirusTotalPage(ConfigurationPageBase, 18 class WebBrowserVirusTotalPage(ConfigurationPageBase, Ui_WebBrowserVirusTotalPage):
19 Ui_WebBrowserVirusTotalPage):
20 """ 19 """
21 Class implementing VirusTotal configuration page (web browser variant). 20 Class implementing VirusTotal configuration page (web browser variant).
22 """ 21 """
22
23 def __init__(self): 23 def __init__(self):
24 """ 24 """
25 Constructor 25 Constructor
26 """ 26 """
27 super().__init__() 27 super().__init__()
28 self.setupUi(self) 28 self.setupUi(self)
29 self.setObjectName("HelpVirusTotalPage") 29 self.setObjectName("HelpVirusTotalPage")
30 30
31 self.testResultLabel.setHidden(True) 31 self.testResultLabel.setHidden(True)
32 32
33 from WebBrowser.VirusTotal.VirusTotalApi import VirusTotalAPI 33 from WebBrowser.VirusTotal.VirusTotalApi import VirusTotalAPI
34
34 self.__vt = VirusTotalAPI(self) 35 self.__vt = VirusTotalAPI(self)
35 self.__vt.checkServiceKeyFinished.connect( 36 self.__vt.checkServiceKeyFinished.connect(self.__checkServiceKeyFinished)
36 self.__checkServiceKeyFinished) 37
37
38 # set initial values 38 # set initial values
39 self.vtEnabledCheckBox.setChecked( 39 self.vtEnabledCheckBox.setChecked(
40 Preferences.getWebBrowser("VirusTotalEnabled")) 40 Preferences.getWebBrowser("VirusTotalEnabled")
41 self.vtSecureCheckBox.setChecked( 41 )
42 Preferences.getWebBrowser("VirusTotalSecure")) 42 self.vtSecureCheckBox.setChecked(Preferences.getWebBrowser("VirusTotalSecure"))
43 self.vtServiceKeyEdit.setText( 43 self.vtServiceKeyEdit.setText(Preferences.getWebBrowser("VirusTotalServiceKey"))
44 Preferences.getWebBrowser("VirusTotalServiceKey")) 44
45
46 def save(self): 45 def save(self):
47 """ 46 """
48 Public slot to save the VirusTotal configuration. 47 Public slot to save the VirusTotal configuration.
49 """ 48 """
50 Preferences.setWebBrowser( 49 Preferences.setWebBrowser(
51 "VirusTotalEnabled", 50 "VirusTotalEnabled", self.vtEnabledCheckBox.isChecked()
52 self.vtEnabledCheckBox.isChecked()) 51 )
53 Preferences.setWebBrowser( 52 Preferences.setWebBrowser("VirusTotalSecure", self.vtSecureCheckBox.isChecked())
54 "VirusTotalSecure", 53 Preferences.setWebBrowser("VirusTotalServiceKey", self.vtServiceKeyEdit.text())
55 self.vtSecureCheckBox.isChecked()) 54
56 Preferences.setWebBrowser(
57 "VirusTotalServiceKey",
58 self.vtServiceKeyEdit.text())
59
60 @pyqtSlot(str) 55 @pyqtSlot(str)
61 def on_vtServiceKeyEdit_textChanged(self, txt): 56 def on_vtServiceKeyEdit_textChanged(self, txt):
62 """ 57 """
63 Private slot to handle changes of the service key. 58 Private slot to handle changes of the service key.
64 59
65 @param txt entered service key (string) 60 @param txt entered service key (string)
66 """ 61 """
67 self.testButton.setEnabled(txt != "") 62 self.testButton.setEnabled(txt != "")
68 63
69 @pyqtSlot() 64 @pyqtSlot()
70 def on_testButton_clicked(self): 65 def on_testButton_clicked(self):
71 """ 66 """
72 Private slot to test the entered service key. 67 Private slot to test the entered service key.
73 """ 68 """
74 self.testResultLabel.setHidden(False) 69 self.testResultLabel.setHidden(False)
75 self.testResultLabel.setText( 70 self.testResultLabel.setText(self.tr("Checking validity of the service key..."))
76 self.tr("Checking validity of the service key..."))
77 protocol = "https" if self.vtSecureCheckBox.isChecked() else "http" 71 protocol = "https" if self.vtSecureCheckBox.isChecked() else "http"
78 self.__vt.checkServiceKeyValidity( 72 self.__vt.checkServiceKeyValidity(self.vtServiceKeyEdit.text(), protocol)
79 self.vtServiceKeyEdit.text(), protocol) 73
80
81 @pyqtSlot(bool, str) 74 @pyqtSlot(bool, str)
82 def __checkServiceKeyFinished(self, result, msg): 75 def __checkServiceKeyFinished(self, result, msg):
83 """ 76 """
84 Private slot to receive the result of the service key check. 77 Private slot to receive the result of the service key check.
85 78
86 @param result flag indicating a successful check (boolean) 79 @param result flag indicating a successful check (boolean)
87 @param msg network error message (str) 80 @param msg network error message (str)
88 """ 81 """
89 if result: 82 if result:
90 self.testResultLabel.setText( 83 self.testResultLabel.setText(self.tr("The service key is valid."))
91 self.tr("The service key is valid."))
92 else: 84 else:
93 if msg == "": 85 if msg == "":
94 self.testResultLabel.setText(self.tr( 86 self.testResultLabel.setText(
95 '<font color="#FF0000">The service key is' 87 self.tr(
96 ' not valid.</font>')) 88 '<font color="#FF0000">The service key is' " not valid.</font>"
89 )
90 )
97 else: 91 else:
98 self.testResultLabel.setText(self.tr( 92 self.testResultLabel.setText(
99 '<font color="#FF0000"><b>Error:</b> {0}</font>') 93 self.tr('<font color="#FF0000"><b>Error:</b> {0}</font>').format(
100 .format(msg)) 94 msg
101 95 )
96 )
97
102 98
103 def create(dlg): 99 def create(dlg):
104 """ 100 """
105 Module function to create the configuration page. 101 Module function to create the configuration page.
106 102
107 @param dlg reference to the configuration dialog 103 @param dlg reference to the configuration dialog
108 @return reference to the instantiated page (ConfigurationPageBase) 104 @return reference to the instantiated page (ConfigurationPageBase)
109 """ 105 """
110 page = WebBrowserVirusTotalPage() 106 page = WebBrowserVirusTotalPage()
111 return page 107 return page

eric ide

mercurial