91 """ |
91 """ |
92 self.resultList.sortItems(self.resultList.sortColumn(), |
92 self.resultList.sortItems(self.resultList.sortColumn(), |
93 self.resultList.header().sortIndicatorOrder() |
93 self.resultList.header().sortIndicatorOrder() |
94 ) |
94 ) |
95 |
95 |
96 def __createResultItem(self, file, line, pos, message): |
96 def __createResultItem(self, file, line, pos, message, fixed): |
97 """ |
97 """ |
98 Private method to create an entry in the result list. |
98 Private method to create an entry in the result list. |
99 |
99 |
100 @param file file name of the file (string) |
100 @param file file name of the file (string) |
101 @param line line number of issue (integer or string) |
101 @param line line number of issue (integer or string) |
102 @param pos character position of issue (integer or string) |
102 @param pos character position of issue (integer or string) |
103 @param message message text (string) |
103 @param message message text (string) |
|
104 @param fixed flag indicating a fixed issue (boolean) |
104 """ |
105 """ |
105 if self.__lastFileItem is None: |
106 if self.__lastFileItem is None: |
106 # It's a new file |
107 # It's a new file |
107 self.__lastFileItem = QTreeWidgetItem(self.resultList, [file]) |
108 self.__lastFileItem = QTreeWidgetItem(self.resultList, [file]) |
108 self.__lastFileItem.setFirstColumnSpanned(True) |
109 self.__lastFileItem.setFirstColumnSpanned(True) |
114 ["{0:6}".format(line), code, message]) |
115 ["{0:6}".format(line), code, message]) |
115 if code.startswith("W"): |
116 if code.startswith("W"): |
116 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png")) |
117 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png")) |
117 else: |
118 else: |
118 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) |
119 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) |
|
120 if fixed: |
|
121 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png")) |
|
122 elif code in Pep8FixableIssues: |
|
123 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable.png")) |
119 |
124 |
120 itm.setTextAlignment(0, Qt.AlignRight) |
125 itm.setTextAlignment(0, Qt.AlignRight) |
121 itm.setTextAlignment(1, Qt.AlignHCenter) |
126 itm.setTextAlignment(1, Qt.AlignHCenter) |
|
127 |
|
128 itm.setTextAlignment(0, Qt.AlignVCenter) |
|
129 itm.setTextAlignment(1, Qt.AlignVCenter) |
|
130 itm.setTextAlignment(2, Qt.AlignVCenter) |
122 |
131 |
123 itm.setData(0, self.filenameRole, file) |
132 itm.setData(0, self.filenameRole, file) |
124 itm.setData(0, self.lineRole, int(line)) |
133 itm.setData(0, self.lineRole, int(line)) |
125 itm.setData(0, self.positionRole, int(pos)) |
134 itm.setData(0, self.positionRole, int(pos)) |
126 itm.setData(0, self.messageRole, message) |
135 itm.setData(0, self.messageRole, message) |
127 |
136 |
128 def __updateStatistics(self, statistics): |
137 def __updateStatistics(self, statistics, fixer): |
129 """ |
138 """ |
130 Private method to update the collected statistics. |
139 Private method to update the collected statistics. |
131 |
140 |
132 @param statistics dictionary of statistical data with |
141 @param statistics dictionary of statistical data with |
133 message code as key and message count as value |
142 message code as key and message count as value |
|
143 @param fixer reference to the PEP 8 fixer (Pep8Fixer) |
134 """ |
144 """ |
135 self.__statistics["_FilesCount"] += 1 |
145 self.__statistics["_FilesCount"] += 1 |
136 if statistics: |
146 if statistics: |
137 self.__statistics["_FilesIssues"] += 1 |
147 self.__statistics["_FilesIssues"] += 1 |
138 for key in statistics: |
148 for key in statistics: |
139 if key in self.__statistics: |
149 if key in self.__statistics: |
140 self.__statistics[key] += statistics[key] |
150 self.__statistics[key] += statistics[key] |
141 else: |
151 else: |
142 self.__statistics[key] = statistics[key] |
152 self.__statistics[key] = statistics[key] |
|
153 if fixer: |
|
154 self.__statistics["_IssuesFixed"] += fixer.fixed |
143 |
155 |
144 def __resetStatistics(self): |
156 def __resetStatistics(self): |
145 """ |
157 """ |
146 Private slot to reset the statistics data. |
158 Private slot to reset the statistics data. |
147 """ |
159 """ |
148 self.__statistics = {} |
160 self.__statistics = {} |
149 self.__statistics["_FilesCount"] = 0 |
161 self.__statistics["_FilesCount"] = 0 |
150 self.__statistics["_FilesIssues"] = 0 |
162 self.__statistics["_FilesIssues"] = 0 |
|
163 self.__statistics["_IssuesFixed"] = 0 |
151 |
164 |
152 def prepare(self, fileList, project): |
165 def prepare(self, fileList, project): |
153 """ |
166 """ |
154 Public method to prepare the dialog with a list of filenames. |
167 Public method to prepare the dialog with a list of filenames. |
155 |
168 |
269 source = source.splitlines(True) |
282 source = source.splitlines(True) |
270 except (UnicodeError, IOError) as msg: |
283 except (UnicodeError, IOError) as msg: |
271 self.noResults = False |
284 self.noResults = False |
272 self.__createResultItem(file, "1", "1", |
285 self.__createResultItem(file, "1", "1", |
273 self.trUtf8("Error: {0}").format(str(msg))\ |
286 self.trUtf8("Error: {0}").format(str(msg))\ |
274 .rstrip()[1:-1]) |
287 .rstrip()[1:-1], False) |
275 progress += 1 |
288 progress += 1 |
276 continue |
289 continue |
277 |
290 |
278 flags = Utilities.extractFlags(source) |
291 flags = Utilities.extractFlags(source) |
279 ext = os.path.splitext(file)[1] |
292 ext = os.path.splitext(file)[1] |
305 for message in checker.messages: |
318 for message in checker.messages: |
306 fname, lineno, position, text = message |
319 fname, lineno, position, text = message |
307 if not source[lineno - 1].strip()\ |
320 if not source[lineno - 1].strip()\ |
308 .endswith("__IGNORE_WARNING__"): |
321 .endswith("__IGNORE_WARNING__"): |
309 self.noResults = False |
322 self.noResults = False |
|
323 fixed = False |
310 if fixer: |
324 if fixer: |
311 fixed, msg = fixer.fixIssue(lineno, position, text) |
325 fixed, msg = fixer.fixIssue(lineno, position, text) |
312 if fixed: |
326 if fixed: |
313 text += "\n" + \ |
327 text += "\n" + \ |
314 self.trUtf8("Fix: {0}").format(msg) |
328 self.trUtf8("Fix: {0}").format(msg) |
315 self.__createResultItem( |
329 self.__createResultItem( |
316 fname, lineno, position, text) |
330 fname, lineno, position, text, fixed) |
317 fixer and fixer.saveFile(encoding) |
331 fixer and fixer.saveFile(encoding) |
318 self.__updateStatistics(checker.statistics) |
332 self.__updateStatistics(checker.statistics, fixer) |
319 progress += 1 |
333 progress += 1 |
320 self.checkProgress.setValue(progress) |
334 self.checkProgress.setValue(progress) |
321 QApplication.processEvents() |
335 QApplication.processEvents() |
322 self.__resort() |
336 self.__resort() |
323 else: |
337 else: |