--- a/RadonMetrics/CyclomaticComplexityDialog.py Wed May 26 17:13:04 2021 +0200 +++ b/RadonMetrics/CyclomaticComplexityDialog.py Wed May 26 17:43:25 2021 +0200 @@ -10,19 +10,16 @@ import os import fnmatch -import sys -sys.path.insert(0, os.path.dirname(__file__)) - -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, QMenu ) from .Ui_CyclomaticComplexityDialog import Ui_CyclomaticComplexityDialog -from E5Gui.E5Application import e5App +from EricWidgets.EricApplication import ericApp import Preferences import Utilities @@ -33,8 +30,8 @@ Class implementing a dialog to show the cyclomatic complexity (McCabe complexity). """ - FilePathRole = Qt.UserRole + 1 - LineNumberRole = Qt.UserRole + 2 + FilePathRole = Qt.ItemDataRole.UserRole + 1 + LineNumberRole = Qt.ItemDataRole.UserRole + 2 def __init__(self, radonService, isSingle=False, parent=None): """ @@ -49,10 +46,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(), "") @@ -68,7 +67,7 @@ self.__isSingle = isSingle self.cancelled = False - self.__project = e5App().getObject("Project") + self.__project = ericApp().getObject("Project") self.__locale = QLocale() self.__finished = True self.__errorItem = None @@ -109,10 +108,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: @@ -148,7 +147,8 @@ self.__menu.addAction(self.tr("Collapse all"), self.__resultCollapse) self.__menu.addAction(self.tr("Expand all"), self.__resultExpand) - self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) + self.resultList.setContextMenuPolicy( + Qt.ContextMenuPolicy.CustomContextMenu) self.resultList.customContextMenuRequested.connect( self.__showContextMenu) @@ -156,7 +156,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 __createFileItem(self, filename): @@ -191,9 +192,9 @@ values["rank"], "{0:6}".format(values["lineno"]), ]) - itm.setTextAlignment(2, Qt.Alignment(Qt.AlignRight)) - itm.setTextAlignment(3, Qt.Alignment(Qt.AlignHCenter)) - itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight)) + itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) + itm.setTextAlignment(3, Qt.AlignmentFlag.AlignHCenter) + itm.setTextAlignment(4, Qt.AlignmentFlag.AlignRight) if values["rank"] in self.__rankColors: itm.setBackground(3, self.__rankColors[values["rank"]]) if values["type"] in self.__typeColors: @@ -223,13 +224,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): @@ -244,9 +245,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) @@ -277,9 +281,12 @@ self.summaryLabel.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) self.rankComboBox.setEnabled(False) QApplication.processEvents() @@ -287,8 +294,7 @@ 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)) @@ -341,7 +347,7 @@ The results are reported to the __processResult slot. - @keyparam codestring optional sourcestring + @param codestring optional sourcestring @type str """ if not self.files: @@ -488,24 +494,24 @@ # re-enable updates of the list self.resultList.setSortingEnabled(True) - self.resultList.sortItems(0, Qt.AscendingOrder) - self.resultList.sortItems(1, Qt.AscendingOrder) + self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) + self.resultList.sortItems(1, 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.rankComboBox.setEnabled(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) averageCC = float(self.__ccSum) / (self.__ccCount or 1) @@ -550,9 +556,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.cancelComplexityBatch() QTimer.singleShot(1000, self.__finish) @@ -638,7 +648,7 @@ filename = item.data(0, self.FilePathRole) lineno = item.data(0, self.LineNumberRole) if filename: - vm = e5App().getObject("ViewManager") + vm = ericApp().getObject("ViewManager") vm.openSourceFile(filename, lineno) @pyqtSlot(str)