RadonMetrics/RawMetricsDialog.py

branch
eric7
changeset 83
d3490ea9facc
parent 77
7e1793d03381
child 88
8b61e17a6d63
--- a/RadonMetrics/RawMetricsDialog.py	Wed May 26 17:13:04 2021 +0200
+++ b/RadonMetrics/RawMetricsDialog.py	Wed May 26 17:43:25 2021 +0200
@@ -10,15 +10,15 @@
 import os
 import fnmatch
 
-from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale
-from PyQt5.QtWidgets import (
+from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QLocale
+from PyQt6.QtWidgets import (
     QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem,
     QApplication
 )
 
 from .Ui_RawMetricsDialog import Ui_RawMetricsDialog
 
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 import Preferences
 import Utilities
@@ -28,7 +28,7 @@
     """
     Class implementing a dialog to show raw code metrics.
     """
-    FilePathRole = Qt.UserRole + 1
+    FilePathRole = Qt.ItemDataRole.UserRole + 1
     
     def __init__(self, radonService, parent=None):
         """
@@ -41,10 +41,12 @@
         """
         super().__init__(parent)
         self.setupUi(self)
-        self.setWindowFlags(Qt.Window)
+        self.setWindowFlags(Qt.WindowType.Window)
         
-        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
-        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Close).setEnabled(False)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Cancel).setDefault(True)
         
         self.summaryList.headerItem().setText(
             self.summaryList.columnCount(), "")
@@ -60,7 +62,7 @@
         
         self.cancelled = False
         
-        self.__project = e5App().getObject("Project")
+        self.__project = ericApp().getObject("Project")
         self.__locale = QLocale()
         self.__finished = True
         self.__errorItem = None
@@ -93,7 +95,8 @@
         """
         Private method to resize the list columns.
         """
-        self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
+        self.resultList.header().resizeSections(
+            QHeaderView.ResizeMode.ResizeToContents)
         self.resultList.header().setStretchLastSection(True)
     
     def __createResultItem(self, filename, values):
@@ -123,7 +126,7 @@
             1.0)))
         itm = QTreeWidgetItem(self.resultList, data)
         for col in range(1, 10):
-            itm.setTextAlignment(col, Qt.Alignment(Qt.AlignRight))
+            itm.setTextAlignment(col, Qt.AlignmentFlag.AlignRight)
         itm.setData(0, self.FilePathRole, filename)
     
     def __createErrorItem(self, filename, message):
@@ -139,13 +142,13 @@
             self.__errorItem = QTreeWidgetItem(self.resultList, [
                 self.tr("Errors")])
             self.__errorItem.setExpanded(True)
-            self.__errorItem.setForeground(0, Qt.red)
+            self.__errorItem.setForeground(0, Qt.GlobalColor.red)
         
         msg = "{0} ({1})".format(self.__project.getRelativePath(filename),
                                  message)
-        if not self.resultList.findItems(msg, Qt.MatchExactly):
+        if not self.resultList.findItems(msg, Qt.MatchFlag.MatchExactly):
             itm = QTreeWidgetItem(self.__errorItem, [msg])
-            itm.setForeground(0, Qt.red)
+            itm.setForeground(0, Qt.GlobalColor.red)
             itm.setFirstColumnSpanned(True)
     
     def prepare(self, fileList, project):
@@ -160,9 +163,12 @@
         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.buttonBox.button(
+            QDialogButtonBox.StandardButton.Close).setEnabled(True)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Close).setDefault(True)
         
         self.filterFrame.setVisible(True)
         
@@ -186,17 +192,19 @@
         self.summaryList.clear()
         QApplication.processEvents()
         
-        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
-        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
-        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Close).setEnabled(False)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.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"))
+            extensions = set(Preferences.getPython("Python3Extensions"))
             for ext in extensions:
                 self.files.extend(
                     Utilities.direntries(fn, True, '*{0}'.format(ext), 0))
@@ -238,7 +246,7 @@
         
         The results are reported to the __processResult slot.
         
-        @keyparam codestring optional sourcestring
+        @param codestring optional sourcestring
         @type str
         """
         if not self.files:
@@ -392,24 +400,24 @@
             
             # reenable updates of the list
             self.resultList.setSortingEnabled(True)
-            self.resultList.sortItems(0, Qt.AscendingOrder)
+            self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder)
             self.resultList.setUpdatesEnabled(True)
             
             self.__createSummary()
             
             self.cancelled = True
-            self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
-            self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
-            self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setEnabled(True)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
+            self.buttonBox.button(
+                QDialogButtonBox.StandardButton.Close).setDefault(True)
             
             self.resultList.header().resizeSections(
-                QHeaderView.ResizeToContents)
+                QHeaderView.ResizeMode.ResizeToContents)
             self.resultList.header().setStretchLastSection(True)
-            if qVersion() >= "5.0.0":
-                self.resultList.header().setSectionResizeMode(
-                    QHeaderView.Interactive)
-            else:
-                self.resultList.header().setResizeMode(QHeaderView.Interactive)
+            self.resultList.header().setSectionResizeMode(
+                QHeaderView.ResizeMode.Interactive)
             
             self.checkProgress.setVisible(False)
             self.checkProgressLabel.setVisible(False)
@@ -439,7 +447,8 @@
             self.tr("Empty Lines"),
             self.__locale.toString(self.__summary["blank"]))
         
-        self.summaryList.header().resizeSections(QHeaderView.ResizeToContents)
+        self.summaryList.header().resizeSections(
+            QHeaderView.ResizeMode.ResizeToContents)
         self.summaryList.header().setStretchLastSection(True)
     
     def __createSummaryItem(self, col0, col1):
@@ -450,7 +459,7 @@
         @param col1 string for column 1 (string)
         """
         itm = QTreeWidgetItem(self.summaryList, [col0, col1])
-        itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight))
+        itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
@@ -460,9 +469,13 @@
         @param button button that was clicked
         @type QAbstractButton
         """
-        if button == self.buttonBox.button(QDialogButtonBox.Close):
+        if button == self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Close
+        ):
             self.close()
-        elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
+        elif button == self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Cancel
+        ):
             if self.__batch:
                 self.radonService.cancelRawMetricsBatch()
                 QTimer.singleShot(1000, self.__finish)
@@ -512,5 +525,5 @@
         """
         filename = item.data(0, self.FilePathRole)
         if filename:
-            vm = e5App().getObject("ViewManager")
+            vm = ericApp().getObject("ViewManager")
             vm.openSourceFile(filename)

eric ide

mercurial