RadonMetrics/MaintainabilityIndexDialog.py

branch
eric7
changeset 83
d3490ea9facc
parent 77
7e1793d03381
child 90
1405e41edc0b
--- a/RadonMetrics/MaintainabilityIndexDialog.py	Wed May 26 17:13:04 2021 +0200
+++ b/RadonMetrics/MaintainabilityIndexDialog.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.QtGui import QColor
-from PyQt5.QtWidgets import (
+from PyQt6.QtCore import pyqtSlot, Qt, QTimer, QLocale
+from PyQt6.QtGui import QColor
+from PyQt6.QtWidgets import (
     QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem,
     QApplication
 )
 
 from .Ui_MaintainabilityIndexDialog import Ui_MaintainabilityIndexDialog
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 import Preferences
 import Utilities
@@ -28,7 +28,7 @@
     """
     Class implementing a dialog to show maintainability indexes.
     """
-    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.resultList.headerItem().setText(self.resultList.columnCount(), "")
         
@@ -56,7 +58,7 @@
         
         self.cancelled = False
         
-        self.__project = e5App().getObject("Project")
+        self.__project = ericApp().getObject("Project")
         self.__locale = QLocale()
         self.__finished = True
         self.__errorItem = None
@@ -75,10 +77,10 @@
         ))
         
         try:
-            usesDarkPalette = e5App().usesDarkPalette()
+            usesDarkPalette = ericApp().usesDarkPalette()
         except AttributeError:
-            from PyQt5.QtGui import QPalette
-            palette = e5App().palette()
+            from PyQt6.QtGui import QPalette
+            palette = ericApp().palette()
             lightness = palette.color(QPalette.Window).lightness()
             usesDarkPalette = lightness <= 128
         if usesDarkPalette:
@@ -98,7 +100,8 @@
         """
         Private method to resize the list columns.
         """
-        self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
+        self.resultList.header().resizeSections(
+            QHeaderView.ResizeMode.ResizeMode.ResizeToContents)
         self.resultList.header().setStretchLastSection(True)
     
     def __createResultItem(self, filename, values):
@@ -118,8 +121,8 @@
             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))
+        itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
+        itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter)
         if values["rank"] in self.__rankColors:
             itm.setBackground(2, self.__rankColors[values["rank"]])
         itm.setData(0, self.FilePathRole, filename)
@@ -140,13 +143,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):
@@ -161,9 +164,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)
         
@@ -187,17 +193,19 @@
         self.cancelled = False
         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))
@@ -241,7 +249,7 @@
         
         The results are reported to the __processResult slot.
         
-        @keyparam codestring optional sourcestring
+        @param codestring optional sourcestring
         @type str
         """
         if not self.files:
@@ -374,22 +382,22 @@
             
             # 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.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.summaryLabel.setText(self.tr(
                 "<table>"
@@ -414,9 +422,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.cancelMaintainabilityIndexBatch()
                 QTimer.singleShot(1000, self.__finish)
@@ -466,5 +478,5 @@
         """
         filename = item.data(0, self.FilePathRole)
         if filename:
-            vm = e5App().getObject("ViewManager")
+            vm = ericApp().getObject("ViewManager")
             vm.openSourceFile(filename)

eric ide

mercurial