Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py

changeset 4503
d68dcbe1deb3
parent 4501
3224f20d8eb0
child 4631
5c1a96925da4
equal deleted inserted replaced
4502:76f2b46437a6 4503:d68dcbe1deb3
31 31
32 class TabnannyDialog(QDialog, Ui_TabnannyDialog): 32 class TabnannyDialog(QDialog, Ui_TabnannyDialog):
33 """ 33 """
34 Class implementing a dialog to show the results of the tabnanny check run. 34 Class implementing a dialog to show the results of the tabnanny check run.
35 """ 35 """
36 filenameRole = Qt.UserRole + 1
37
36 def __init__(self, indentCheckService, parent=None): 38 def __init__(self, indentCheckService, parent=None):
37 """ 39 """
38 Constructor 40 Constructor
39 41
40 @param indentCheckService reference to the service (IndentCheckService) 42 @param indentCheckService reference to the service (IndentCheckService)
51 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 53 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
52 54
53 self.indentCheckService = indentCheckService 55 self.indentCheckService = indentCheckService
54 self.indentCheckService.indentChecked.connect(self.__processResult) 56 self.indentCheckService.indentChecked.connect(self.__processResult)
55 self.indentCheckService.batchFinished.connect(self.__batchFinished) 57 self.indentCheckService.batchFinished.connect(self.__batchFinished)
58 self.indentCheckService.error.connect(self.__processError)
56 self.filename = None 59 self.filename = None
57 60
58 self.noResults = True 61 self.noResults = True
59 self.cancelled = False 62 self.cancelled = False
60 self.__finished = True 63 self.__finished = True
64 self.__errorItem = None
61 65
62 self.__fileList = [] 66 self.__fileList = []
63 self.__project = None 67 self.__project = None
64 self.filterFrame.setVisible(False) 68 self.filterFrame.setVisible(False)
65 69
72 Private method to resort the tree. 76 Private method to resort the tree.
73 """ 77 """
74 self.resultList.sortItems( 78 self.resultList.sortItems(
75 self.resultList.sortColumn(), 79 self.resultList.sortColumn(),
76 self.resultList.header().sortIndicatorOrder()) 80 self.resultList.header().sortIndicatorOrder())
77 81
78 def __createResultItem(self, file, line, sourcecode): 82 def __createErrorItem(self, filename, message):
83 """
84 Private slot to create a new error item in the result list.
85
86 @param filename name of the file
87 @type str
88 @param message error message
89 @type str
90 """
91 if self.__errorItem is None:
92 self.__errorItem = QTreeWidgetItem(self.resultList, [
93 self.tr("Errors")])
94 self.__errorItem.setExpanded(True)
95 self.__errorItem.setForeground(0, Qt.red)
96
97 msg = "{0} ({1})".format(self.__project.getRelativePath(filename),
98 message)
99 if not self.resultList.findItems(msg, Qt.MatchExactly):
100 itm = QTreeWidgetItem(self.__errorItem, [msg])
101 itm.setForeground(0, Qt.red)
102 itm.setFirstColumnSpanned(True)
103
104 def __createResultItem(self, filename, line, sourcecode):
79 """ 105 """
80 Private method to create an entry in the result list. 106 Private method to create an entry in the result list.
81 107
82 @param file filename of file (string) 108 @param filename filename of file (string)
83 @param line linenumber of faulty source (integer or string) 109 @param line linenumber of faulty source (integer or string)
84 @param sourcecode faulty line of code (string) 110 @param sourcecode faulty line of code (string)
85 """ 111 """
86 # TODO: create the file item relative to the project
87 itm = QTreeWidgetItem(self.resultList) 112 itm = QTreeWidgetItem(self.resultList)
88 itm.setData(0, Qt.DisplayRole, file) 113 itm.setData(0, Qt.DisplayRole,
114 self.__project.getRelativePath(filename))
89 itm.setData(1, Qt.DisplayRole, line) 115 itm.setData(1, Qt.DisplayRole, line)
90 itm.setData(2, Qt.DisplayRole, sourcecode) 116 itm.setData(2, Qt.DisplayRole, sourcecode)
91 itm.setTextAlignment(1, Qt.AlignRight) 117 itm.setTextAlignment(1, Qt.AlignRight)
118 itm.setData(0, self.filenameRole, filename)
92 119
93 def prepare(self, fileList, project): 120 def prepare(self, fileList, project):
94 """ 121 """
95 Public method to prepare the dialog with a list of filenames. 122 Public method to prepare the dialog with a list of filenames.
96 123
138 self.files.extend( 165 self.files.extend(
139 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) 166 Utilities.direntries(fn, True, '*{0}'.format(ext), 0))
140 else: 167 else:
141 self.files = [fn] 168 self.files = [fn]
142 169
170 self.__errorItem = None
171
143 if len(self.files) > 0: 172 if len(self.files) > 0:
144 self.checkProgress.setMaximum(len(self.files)) 173 self.checkProgress.setMaximum(len(self.files))
145 self.checkProgress.setVisible(len(self.files) > 1) 174 self.checkProgress.setVisible(len(self.files) > 1)
146 self.checkProgressLabel.setVisible(len(self.files) > 1) 175 self.checkProgressLabel.setVisible(len(self.files) > 1)
147 QApplication.processEvents() 176 QApplication.processEvents()
225 254
226 argumentsList.append((filename, source)) 255 argumentsList.append((filename, source))
227 256
228 # reset the progress bar to the checked files 257 # reset the progress bar to the checked files
229 self.checkProgress.setValue(self.progress) 258 self.checkProgress.setValue(self.progress)
259 self.checkProgressLabel.setPath(self.tr("Transferring data..."))
230 QApplication.processEvents() 260 QApplication.processEvents()
231 261
232 self.__finished = False 262 self.__finished = False
233 self.indentCheckService.indentBatchCheck(argumentsList) 263 self.indentCheckService.indentBatchCheck(argumentsList)
234 264
238 """ 268 """
239 self.checkProgressLabel.setPath("") 269 self.checkProgressLabel.setPath("")
240 self.checkProgress.setMaximum(1) 270 self.checkProgress.setMaximum(1)
241 self.checkProgress.setValue(1) 271 self.checkProgress.setValue(1)
242 self.__finish() 272 self.__finish()
273
274 def __processError(self, fn, msg):
275 """
276 Private slot to process an error indication from the service.
277
278 @param fn filename of the file
279 @type str
280 @param msg error message
281 @type str
282 """
283 self.__createErrorItem(fn, msg)
284
285 if not self.__batch:
286 self.check()
243 287
244 def __processResult(self, fn, nok, line, error): 288 def __processResult(self, fn, nok, line, error):
245 """ 289 """
246 Private slot called after perfoming a style check on one file. 290 Private slot called after perfoming a style check on one file.
247 291
341 @param col column the item was activated in (integer) 385 @param col column the item was activated in (integer)
342 """ 386 """
343 if self.noResults: 387 if self.noResults:
344 return 388 return
345 389
346 fn = Utilities.normabspath(itm.text(0)) 390 fn = Utilities.normabspath(itm.data(0, self.filenameRole))
347 lineno = int(itm.text(1)) 391 lineno = int(itm.text(1))
348 392
349 e5App().getObject("ViewManager").openSourceFile(fn, lineno) 393 e5App().getObject("ViewManager").openSourceFile(fn, lineno)

eric ide

mercurial