Plugins/CheckerPlugins/Pep8/Pep8Dialog.py

changeset 940
0f5461fe69d4
parent 853
ec7dd115e26b
child 945
8cd4d08fa9f6
child 1510
e75ecf2bd9dd
equal deleted inserted replaced
939:10d3a201cd27 940:0f5461fe69d4
213 213
214 self.cancelled = False 214 self.cancelled = False
215 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 215 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
216 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 216 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
217 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 217 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
218 self.statisticsButton.setEnabled(False)
219 self.showButton.setEnabled(False)
218 if repeat is not None: 220 if repeat is not None:
219 self.repeatCheckBox.setChecked(repeat) 221 self.repeatCheckBox.setChecked(repeat)
220 QApplication.processEvents() 222 QApplication.processEvents()
221 223
222 self.__resetStatistics() 224 self.__resetStatistics()
263 includeMessages = self.includeMessagesEdit.text() 265 includeMessages = self.includeMessagesEdit.text()
264 repeatMessages = self.repeatCheckBox.isChecked() 266 repeatMessages = self.repeatCheckBox.isChecked()
265 fixCodes = self.fixIssuesEdit.text() 267 fixCodes = self.fixIssuesEdit.text()
266 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages 268 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages
267 269
268 # now go through all the files 270 try:
269 progress = 0 271 # disable updates of the list for speed
270 for file in py3files + py2files: 272 self.resultList.setUpdatesEnabled(False)
271 self.checkProgress.setValue(progress) 273 self.resultList.setSortingEnabled(False)
272 QApplication.processEvents()
273 274
274 if self.cancelled: 275 # now go through all the files
275 self.__resort() 276 progress = 0
276 return 277 for file in py3files + py2files:
277 278 self.checkProgress.setValue(progress)
278 self.__lastFileItem = None 279 QApplication.processEvents()
279 280
280 try: 281 if self.cancelled:
281 source, encoding = Utilities.readEncodedFile(file) 282 self.__resort()
282 source = source.splitlines(True) 283 return
283 except (UnicodeError, IOError) as msg: 284
284 self.noResults = False 285 self.__lastFileItem = None
285 self.__createResultItem(file, "1", "1", 286
286 self.trUtf8("Error: {0}").format(str(msg))\ 287 try:
287 .rstrip()[1:-1], False) 288 source, encoding = Utilities.readEncodedFile(file)
289 source = source.splitlines(True)
290 except (UnicodeError, IOError) as msg:
291 self.noResults = False
292 self.__createResultItem(file, "1", "1",
293 self.trUtf8("Error: {0}").format(str(msg))\
294 .rstrip()[1:-1], False)
295 progress += 1
296 continue
297
298 flags = Utilities.extractFlags(source)
299 ext = os.path.splitext(file)[1]
300 if fixIssues:
301 fixer = Pep8Fixer(self.__project, file, source,
302 fixCodes, True) # always fix in place
303 else:
304 fixer = None
305 if ("FileType" in flags and
306 flags["FileType"] in ["Python", "Python2"]) or \
307 file in py2files or \
308 (ext in [".py", ".pyw"] and \
309 Preferences.getProject("DeterminePyFromProject") and \
310 self.__project.isOpen() and \
311 self.__project.isProjectFile(file) and \
312 self.__project.getProjectLanguage() in ["Python",
313 "Python2"]):
314 checker = Pep8Py2Checker(file, [],
315 repeat = repeatMessages,
316 select = includeMessages,
317 ignore = excludeMessages)
318 else:
319 checker = Pep8Checker(file, source,
320 repeat = repeatMessages,
321 select = includeMessages,
322 ignore = excludeMessages)
323 checker.check_all()
324 checker.messages.sort(key = lambda a: a[1])
325 for message in checker.messages:
326 fname, lineno, position, text = message
327 if not source[lineno - 1].strip()\
328 .endswith("__IGNORE_WARNING__"):
329 self.noResults = False
330 fixed = False
331 if fixer:
332 fixed, msg = fixer.fixIssue(lineno, position, text)
333 if fixed:
334 text += "\n" + \
335 self.trUtf8("Fix: {0}").format(msg)
336 self.__createResultItem(
337 fname, lineno, position, text, fixed)
338 fixer and fixer.saveFile(encoding)
339 self.__updateStatistics(checker.statistics, fixer)
288 progress += 1 340 progress += 1
289 continue 341 finally:
290 342 # reenable updates of the list
291 flags = Utilities.extractFlags(source) 343 self.resultList.setSortingEnabled(True)
292 ext = os.path.splitext(file)[1] 344 self.resultList.setUpdatesEnabled(True)
293 if fixIssues:
294 fixer = Pep8Fixer(self.__project, file, source,
295 fixCodes, True) # always fix in place
296 else:
297 fixer = None
298 if ("FileType" in flags and
299 flags["FileType"] in ["Python", "Python2"]) or \
300 file in py2files or \
301 (ext in [".py", ".pyw"] and \
302 Preferences.getProject("DeterminePyFromProject") and \
303 self.__project.isOpen() and \
304 self.__project.isProjectFile(file) and \
305 self.__project.getProjectLanguage() in ["Python",
306 "Python2"]):
307 checker = Pep8Py2Checker(file, [],
308 repeat = repeatMessages,
309 select = includeMessages,
310 ignore = excludeMessages)
311 else:
312 checker = Pep8Checker(file, source,
313 repeat = repeatMessages,
314 select = includeMessages,
315 ignore = excludeMessages)
316 checker.check_all()
317 checker.messages.sort(key = lambda a: a[1])
318 for message in checker.messages:
319 fname, lineno, position, text = message
320 if not source[lineno - 1].strip()\
321 .endswith("__IGNORE_WARNING__"):
322 self.noResults = False
323 fixed = False
324 if fixer:
325 fixed, msg = fixer.fixIssue(lineno, position, text)
326 if fixed:
327 text += "\n" + \
328 self.trUtf8("Fix: {0}").format(msg)
329 self.__createResultItem(
330 fname, lineno, position, text, fixed)
331 fixer and fixer.saveFile(encoding)
332 self.__updateStatistics(checker.statistics, fixer)
333 progress += 1
334 self.checkProgress.setValue(progress) 345 self.checkProgress.setValue(progress)
335 QApplication.processEvents() 346 QApplication.processEvents()
336 self.__resort() 347 self.__resort()
337 else: 348 else:
338 self.checkProgress.setMaximum(1) 349 self.checkProgress.setMaximum(1)
346 """ 357 """
347 self.cancelled = True 358 self.cancelled = True
348 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 359 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
349 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 360 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
350 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 361 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
362 self.statisticsButton.setEnabled(True)
363 self.showButton.setEnabled(True)
351 364
352 if self.noResults: 365 if self.noResults:
353 QTreeWidgetItem(self.resultList, [self.trUtf8('No issues found.')]) 366 QTreeWidgetItem(self.resultList, [self.trUtf8('No issues found.')])
354 QApplication.processEvents() 367 QApplication.processEvents()
355 self.statisticsButton.setEnabled(False) 368 self.statisticsButton.setEnabled(False)

eric ide

mercurial