13 except NameError: |
13 except NameError: |
14 pass |
14 pass |
15 |
15 |
16 import os |
16 import os |
17 |
17 |
18 from PyQt4.QtCore import QTimer, QProcess, Qt, pyqtSlot |
18 from PyQt5.QtCore import QTimer, QProcess, Qt, pyqtSlot |
19 from PyQt4.QtGui import QWidget, QCursor, QHeaderView, QApplication, \ |
19 from PyQt5.QtGui import QCursor, QTextCursor |
20 QTextCursor, QDialogButtonBox, QTreeWidgetItem |
20 from PyQt5.QtWidgets import QWidget, QHeaderView, QApplication, \ |
|
21 QDialogButtonBox, QTreeWidgetItem |
21 |
22 |
22 from E5Gui import E5MessageBox, E5FileDialog |
23 from E5Gui import E5MessageBox, E5FileDialog |
23 from E5Gui.E5Application import e5App |
24 from E5Gui.E5Application import e5App |
24 |
25 |
25 from .Ui_PyLintExecDialog import Ui_PyLintExecDialog |
26 from .Ui_PyLintExecDialog import Ui_PyLintExecDialog |
45 """ |
46 """ |
46 QWidget.__init__(self, parent) |
47 QWidget.__init__(self, parent) |
47 self.setupUi(self) |
48 self.setupUi(self) |
48 |
49 |
49 self.saveButton = self.buttonBox.addButton( |
50 self.saveButton = self.buttonBox.addButton( |
50 self.trUtf8("Save Report..."), QDialogButtonBox.ActionRole) |
51 self.tr("Save Report..."), QDialogButtonBox.ActionRole) |
51 self.saveButton.setToolTip( |
52 self.saveButton.setToolTip( |
52 self.trUtf8("Press to save the report to a file")) |
53 self.tr("Press to save the report to a file")) |
53 self.saveButton.setEnabled(False) |
54 self.saveButton.setEnabled(False) |
54 |
55 |
55 self.refreshButton = self.buttonBox.addButton( |
56 self.refreshButton = self.buttonBox.addButton( |
56 self.trUtf8("Refresh"), QDialogButtonBox.ActionRole) |
57 self.tr("Refresh"), QDialogButtonBox.ActionRole) |
57 self.refreshButton.setToolTip(self.trUtf8( |
58 self.refreshButton.setToolTip(self.tr( |
58 "Press to refresh the result display")) |
59 "Press to refresh the result display")) |
59 self.refreshButton.setEnabled(False) |
60 self.refreshButton.setEnabled(False) |
60 |
61 |
61 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
62 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
62 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
63 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
68 self.htmlOutput = False |
69 self.htmlOutput = False |
69 self.parsedOutput = False |
70 self.parsedOutput = False |
70 self.__scrollPosition = -1 # illegal value |
71 self.__scrollPosition = -1 # illegal value |
71 |
72 |
72 self.typeDict = { |
73 self.typeDict = { |
73 'C': self.trUtf8('Convention'), |
74 'C': self.tr('Convention'), |
74 'R': self.trUtf8('Refactor'), |
75 'R': self.tr('Refactor'), |
75 'W': self.trUtf8('Warning'), |
76 'W': self.tr('Warning'), |
76 'E': self.trUtf8('Error'), |
77 'E': self.tr('Error'), |
77 'F': self.trUtf8('Fatal'), |
78 'F': self.tr('Fatal'), |
78 } |
79 } |
79 |
80 |
80 def start(self, args, fn, reportFile, ppath): |
81 def start(self, args, fn, reportFile, ppath): |
81 """ |
82 """ |
82 Public slot to start PyLint. |
83 Public slot to start PyLint. |
146 self.process.start(program, args) |
147 self.process.start(program, args) |
147 procStarted = self.process.waitForStarted() |
148 procStarted = self.process.waitForStarted() |
148 if not procStarted: |
149 if not procStarted: |
149 E5MessageBox.critical( |
150 E5MessageBox.critical( |
150 self, |
151 self, |
151 self.trUtf8('Process Generation Error'), |
152 self.tr('Process Generation Error'), |
152 self.trUtf8( |
153 self.tr( |
153 'The process {0} could not be started. ' |
154 'The process {0} could not be started. ' |
154 'Ensure, that it is in the search path.' |
155 'Ensure, that it is in the search path.' |
155 ).format(program)) |
156 ).format(program)) |
156 else: |
157 else: |
157 self.setCursor(QCursor(Qt.WaitCursor)) |
158 self.setCursor(QCursor(Qt.WaitCursor)) |
218 elif not self.parsedOutput: |
219 elif not self.parsedOutput: |
219 self.saveButton.setEnabled(True) |
220 self.saveButton.setEnabled(True) |
220 |
221 |
221 if self.noResults: |
222 if self.noResults: |
222 self.__createItem( |
223 self.__createItem( |
223 self.trUtf8('No PyLint errors found.'), "", "", "") |
224 self.tr('No PyLint errors found.'), "", "", "") |
224 |
225 |
225 @pyqtSlot() |
226 @pyqtSlot() |
226 def on_refreshButton_clicked(self): |
227 def on_refreshButton_clicked(self): |
227 """ |
228 """ |
228 Private slot to refresh the status display. |
229 Private slot to refresh the status display. |
342 |
343 |
343 vm = e5App().getObject("ViewManager") |
344 vm = e5App().getObject("ViewManager") |
344 vm.openSourceFile(fn, lineno) |
345 vm.openSourceFile(fn, lineno) |
345 editor = vm.getOpenEditor(fn) |
346 editor = vm.getOpenEditor(fn) |
346 editor.toggleWarning( |
347 editor.toggleWarning( |
347 lineno, True, |
348 lineno, 0, True, |
348 "{0} | {1}".format(itm.text(1), itm.text(2))) |
349 "{0} | {1}".format(itm.text(1), itm.text(2))) |
349 else: |
350 else: |
350 fn = os.path.join(self.pathname, itm.data(0, self.filenameRole)) |
351 fn = os.path.join(self.pathname, itm.data(0, self.filenameRole)) |
351 vm = e5App().getObject("ViewManager") |
352 vm = e5App().getObject("ViewManager") |
352 vm.openSourceFile(fn) |
353 vm.openSourceFile(fn) |
353 editor = vm.getOpenEditor(fn) |
354 editor = vm.getOpenEditor(fn) |
354 for index in range(itm.childCount()): |
355 for index in range(itm.childCount()): |
355 citm = itm.child(index) |
356 citm = itm.child(index) |
356 lineno = int(citm.text(0)) |
357 lineno = int(citm.text(0)) |
357 editor.toggleWarning( |
358 editor.toggleWarning( |
358 lineno, True, |
359 lineno, 0, True, |
359 "{0} | {1}".format(citm.text(1), citm.text(2))) |
360 "{0} | {1}".format(citm.text(1), citm.text(2))) |
360 |
361 |
361 def __writeReport(self): |
362 def __writeReport(self): |
362 """ |
363 """ |
363 Private slot to write the report to a report file. |
364 Private slot to write the report to a report file. |
364 """ |
365 """ |
365 self.reportFile = self.reportFile |
366 self.reportFile = self.reportFile |
366 if os.path.exists(self.reportFile): |
367 if os.path.exists(self.reportFile): |
367 res = E5MessageBox.warning( |
368 res = E5MessageBox.warning( |
368 self, |
369 self, |
369 self.trUtf8("PyLint Report"), |
370 self.tr("PyLint Report"), |
370 self.trUtf8( |
371 self.tr( |
371 """<p>The PyLint report file <b>{0}</b> already""" |
372 """<p>The PyLint report file <b>{0}</b> already""" |
372 """ exists.</p>""") |
373 """ exists.</p>""") |
373 .format(self.reportFile), |
374 .format(self.reportFile), |
374 E5MessageBox.StandardButtons( |
375 E5MessageBox.StandardButtons( |
375 E5MessageBox.Cancel | |
376 E5MessageBox.Cancel | |
384 f.write(codecs.BOM_UTF8) |
385 f.write(codecs.BOM_UTF8) |
385 f.write(self.buf.encode('utf-8')) |
386 f.write(self.buf.encode('utf-8')) |
386 f.close() |
387 f.close() |
387 except IOError as why: |
388 except IOError as why: |
388 E5MessageBox.critical( |
389 E5MessageBox.critical( |
389 self, self.trUtf8('PyLint Report'), |
390 self, self.tr('PyLint Report'), |
390 self.trUtf8('<p>The PyLint report file <b>{0}</b> could not' |
391 self.tr('<p>The PyLint report file <b>{0}</b> could not' |
391 ' be written.<br>Reason: {1}</p>') |
392 ' be written.<br>Reason: {1}</p>') |
392 .format(self.reportFile, str(why))) |
393 .format(self.reportFile, str(why))) |
393 |
394 |
394 @pyqtSlot() |
395 @pyqtSlot() |
395 def on_saveButton_clicked(self): |
396 def on_saveButton_clicked(self): |
396 """ |
397 """ |
397 Private slot to save the report to a file. |
398 Private slot to save the report to a file. |
398 """ |
399 """ |
399 if self.htmlOutput: |
400 if self.htmlOutput: |
400 filter = self.trUtf8("HTML Files (*.html);;All Files (*)") |
401 filter = self.tr("HTML Files (*.html);;All Files (*)") |
401 else: |
402 else: |
402 filter = self.trUtf8("Text Files (*.txt);;All Files (*)") |
403 filter = self.tr("Text Files (*.txt);;All Files (*)") |
403 |
404 |
404 self.reportFile = E5FileDialog.getSaveFileName( |
405 self.reportFile = E5FileDialog.getSaveFileName( |
405 self, |
406 self, |
406 self.trUtf8("PyLint Report"), |
407 self.tr("PyLint Report"), |
407 self.ppath, |
408 self.ppath, |
408 filter, |
409 filter, |
409 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
410 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
410 if self.reportFile: |
411 if self.reportFile: |
411 self.__writeReport() |
412 self.__writeReport() |