PyLint/PyLintExecDialog.py

changeset 28
1dae294006e8
parent 24
b01348dd84d5
child 30
de4b620a6e88
equal deleted inserted replaced
27:ff4bcced7a34 28:1dae294006e8
52 self.trUtf8("Press to save the report to a file")) 52 self.trUtf8("Press to save the report to a file"))
53 self.saveButton.setEnabled(False) 53 self.saveButton.setEnabled(False)
54 54
55 self.refreshButton = self.buttonBox.addButton( 55 self.refreshButton = self.buttonBox.addButton(
56 self.trUtf8("Refresh"), QDialogButtonBox.ActionRole) 56 self.trUtf8("Refresh"), QDialogButtonBox.ActionRole)
57 self.refreshButton.setToolTip(self.trUtf8("Press to refresh the result display")) 57 self.refreshButton.setToolTip(self.trUtf8(
58 "Press to refresh the result display"))
58 self.refreshButton.setEnabled(False) 59 self.refreshButton.setEnabled(False)
59 60
60 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 61 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
61 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 62 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
62 63
119 120
120 self.__ioEncoding = Preferences.getSystem("IOEncoding") 121 self.__ioEncoding = Preferences.getSystem("IOEncoding")
121 if "--output-format=parseable" in args: 122 if "--output-format=parseable" in args:
122 self.reportFile = None 123 self.reportFile = None
123 self.contents.hide() 124 self.contents.hide()
124 self.process.readyReadStandardOutput.connect(self.__readParseStdout) 125 self.process.readyReadStandardOutput.connect(
126 self.__readParseStdout)
125 self.parsedOutput = True 127 self.parsedOutput = True
126 else: 128 else:
127 self.process.readyReadStandardOutput.connect(self.__readStdout) 129 self.process.readyReadStandardOutput.connect(self.__readStdout)
128 self.messageList.hide() 130 self.messageList.hide()
129 if "--output-format=html" in args: 131 if "--output-format=html" in args:
142 self.__lastFileItem = None 144 self.__lastFileItem = None
143 145
144 self.process.start(program, args) 146 self.process.start(program, args)
145 procStarted = self.process.waitForStarted() 147 procStarted = self.process.waitForStarted()
146 if not procStarted: 148 if not procStarted:
147 E5MessageBox.critical(None, 149 E5MessageBox.critical(
150 self,
148 self.trUtf8('Process Generation Error'), 151 self.trUtf8('Process Generation Error'),
149 self.trUtf8( 152 self.trUtf8(
150 'The process {0} could not be started. ' 153 'The process {0} could not be started. '
151 'Ensure, that it is in the search path.' 154 'Ensure, that it is in the search path.'
152 ).format(program)) 155 ).format(program))
195 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 198 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
196 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 199 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
197 self.refreshButton.setEnabled(True) 200 self.refreshButton.setEnabled(True)
198 if self.parsedOutput: 201 if self.parsedOutput:
199 QApplication.processEvents() 202 QApplication.processEvents()
200 self.messageList.sortItems(self.messageList.sortColumn(), 203 self.messageList.sortItems(
201 self.messageList.header().sortIndicatorOrder()) 204 self.messageList.sortColumn(),
202 self.messageList.header().resizeSections(QHeaderView.ResizeToContents) 205 self.messageList.header().sortIndicatorOrder())
206 self.messageList.header().resizeSections(
207 QHeaderView.ResizeToContents)
203 self.messageList.header().setStretchLastSection(True) 208 self.messageList.header().setStretchLastSection(True)
204 else: 209 else:
205 if self.__scrollPosition != -1: 210 if self.__scrollPosition != -1:
206 self.contents.verticalScrollBar().setValue(self.__scrollPosition) 211 self.contents.verticalScrollBar().setValue(
212 self.__scrollPosition)
207 213
208 self.process = None 214 self.process = None
209 215
210 if self.reportFile: 216 if self.reportFile:
211 self.__writeReport() 217 self.__writeReport()
212 elif not self.parsedOutput: 218 elif not self.parsedOutput:
213 self.saveButton.setEnabled(True) 219 self.saveButton.setEnabled(True)
214 220
215 if self.noResults: 221 if self.noResults:
216 self.__createItem(self.trUtf8('No PyLint errors found.'), "", "", "") 222 self.__createItem(
223 self.trUtf8('No PyLint errors found.'), "", "", "")
217 224
218 @pyqtSlot() 225 @pyqtSlot()
219 def on_refreshButton_clicked(self): 226 def on_refreshButton_clicked(self):
220 """ 227 """
221 Private slot to refresh the status display. 228 Private slot to refresh the status display.
268 itm.setTextAlignment(1, Qt.AlignHCenter) 275 itm.setTextAlignment(1, Qt.AlignHCenter)
269 itm.setData(0, self.filenameRole, file) 276 itm.setData(0, self.filenameRole, file)
270 277
271 def __readParseStdout(self): 278 def __readParseStdout(self):
272 """ 279 """
273 Private slot to handle the readyReadStandardOutput signal for parseable output. 280 Private slot to handle the readyReadStandardOutput signal for
281 parseable output.
274 282
275 It reads the output of the process, formats it and inserts it into 283 It reads the output of the process, formats it and inserts it into
276 the message list pane. 284 the message list pane.
277 """ 285 """
278 self.process.setReadChannel(QProcess.StandardOutput) 286 self.process.setReadChannel(QProcess.StandardOutput)
290 type_, message = fullmessage.strip().split(']', 1) 298 type_, message = fullmessage.strip().split(']', 1)
291 type_ = type_.strip()[1:].split(',', 1)[0] 299 type_ = type_.strip()[1:].split(',', 1)[0]
292 message = message.strip() 300 message = message.strip()
293 if type_ and type_[0] in self.typeDict: 301 if type_ and type_[0] in self.typeDict:
294 if len(type_) == 1: 302 if len(type_) == 1:
295 self.__createItem(fname, lineno, 303 self.__createItem(
296 self.typeDict[type_], message) 304 fname, lineno, self.typeDict[type_], message)
297 else: 305 else:
298 self.__createItem(fname, lineno, 306 self.__createItem(
299 "{0} {1}".format( 307 fname, lineno, "{0} {1}".format(
300 self.typeDict[type_[0]], type_[1:]), 308 self.typeDict[type_[0]], type_[1:]),
301 message) 309 message)
302 self.noResults = False 310 self.noResults = False
303 except ValueError: 311 except ValueError:
304 continue 312 continue
305 313
306 def __readStderr(self): 314 def __readStderr(self):
333 lineno = int(itm.text(0)) 341 lineno = int(itm.text(0))
334 342
335 vm = e5App().getObject("ViewManager") 343 vm = e5App().getObject("ViewManager")
336 vm.openSourceFile(fn, lineno) 344 vm.openSourceFile(fn, lineno)
337 editor = vm.getOpenEditor(fn) 345 editor = vm.getOpenEditor(fn)
338 editor.toggleFlakesWarning(lineno, True, 346 editor.toggleFlakesWarning(
347 lineno, True,
339 "{0} | {1}".format(itm.text(1), itm.text(2))) 348 "{0} | {1}".format(itm.text(1), itm.text(2)))
340 else: 349 else:
341 fn = os.path.join(self.pathname, itm.data(0, self.filenameRole)) 350 fn = os.path.join(self.pathname, itm.data(0, self.filenameRole))
342 vm = e5App().getObject("ViewManager") 351 vm = e5App().getObject("ViewManager")
343 vm.openSourceFile(fn) 352 vm.openSourceFile(fn)
344 editor = vm.getOpenEditor(fn) 353 editor = vm.getOpenEditor(fn)
345 for index in range(itm.childCount()): 354 for index in range(itm.childCount()):
346 citm = itm.child(index) 355 citm = itm.child(index)
347 lineno = int(citm.text(0)) 356 lineno = int(citm.text(0))
348 editor.toggleFlakesWarning(lineno, True, 357 editor.toggleFlakesWarning(
358 lineno, True,
349 "{0} | {1}".format(citm.text(1), citm.text(2))) 359 "{0} | {1}".format(citm.text(1), citm.text(2)))
350 360
351 def __writeReport(self): 361 def __writeReport(self):
352 """ 362 """
353 Private slot to write the report to a report file. 363 Private slot to write the report to a report file.
354 """ 364 """
355 self.reportFile = self.reportFile 365 self.reportFile = self.reportFile
356 if os.path.exists(self.reportFile): 366 if os.path.exists(self.reportFile):
357 res = E5MessageBox.warning(self, 367 res = E5MessageBox.warning(
368 self,
358 self.trUtf8("PyLint Report"), 369 self.trUtf8("PyLint Report"),
359 self.trUtf8( 370 self.trUtf8(
360 """<p>The PyLint report file <b>{0}</b> already exists.</p>""")\ 371 """<p>The PyLint report file <b>{0}</b> already"""
361 .format(self.reportFile), 372 """ exists.</p>""")
373 .format(self.reportFile),
362 E5MessageBox.StandardButtons( 374 E5MessageBox.StandardButtons(
363 E5MessageBox.Cancel | \ 375 E5MessageBox.Cancel |
364 E5MessageBox.Ignore), 376 E5MessageBox.Ignore),
365 E5MessageBox.Cancel) 377 E5MessageBox.Cancel)
366 if res == E5MessageBox.Cancel: 378 if res == E5MessageBox.Cancel:
367 return 379 return
368 380
371 f = open(self.reportFile, 'wb') 383 f = open(self.reportFile, 'wb')
372 f.write(codecs.BOM_UTF8) 384 f.write(codecs.BOM_UTF8)
373 f.write(self.buf.encode('utf-8')) 385 f.write(self.buf.encode('utf-8'))
374 f.close() 386 f.close()
375 except IOError as why: 387 except IOError as why:
376 E5MessageBox.critical(self, self.trUtf8('PyLint Report'), 388 E5MessageBox.critical(
377 self.trUtf8('<p>The PyLint report file <b>{0}</b> could not be written.' 389 self, self.trUtf8('PyLint Report'),
378 '<br>Reason: {1}</p>') 390 self.trUtf8('<p>The PyLint report file <b>{0}</b> could not'
379 .format(self.reportFile, str(why))) 391 ' be written.<br>Reason: {1}</p>')
392 .format(self.reportFile, str(why)))
380 393
381 @pyqtSlot() 394 @pyqtSlot()
382 def on_saveButton_clicked(self): 395 def on_saveButton_clicked(self):
383 """ 396 """
384 Private slot to save the report to a file. 397 Private slot to save the report to a file.

eric ide

mercurial