Wed, 16 Sep 2015 20:07:48 +0200
Continued implementing the maintainability index stuff.
--- a/PluginMetricsRadon.e4p Wed Sep 16 20:07:28 2015 +0200 +++ b/PluginMetricsRadon.e4p Wed Sep 16 20:07:48 2015 +0200 @@ -16,6 +16,7 @@ <Sources> <Source>PluginMetricsRadon.py</Source> <Source>RadonMetrics/CodeMetricsCalculator.py</Source> + <Source>RadonMetrics/MaintainabilityIndexDialog.py</Source> <Source>RadonMetrics/RawMetricsDialog.py</Source> <Source>RadonMetrics/__init__.py</Source> <Source>RadonMetrics/radon/__init__.py</Source> @@ -26,6 +27,7 @@ <Source>__init__.py</Source> </Sources> <Forms> + <Form>RadonMetrics/MaintainabilityIndexDialog.ui</Form> <Form>RadonMetrics/RawMetricsDialog.ui</Form> </Forms> <Translations/>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadonMetrics/MaintainabilityIndexDialog.py Wed Sep 16 20:07:48 2015 +0200 @@ -0,0 +1,196 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to show maintainability indexes. +""" + +from __future__ import unicode_literals + +try: + str = unicode # __IGNORE_EXCEPTION __IGNORE_WARNING__ +except NameError: + pass + +import os +import fnmatch + +from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale +from PyQt5.QtWidgets import ( + QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, + QApplication +) + +from .Ui_MaintainabilityIndexDialog import Ui_MaintainabilityIndexDialog +from E5Gui.E5Application import e5App + +import Preferences +import Utilities + + +class MaintainabilityIndexDialog(QDialog, Ui_MaintainabilityIndexDialog): + """ + Class implementing a dialog to show maintainability indexes. + """ + def __init__(self, radonService, parent=None): + """ + Constructor + + @param radonService reference to the service + @type RadonMetricsPlugin + @param parent reference to the parent widget + @type QWidget + """ + super(MaintainabilityIndexDialog, self).__init__(parent) + self.setupUi(self) + self.setWindowFlags(Qt.Window) + + self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) + self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) + + self.resultList.headerItem().setText(self.resultList.columnCount(), "") + + self.radonService = radonService + self.radonService.metricsDone.connect(self.__processResult) + self.radonService.metricsError.connect(self.__processError) + self.radonService.batchFinished.connect(self.__batchFinished) + + self.cancelled = False + + self.__project = e5App().getObject("Project") + self.__locale = QLocale() + + self.__fileList = [] + self.filterFrame.setVisible(False) + + self.explanationLabel.setText(self.tr( + "<table>" + "<tr><td colspan=2><b>Ranking:</b></td></tr>" + "<tr><td><b>A</b></td><td>score > 19</td></tr>" + "<tr><td><b>B</b></td><td>9 < score ≤ 19</td></tr>" + "<tr><td><b>C</b></td><td>score ≤ 9</td></tr>" + "</table>" + )) + + def __resizeResultColumns(self): + """ + Private method to resize the list columns. + """ + self.resultList.header().resizeSections(QHeaderView.ResizeToContents) + self.resultList.header().setStretchLastSection(True) + + def __createResultItem(self, filename, values): + """ + Private slot to create a new item in the result list. + + @param filename name of the file + @type str + @param values values to be displayed + @type dict + """ + data = [self.__project.getRelativePath(filename)] + try: + data.append(self.__locale.toString(float(values["mi"]), "f", 2)) + except ValueError: + data.append(values["mi"]) + data.append(values["rank"]) + itm = QTreeWidgetItem(self.resultList, data) + itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) + itm.setTextAlignment(2, Qt.Alignment(Qt.AlignHCenter)) + + def __createErrorItem(self, filename, message): + """ + Private slot to create a new error item in the result list. + + @param filename name of the file + @type str + @param message error message + @type str + """ + itm = QTreeWidgetItem(self.resultList, [ + "{0} ({1})".format(self.__project.getRelativePath(filename), + message)]) + itm.setFirstColumnSpanned(True) + font = itm.font(0) + font.setItalic(True) + itm.setFont(0, font) + + def prepare(self, fileList, project): + """ + Public method to prepare the dialog with a list of filenames. + + @param fileList list of filenames + @type list of str + @param project reference to the project object + @type Project + """ + self.__fileList = fileList[:] + self.__project = project + + self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) + self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) + self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) + + self.filterFrame.setVisible(True) + + self.__data = self.__project.getData( + "OTHERTOOLSPARMS", "RadonCodeMetrics") + if self.__data is None or "ExcludeFiles" not in self.__data: + self.__data = {"ExcludeFiles": ""} + self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) + + def start(self, fn): + """ + Public slot to start the maintainability index determination. + + @param fn file or list of files or directory to show + the maintainability index for + @type str or list of str + """ + self.cancelled = False + self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) + self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) + self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) + QApplication.processEvents() + + if isinstance(fn, list): + self.files = fn + elif os.path.isdir(fn): + self.files = [] + extensions = set(Preferences.getPython("PythonExtensions") + + Preferences.getPython("Python3Extensions")) + for ext in extensions: + self.files.extend( + Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) + else: + self.files = [fn] + self.files.sort() + # check for missing files + for f in self.files[:]: + if not os.path.exists(f): + self.files.remove(f) + + self.__summary = {"files": 0} + for key in ['loc', 'sloc', 'lloc', 'comments', 'multi', 'blank']: + self.__summary[key] = 0 + + if len(self.files) > 0: + # disable updates of the list for speed + self.resultList.setUpdatesEnabled(False) + self.resultList.setSortingEnabled(False) + + self.checkProgress.setMaximum(len(self.files)) + self.checkProgress.setVisible(len(self.files) > 1) + self.checkProgressLabel.setVisible(len(self.files) > 1) + QApplication.processEvents() + + # now go through all the files + self.progress = 0 + if len(self.files) == 1 or not self.radonService.hasBatch: + self.__batch = False + self.maintainabilityIndex() + else: + self.__batch = True + self.maintainabilityIndexBatch()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadonMetrics/MaintainabilityIndexDialog.ui Wed Sep 16 20:07:48 2015 +0200 @@ -0,0 +1,177 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MaintainabilityIndexDialog</class> + <widget class="QDialog" name="MaintainabilityIndexDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>832</width> + <height>587</height> + </rect> + </property> + <property name="windowTitle"> + <string>Maintainability Index</string> + </property> + <property name="whatsThis"> + <string><b>Maintainability Index</b> +<p>This dialog shows the mintainability index and rank.</p></string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QFrame" name="filterFrame"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Exclude Files:</string> + </property> + </widget> + </item> + <item> + <widget class="E5ClearableLineEdit" name="excludeFilesEdit"> + <property name="toolTip"> + <string>Enter filename patterns of files to be excluded separated by a comma</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="lineWidth"> + <number>2</number> + </property> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="startButton"> + <property name="toolTip"> + <string>Press to start the code metrics run</string> + </property> + <property name="text"> + <string>Start</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QTreeWidget" name="resultList"> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <column> + <property name="text"> + <string>Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Score</string> + </property> + </column> + <column> + <property name="text"> + <string>Rank</string> + </property> + </column> + </widget> + </item> + <item> + <widget class="QLabel" name="explanationLabel"> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="E5SqueezeLabelPath" name="checkProgressLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QProgressBar" name="checkProgress"> + <property name="toolTip"> + <string>Shows the progress of the code metrics action</string> + </property> + <property name="value"> + <number>0</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="format"> + <string>%v/%m Files</string> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Close</set> + </property> + </widget> + </item> + </layout> + </widget> + <layoutdefault spacing="6" margin="6"/> + <pixmapfunction>qPixmapFromMimeSource</pixmapfunction> + <customwidgets> + <customwidget> + <class>E5ClearableLineEdit</class> + <extends>QLineEdit</extends> + <header>E5Gui/E5LineEdit.h</header> + </customwidget> + <customwidget> + <class>E5SqueezeLabelPath</class> + <extends>QLabel</extends> + <header>E5Gui/E5SqueezeLabels.h</header> + </customwidget> + </customwidgets> + <tabstops> + <tabstop>startButton</tabstop> + <tabstop>excludeFilesEdit</tabstop> + <tabstop>resultList</tabstop> + <tabstop>buttonBox</tabstop> + </tabstops> + <resources/> + <connections/> +</ui>