--- a/eric7/DataViews/PyCoverageDialog.py Tue May 17 14:21:13 2022 +0200 +++ b/eric7/DataViews/PyCoverageDialog.py Tue May 17 17:23:07 2022 +0200 @@ -11,7 +11,7 @@ import os import time -from PyQt6.QtCore import pyqtSlot, Qt +from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt from PyQt6.QtWidgets import ( QDialog, QDialogButtonBox, QMenu, QHeaderView, QTreeWidgetItem, QApplication @@ -31,12 +31,17 @@ class PyCoverageDialog(QDialog, Ui_PyCoverageDialog): """ Class implementing a dialog to display the collected code coverage data. + + @signal openFile(str) emitted to open the given file in an editor """ + openFile = pyqtSignal(str) + def __init__(self, parent=None): """ Constructor - @param parent parent widget (QWidget) + @param parent parent widget + @type QWidget """ super().__init__(parent) self.setupUi(self) @@ -80,7 +85,9 @@ groups. @param lines list of integers + @type list of int @return string representing the list + @rtype str """ pairs = [] lines.sort() @@ -110,6 +117,9 @@ pair. @param pair pair of integers + @type tuple of (int, int + @return representation of the pair + @rtype str """ start, end = pair if start == end: @@ -124,12 +134,18 @@ """ Private method to create an entry in the result list. - @param file filename of file (string) - @param statements amount of statements (integer) - @param executed amount of executed statements (integer) - @param coverage percent of coverage (integer) - @param excluded list of excluded lines (string) - @param missing list of lines without coverage (string) + @param file filename of file + @type str + @param statements number of statements + @type int + @param executed number of executed statements + @type int + @param coverage percent of coverage + @type int + @param excluded list of excluded lines + @type str + @param missing list of lines without coverage + @type str """ itm = QTreeWidgetItem(self.resultList, [ file, @@ -146,14 +162,15 @@ font.setBold(True) for col in range(itm.columnCount()): itm.setFont(col, font) - + def start(self, cfn, fn): """ Public slot to start the coverage data evaluation. - @param cfn basename of the coverage file (string) + @param cfn basename of the coverage file + @type str @param fn file or list of files or directory to be checked - (string or list of strings) + @type str or list of str """ self.__cfn = cfn self.__fn = fn @@ -251,7 +268,7 @@ total_exceptions)) self.__finish() - + def __finish(self): """ Private slot called when the action finished or the user pressed the @@ -271,12 +288,13 @@ self.summaryList.header().resizeSections( QHeaderView.ResizeMode.ResizeToContents) self.summaryList.header().setStretchLastSection(True) - + def on_buttonBox_clicked(self, button): """ Private slot called by a button of the button box clicked. - @param button button that was clicked (QAbstractButton) + @param button button that was clicked + @type QAbstractButton """ if button == self.buttonBox.button( QDialogButtonBox.StandardButton.Close @@ -286,12 +304,13 @@ QDialogButtonBox.StandardButton.Cancel ): self.__finish() - + def __showContextMenu(self, coord): """ Private slot to show the context menu of the listview. - @param coord the position of the mouse pointer (QPoint) + @param coord position of the mouse pointer + @type QPoint """ itm = self.resultList.itemAt(coord) if itm: @@ -301,27 +320,32 @@ self.annotate.setEnabled(False) self.openAct.setEnabled(False) self.__menu.popup(self.mapToGlobal(coord)) - + def __openFile(self, itm=None): """ Private slot to open the selected file. - @param itm reference to the item to be opened (QTreeWidgetItem) + @param itm reference to the item to be opened + @type QTreeWidgetItem """ if itm is None: itm = self.resultList.currentItem() fn = itm.text(0) - vm = ericApp().getObject("ViewManager") - vm.openSourceFile(fn) - editor = vm.getOpenEditor(fn) - editor.codeCoverageShowAnnotations() - + try: + vm = ericApp().getObject("ViewManager") + vm.openSourceFile(fn) + editor = vm.getOpenEditor(fn) + editor.codeCoverageShowAnnotations(coverageFile=self.cfn) + except KeyError: + self.openFile.emit(fn) + + # TODO: Coverage.annotate is deprecated def __annotate(self): """ Private slot to handle the annotate context menu action. - This method produce an annotated coverage file of the + This method produces an annotated coverage file of the selected file. """ itm = self.resultList.currentItem() @@ -331,7 +355,8 @@ cover.exclude(self.excludeList[0]) cover.load() cover.annotate([fn], None, True) - + + # TODO: Coverage.annotate is deprecated def __annotateAll(self): """ Private slot to handle the annotate all context menu action. @@ -367,7 +392,7 @@ cover.annotate([file], None) # , True) progress.setValue(len(files)) - + def __erase(self): """ Private slot to handle the erase context menu action. @@ -382,7 +407,7 @@ self.reloadButton.setEnabled(False) self.resultList.clear() self.summaryList.clear() - + def __deleteAnnotated(self): """ Private slot to handle the delete annotated context menu action. @@ -394,7 +419,7 @@ for file in files: with contextlib.suppress(OSError): os.remove(file) - + @pyqtSlot() def on_reloadButton_clicked(self): """