Changed the code metrics dialog to show project relative file paths if possible. eric7

Thu, 07 Jul 2022 15:02:00 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 07 Jul 2022 15:02:00 +0200
branch
eric7
changeset 9210
15743bae8a50
parent 9209
b99e7fd55fd3
child 9211
99eb1cb030a5

Changed the code metrics dialog to show project relative file paths if possible.

eric7.epj file | annotate | diff | comparison | revisions
src/eric7/DataViews/CodeMetricsDialog.py file | annotate | diff | comparison | revisions
src/eric7/Project/Project.py file | annotate | diff | comparison | revisions
--- a/eric7.epj	Thu Jul 07 11:23:56 2022 +0200
+++ b/eric7.epj	Thu Jul 07 15:02:00 2022 +0200
@@ -768,12 +768,6 @@
       "docs/eric7-plugin.odt",
       "docs/eric7-plugin.pdf",
       "eric7.epj",
-      "src/eric7/data/linux/eric7.appdata.xml",
-      "src/eric7/data/linux/eric7.appdata.xml.in",
-      "src/eric7/data/linux/eric7.desktop",
-      "src/eric7/data/linux/eric7.desktop.in",
-      "src/eric7/data/linux/eric7_browser.desktop",
-      "src/eric7/data/linux/eric7_browser.desktop.in",
       "others/default.e4k",
       "others/default.ekj",
       "others/default_Mac.e4k",
@@ -953,13 +947,19 @@
       "src/eric7/WebBrowser/data/javascript/jquery-ui.js",
       "src/eric7/WebBrowser/data/javascript/jquery.js",
       "src/eric7/WebBrowser/data/javascript/qwebchannel.js",
+      "src/eric7/data/linux/eric7.appdata.xml",
+      "src/eric7/data/linux/eric7.appdata.xml.in",
+      "src/eric7/data/linux/eric7.desktop",
+      "src/eric7/data/linux/eric7.desktop.in",
+      "src/eric7/data/linux/eric7_browser.desktop",
+      "src/eric7/data/linux/eric7_browser.desktop.in",
       "src/eric7/eric7installpip.json",
       "src/eric7/icons",
       "src/eric7/pixmaps"
     ],
     "OTHERTOOLSPARMS": {
       "CodeMetrics": {
-        "ExcludeFiles": "*/ThirdParty/*, */coverage/*, Ui_*.py"
+        "ExcludeFiles": "Examples/*, */ThirdParty/*, */coverage/*, Ui_*.py"
       },
       "RadonCodeMetrics": {
         "ExcludeFiles": "*/ThirdParty/*, */coverage/*, Ui_*.py, *_rc.py"
@@ -2432,4 +2432,4 @@
     "VCSOTHERDATA": {},
     "VERSION": "7.x"
   }
-}
+}
\ No newline at end of file
--- a/src/eric7/DataViews/CodeMetricsDialog.py	Thu Jul 07 11:23:56 2022 +0200
+++ b/src/eric7/DataViews/CodeMetricsDialog.py	Thu Jul 07 15:02:00 2022 +0200
@@ -18,6 +18,8 @@
     QApplication
 )
 
+from EricWidgets.EricApplication import ericApp
+
 from .Ui_CodeMetricsDialog import Ui_CodeMetricsDialog
 from . import CodeMetrics
 
@@ -62,7 +64,7 @@
             self.__showContextMenu)
         
         self.__fileList = []
-        self.__project = None
+        self.__project = ericApp().getObject("Project")
         self.filterFrame.setVisible(False)
         
     def __resizeResultColumns(self):
@@ -111,15 +113,14 @@
         itm = QTreeWidgetItem(self.summaryList, [col0, col1])
         itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
         
-    def prepare(self, fileList, project):
+    def prepare(self, fileList):
         """
         Public method to prepare the dialog with a list of filenames.
         
-        @param fileList list of filenames (list of strings)
-        @param project reference to the project object (Project)
+        @param fileList list of filenames
+        @type list of str
         """
         self.__fileList = fileList[:]
-        self.__project = project
         
         self.buttonBox.button(
             QDialogButtonBox.StandardButton.Close).setEnabled(True)
@@ -184,7 +185,11 @@
                 stats = CodeMetrics.analyze(file, total)
                 
                 v = self.__getValues(loc, stats, 'TOTAL ')
-                fitm = self.__createResultItem(self.resultList, [file] + v)
+                # make the file name project relative
+                fitm = self.__createResultItem(
+                    self.resultList,
+                    [self.__project.getRelativePath(file)] + v
+                )
                 
                 identifiers = stats.identifiers
                 for identifier in identifiers:
--- a/src/eric7/Project/Project.py	Thu Jul 07 11:23:56 2022 +0200
+++ b/src/eric7/Project/Project.py	Thu Jul 07 15:02:00 2022 +0200
@@ -3608,15 +3608,9 @@
         @return project relative path or unchanged path, if path doesn't
             belong to the project (string)
         """
-        if self.startswithProjectPath(path):
-            if self.ppath and path == self.ppath:
-                return ""
-            else:
-                relpath = path[len(self.ppath):]
-                if relpath.startswith(("/", "\\")):
-                    relpath = relpath[1:]
-                return relpath
-        else:
+        try:
+            return str(pathlib.Path(path).relative_to(self.ppath))
+        except ValueError:
             return path
         
     def getRelativeUniversalPath(self, path):
@@ -5097,7 +5091,7 @@
         from DataViews.CodeMetricsDialog import CodeMetricsDialog
         self.codemetrics = CodeMetricsDialog()
         self.codemetrics.show()
-        self.codemetrics.prepare(files, self)
+        self.codemetrics.prepare(files)
 
     def __showCodeCoverage(self):
         """

eric ide

mercurial