Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 4503
d68dcbe1deb3
parent 4501
3224f20d8eb0
child 4506
57666e501a42
equal deleted inserted replaced
4502:76f2b46437a6 4503:d68dcbe1deb3
85 self.checkProgressLabel.setMaximumWidth(600) 85 self.checkProgressLabel.setMaximumWidth(600)
86 86
87 self.styleCheckService = styleCheckService 87 self.styleCheckService = styleCheckService
88 self.styleCheckService.styleChecked.connect(self.__processResult) 88 self.styleCheckService.styleChecked.connect(self.__processResult)
89 self.styleCheckService.batchFinished.connect(self.__batchFinished) 89 self.styleCheckService.batchFinished.connect(self.__batchFinished)
90 self.styleCheckService.error.connect(self.__processError)
90 self.filename = None 91 self.filename = None
91 92
92 self.noResults = True 93 self.noResults = True
93 self.cancelled = False 94 self.cancelled = False
94 self.__lastFileItem = None 95 self.__lastFileItem = None
95 self.__finished = True 96 self.__finished = True
97 self.__errorItem = None
96 98
97 self.__fileOrFileList = "" 99 self.__fileOrFileList = ""
98 self.__project = None 100 self.__project = None
99 self.__forProject = False 101 self.__forProject = False
100 self.__data = {} 102 self.__data = {}
110 """ 112 """
111 self.resultList.sortItems(self.resultList.sortColumn(), 113 self.resultList.sortItems(self.resultList.sortColumn(),
112 self.resultList.header().sortIndicatorOrder() 114 self.resultList.header().sortIndicatorOrder()
113 ) 115 )
114 116
115 def __createResultItem(self, file, line, pos, message, fixed, autofixing, 117 def __createErrorItem(self, filename, message):
116 ignored): 118 """
119 Private slot to create a new error item in the result list.
120
121 @param filename name of the file
122 @type str
123 @param message error message
124 @type str
125 """
126 if self.__errorItem is None:
127 self.__errorItem = QTreeWidgetItem(self.resultList, [
128 self.tr("Errors")])
129 self.__errorItem.setExpanded(True)
130 self.__errorItem.setForeground(0, Qt.red)
131
132 msg = "{0} ({1})".format(self.__project.getRelativePath(filename),
133 message)
134 if not self.resultList.findItems(msg, Qt.MatchExactly):
135 itm = QTreeWidgetItem(self.__errorItem, [msg])
136 itm.setForeground(0, Qt.red)
137 itm.setFirstColumnSpanned(True)
138
139 def __createResultItem(self, filename, line, pos, message, fixed,
140 autofixing, ignored):
117 """ 141 """
118 Private method to create an entry in the result list. 142 Private method to create an entry in the result list.
119 143
120 @param file file name of the file (string) 144 @param filename file name of the file (string)
121 @param line line number of issue (integer or string) 145 @param line line number of issue (integer or string)
122 @param pos character position of issue (integer or string) 146 @param pos character position of issue (integer or string)
123 @param message message text (string) 147 @param message message text (string)
124 @param fixed flag indicating a fixed issue (boolean) 148 @param fixed flag indicating a fixed issue (boolean)
125 @param autofixing flag indicating, that we are fixing issues 149 @param autofixing flag indicating, that we are fixing issues
129 """ 153 """
130 from .CodeStyleFixer import FixableCodeStyleIssues 154 from .CodeStyleFixer import FixableCodeStyleIssues
131 155
132 if self.__lastFileItem is None: 156 if self.__lastFileItem is None:
133 # It's a new file 157 # It's a new file
134 # TODO: create the file item relative to the project 158 self.__lastFileItem = QTreeWidgetItem(self.resultList, [
135 self.__lastFileItem = QTreeWidgetItem(self.resultList, [file]) 159 self.__project.getRelativePath(filename)])
136 self.__lastFileItem.setFirstColumnSpanned(True) 160 self.__lastFileItem.setFirstColumnSpanned(True)
137 self.__lastFileItem.setExpanded(True) 161 self.__lastFileItem.setExpanded(True)
138 self.__lastFileItem.setData(0, self.filenameRole, file) 162 self.__lastFileItem.setData(0, self.filenameRole, filename)
139 163
140 fixable = False 164 fixable = False
141 code, message = message.split(None, 1) 165 code, message = message.split(None, 1)
142 itm = QTreeWidgetItem( 166 itm = QTreeWidgetItem(
143 self.__lastFileItem, 167 self.__lastFileItem,
162 186
163 itm.setTextAlignment(0, Qt.AlignVCenter) 187 itm.setTextAlignment(0, Qt.AlignVCenter)
164 itm.setTextAlignment(1, Qt.AlignVCenter) 188 itm.setTextAlignment(1, Qt.AlignVCenter)
165 itm.setTextAlignment(2, Qt.AlignVCenter) 189 itm.setTextAlignment(2, Qt.AlignVCenter)
166 190
167 itm.setData(0, self.filenameRole, file) 191 itm.setData(0, self.filenameRole, filename)
168 itm.setData(0, self.lineRole, int(line)) 192 itm.setData(0, self.lineRole, int(line))
169 itm.setData(0, self.positionRole, int(pos)) 193 itm.setData(0, self.positionRole, int(pos))
170 itm.setData(0, self.messageRole, message) 194 itm.setData(0, self.messageRole, message)
171 itm.setData(0, self.fixableRole, fixable) 195 itm.setData(0, self.fixableRole, fixable)
172 itm.setData(0, self.codeRole, code) 196 itm.setData(0, self.codeRole, code)
342 for filter in filterList: 366 for filter in filterList:
343 self.files = \ 367 self.files = \
344 [f for f in self.files 368 [f for f in self.files
345 if not fnmatch.fnmatch(f, filter.strip())] 369 if not fnmatch.fnmatch(f, filter.strip())]
346 370
371 self.__errorItem = None
347 self.__resetStatistics() 372 self.__resetStatistics()
348 self.__clearErrors(self.files) 373 self.__clearErrors(self.files)
349 374
350 if len(self.files) > 0: 375 if len(self.files) > 0:
351 self.checkProgress.setMaximum(len(self.files)) 376 self.checkProgress.setMaximum(len(self.files))
492 ] 517 ]
493 argumentsList.append((filename, source, args)) 518 argumentsList.append((filename, source, args))
494 519
495 # reset the progress bar to the checked files 520 # reset the progress bar to the checked files
496 self.checkProgress.setValue(self.progress) 521 self.checkProgress.setValue(self.progress)
522 self.checkProgressLabel.setPath(self.tr("Transferring data..."))
497 QApplication.processEvents() 523 QApplication.processEvents()
498 524
499 self.__finished = False 525 self.__finished = False
500 self.styleCheckService.styleBatchCheck(argumentsList) 526 self.styleCheckService.styleBatchCheck(argumentsList)
501 527
505 """ 531 """
506 self.checkProgressLabel.setPath("") 532 self.checkProgressLabel.setPath("")
507 self.checkProgress.setMaximum(1) 533 self.checkProgress.setMaximum(1)
508 self.checkProgress.setValue(1) 534 self.checkProgress.setValue(1)
509 self.__finish() 535 self.__finish()
536
537 def __processError(self, fn, msg):
538 """
539 Private slot to process an error indication from the service.
540
541 @param fn filename of the file
542 @type str
543 @param msg error message
544 @type str
545 """
546 self.__createErrorItem(fn, msg)
547
548 if not self.__batch:
549 self.check()
510 550
511 def __processResult(self, fn, codeStyleCheckerStats, fixes, results): 551 def __processResult(self, fn, codeStyleCheckerStats, fixes, results):
512 """ 552 """
513 Private slot called after perfoming a style check on one file. 553 Private slot called after perfoming a style check on one file.
514 554

eric ide

mercurial