src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py

branch
eric7
changeset 9508
5a02bdb1dcba
parent 9507
1f39839655ea
child 9624
b47dfa7a137d
equal deleted inserted replaced
9507:1f39839655ea 9508:5a02bdb1dcba
40 40
41 def __init__(self, parent=None): 41 def __init__(self, parent=None):
42 """ 42 """
43 Constructor 43 Constructor
44 44
45 @param parent The parent widget. (QWidget) 45 @param parent reference to the parent widget
46 @type QWidget
46 """ 47 """
47 super().__init__(parent) 48 super().__init__(parent)
48 self.setupUi(self) 49 self.setupUi(self)
49 self.setWindowFlags(Qt.WindowType.Window) 50 self.setWindowFlags(Qt.WindowType.Window)
50 51
115 self, filename, line, index, error, sourcecode, isWarning=False 116 self, filename, line, index, error, sourcecode, isWarning=False
116 ): 117 ):
117 """ 118 """
118 Private method to create an entry in the result list. 119 Private method to create an entry in the result list.
119 120
120 @param filename file name of file (string) 121 @param filename file name of file
121 @param line line number of faulty source (integer or string) 122 @type str
122 @param index index number of fault (integer) 123 @param line line number of faulty source
123 @param error error text (string) 124 @type int or str
124 @param sourcecode faulty line of code (string) 125 @param index index number of fault
125 @param isWarning flag indicating a warning message (boolean) 126 @type int
127 @param error error text
128 @type str
129 @param sourcecode faulty line of code
130 @type str
131 @param isWarning flag indicating a warning message
132 @type bool
126 """ 133 """
127 if ( 134 if (
128 self.__lastFileItem is None 135 self.__lastFileItem is None
129 or self.__lastFileItem.data(0, self.filenameRole) != filename 136 or self.__lastFileItem.data(0, self.filenameRole) != filename
130 ): 137 ):
152 159
153 def prepare(self, fileList, project): 160 def prepare(self, fileList, project):
154 """ 161 """
155 Public method to prepare the dialog with a list of filenames. 162 Public method to prepare the dialog with a list of filenames.
156 163
157 @param fileList list of filenames (list of strings) 164 @param fileList list of filenames
158 @param project reference to the project object (Project) 165 @type list of str
166 @param project reference to the project object
167 @type Project
159 """ 168 """
160 self.__fileList = fileList[:] 169 self.__fileList = fileList[:]
161 self.__project = project 170 self.__project = project
162 171
163 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) 172 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True)
169 self.__data = self.__project.getData("CHECKERSPARMS", "SyntaxChecker") 178 self.__data = self.__project.getData("CHECKERSPARMS", "SyntaxChecker")
170 if self.__data is None or "ExcludeFiles" not in self.__data: 179 if self.__data is None or "ExcludeFiles" not in self.__data:
171 self.__data = {"ExcludeFiles": ""} 180 self.__data = {"ExcludeFiles": ""}
172 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) 181 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
173 182
183 def startForBrowser(self, fn):
184 """
185 Public slot to start the syntax check for the project sources browser.
186
187 @param fn file or list of files or directory to be checked
188 @type str or list of str
189 """
190 if isinstance(fn, list):
191 files = fn
192 elif os.path.isdir(fn):
193 files = []
194 for ext in self.syntaxCheckService.getExtensions():
195 files.extend(Utilities.direntries(fn, True, "*{0}".format(ext), 0))
196 else:
197 files = [fn]
198
199 if files:
200 if self.__project is None:
201 self.__project = ericApp().getObject("Project")
202
203 self.__fileList = files[:]
204
205 self.filterFrame.setVisible(True)
206
207 self.__data = self.__project.getData("CHECKERSPARMS", "SyntaxChecker")
208 if self.__data is None or "ExcludeFiles" not in self.__data:
209 self.__data = {"ExcludeFiles": ""}
210 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"])
211
212 self.on_startButton_clicked() # press the start button
213
174 def start(self, fn, codestring=""): 214 def start(self, fn, codestring=""):
175 """ 215 """
176 Public slot to start the syntax check. 216 Public slot to start the syntax check.
177 217
178 @param fn file or list of files or directory to be checked 218 @param fn file or list of files or directory to be checked
179 (string or list of strings) 219 @type str or list of str
180 @param codestring string containing the code to be checked (string). 220 @param codestring string containing the code to be checked. If this is given,
181 If this is given, fn must be a single file name. 221 fn must be a single file name.
222 @type str
182 """ 223 """
183 self.__batch = False 224 self.__batch = False
184 225
185 if self.syntaxCheckService is not None: 226 if self.syntaxCheckService is not None:
186 if self.__project is None: 227 if self.__project is None:
234 """ 275 """
235 Public method to start a check for one file. 276 Public method to start a check for one file.
236 277
237 The results are reported to the __processResult slot. 278 The results are reported to the __processResult slot.
238 279
239 @param codestring optional sourcestring (str) 280 @param codestring optional sourcestring
281 @type str
240 """ 282 """
241 if self.syntaxCheckService is None or not self.files: 283 if self.syntaxCheckService is None or not self.files:
242 self.checkProgress.setMaximum(1) 284 self.checkProgress.setMaximum(1)
243 self.checkProgress.setValue(1) 285 self.checkProgress.setValue(1)
244 self.__finish() 286 self.__finish()
339 381
340 def __processResult(self, fn, problems): 382 def __processResult(self, fn, problems):
341 """ 383 """
342 Private slot to display the reported messages. 384 Private slot to display the reported messages.
343 385
344 @param fn filename of the checked file (str) 386 @param fn filename of the checked file
387 @type str
345 @param problems dictionary with the keys 'error' and 'warnings' which 388 @param problems dictionary with the keys 'error' and 'warnings' which
346 hold a list containing details about the error/ warnings 389 hold a list containing details about the error/ warnings
347 (file name, line number, column, codestring (only at syntax 390 (file name, line number, column, codestring (only at syntax
348 errors), the message) (dict) 391 errors), the message)
392 @type dict
349 """ 393 """
350 if self.__finished: 394 if self.__finished:
351 return 395 return
352 396
353 # Check if it's the requested file, otherwise ignore signal if not 397 # Check if it's the requested file, otherwise ignore signal if not
427 471
428 def on_buttonBox_clicked(self, button): 472 def on_buttonBox_clicked(self, button):
429 """ 473 """
430 Private slot called by a button of the button box clicked. 474 Private slot called by a button of the button box clicked.
431 475
432 @param button button that was clicked (QAbstractButton) 476 @param button button that was clicked
477 @type QAbstractButton
433 """ 478 """
434 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): 479 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
435 self.close() 480 self.close()
436 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): 481 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel):
437 if self.__batch: 482 if self.__batch:
468 513
469 def on_resultList_itemActivated(self, itm, col): 514 def on_resultList_itemActivated(self, itm, col):
470 """ 515 """
471 Private slot to handle the activation of an item. 516 Private slot to handle the activation of an item.
472 517
473 @param itm reference to the activated item (QTreeWidgetItem) 518 @param itm reference to the activated item
474 @param col column the item was activated in (integer) 519 @type QTreeWidgetItem
520 @param col column the item was activated in
521 @type int
475 """ 522 """
476 if self.noResults: 523 if self.noResults:
477 return 524 return
478 525
479 vm = ericApp().getObject("ViewManager") 526 vm = ericApp().getObject("ViewManager")
557 def __clearErrors(self, files): 604 def __clearErrors(self, files):
558 """ 605 """
559 Private method to clear all error and warning markers of 606 Private method to clear all error and warning markers of
560 open editors to be checked. 607 open editors to be checked.
561 608
562 @param files list of files to be checked (list of string) 609 @param files list of files to be checked
610 @type list of str
563 """ 611 """
564 vm = ericApp().getObject("ViewManager") 612 vm = ericApp().getObject("ViewManager")
565 openFiles = vm.getOpenFilenames() 613 openFiles = vm.getOpenFilenames()
566 for file in [f for f in openFiles if f in files]: 614 for file in [f for f in openFiles if f in files]:
567 editor = vm.getOpenEditor(file) 615 editor = vm.getOpenEditor(file)

eric ide

mercurial