diff --git a/src/Mod/AddonManager/package_list.py b/src/Mod/AddonManager/package_list.py index 6db03395ef..19a9449ce6 100644 --- a/src/Mod/AddonManager/package_list.py +++ b/src/Mod/AddonManager/package_list.py @@ -28,9 +28,7 @@ import threading import FreeCAD -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtWidgets import * +from PySide import QtCore, QtGui, QtWidgets from Addon import Addon @@ -42,6 +40,8 @@ import addonmanager_utilities as utils translate = FreeCAD.Qt.translate +# pylint: disable=too-few-public-methods + class ListDisplayStyle(IntEnum): """The display mode of the list""" @@ -58,10 +58,11 @@ class StatusFilter(IntEnum): UPDATE_AVAILABLE = 3 -class PackageList(QWidget): - """A widget that shows a list of packages and various widgets to control the display of the list""" +class PackageList(QtWidgets.QWidget): + """A widget that shows a list of packages and various widgets to control the + display of the list""" - itemSelected = Signal(Addon) + itemSelected = QtCore.Signal(Addon) def __init__(self, parent=None): super().__init__(parent) @@ -117,7 +118,7 @@ class PackageList(QWidget): pref.GetBool("HideNewerFreeCADRequired", True) ) - def on_listPackages_clicked(self, index: QModelIndex): + def on_listPackages_clicked(self, index: QtCore.QModelIndex): """Determine what addon was selected and emit the itemSelected signal with it as an argument.""" source_selection = self.item_filter.mapToSource(index) @@ -127,7 +128,8 @@ class PackageList(QWidget): def update_type_filter(self, type_filter: int) -> None: """hide/show rows corresponding to the type filter - type_filter is an integer: 0 for all, 1 for workbenches, 2 for macros, and 3 for preference packs + type_filter is an integer: 0 for all, 1 for workbenches, 2 for macros, + and 3 for preference packs """ @@ -138,7 +140,8 @@ class PackageList(QWidget): def update_status_filter(self, status_filter: int) -> None: """hide/show rows corresponding to the status filter - status_filter is an integer: 0 for any, 1 for installed, 2 for not installed, and 3 for update available + status_filter is an integer: 0 for any, 1 for installed, 2 for not installed, + and 3 for update available """ @@ -153,20 +156,22 @@ class PackageList(QWidget): if hasattr( self.item_filter, "setFilterRegularExpression" ): # Added in Qt 5.12 - test_regex = QRegularExpression(text_filter) + test_regex = QtCore.QRegularExpression(text_filter) else: - test_regex = QRegExp(text_filter) + test_regex = QtCore.QRegExp(text_filter) if test_regex.isValid(): self.ui.labelFilterValidity.setToolTip( translate("AddonsInstaller", "Filter is valid") ) - icon = QIcon.fromTheme("ok", QIcon(":/icons/edit_OK.svg")) + icon = QtGui.QIcon.fromTheme("ok", QtGui.QIcon(":/icons/edit_OK.svg")) self.ui.labelFilterValidity.setPixmap(icon.pixmap(16, 16)) else: self.ui.labelFilterValidity.setToolTip( translate("AddonsInstaller", "Filter regular expression is invalid") ) - icon = QIcon.fromTheme("cancel", QIcon(":/icons/edit_Cancel.svg")) + icon = QtGui.QIcon.fromTheme( + "cancel", QtGui.QIcon(":/icons/edit_Cancel.svg") + ) self.ui.labelFilterValidity.setPixmap(icon.pixmap(16, 16)) self.ui.labelFilterValidity.show() else: @@ -190,34 +195,34 @@ class PackageList(QWidget): pref.SetInt("ViewStyle", style) -class PackageListItemModel(QAbstractListModel): +class PackageListItemModel(QtCore.QAbstractListModel): """The model for use with the PackageList class.""" repos = [] write_lock = threading.Lock() - DataAccessRole = Qt.UserRole - StatusUpdateRole = Qt.UserRole + 1 - IconUpdateRole = Qt.UserRole + 2 + DataAccessRole = QtCore.Qt.UserRole + StatusUpdateRole = QtCore.Qt.UserRole + 1 + IconUpdateRole = QtCore.Qt.UserRole + 2 - def rowCount(self, parent: QModelIndex = QModelIndex()) -> int: + def rowCount(self, parent: QtCore.QModelIndex = QtCore.QModelIndex()) -> int: """The number of rows""" if parent.isValid(): return 0 return len(self.repos) - def columnCount(self, parent: QModelIndex = QModelIndex()) -> int: + def columnCount(self, parent: QtCore.QModelIndex = QtCore.QModelIndex()) -> int: """Only one column, always returns 1.""" if parent.isValid(): return 0 return 1 - def data(self, index: QModelIndex, role: int = Qt.DisplayRole): + def data(self, index: QtCore.QModelIndex, role: int = QtCore.Qt.DisplayRole): """Get the data for a given index and role.""" if not index.isValid(): return None row = index.row() - if role == Qt.ToolTipRole: + if role == QtCore.Qt.ToolTipRole: tooltip = "" if self.repos[row].repo_type == Addon.Kind.PACKAGE: tooltip = translate( @@ -235,11 +240,13 @@ class PackageListItemModel(QAbstractListModel): if role == PackageListItemModel.DataAccessRole: return self.repos[row] - def headerData(self, _unused1, _unused2, _role=Qt.DisplayRole): + def headerData(self, _unused1, _unused2, _role=QtCore.Qt.DisplayRole): """No header in this implementation: always returns None.""" return None - def setData(self, index: QModelIndex, value, role=Qt.EditRole) -> None: + def setData( + self, index: QtCore.QModelIndex, value, role=QtCore.Qt.EditRole + ) -> None: """Set the data for this row. The column of the index is ignored.""" row = index.row() @@ -265,7 +272,7 @@ class PackageListItemModel(QAbstractListModel): # Cowardly refuse to insert the same repo a second time return with self.write_lock: - self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount()) + self.beginInsertRows(QtCore.QModelIndex(), self.rowCount(), self.rowCount()) self.repos.append(repo) self.endInsertRows() @@ -273,7 +280,7 @@ class PackageListItemModel(QAbstractListModel): """Clear the model, removing all rows. Thread safe.""" if self.rowCount() > 0: with self.write_lock: - self.beginRemoveRows(QModelIndex(), 0, self.rowCount() - 1) + self.beginRemoveRows(QtCore.QModelIndex(), 0, self.rowCount() - 1) self.repos = [] self.endRemoveRows() @@ -286,7 +293,7 @@ class PackageListItemModel(QAbstractListModel): ) return - def update_item_icon(self, name: str, icon: QIcon) -> None: + def update_item_icon(self, name: str, icon: QtGui.QIcon) -> None: """Set the icon for Addon with name to icon""" for row, item in enumerate(self.repos): if item.name == name: @@ -304,29 +311,25 @@ class PackageListItemModel(QAbstractListModel): return -class CompactView(QWidget): +class CompactView(QtWidgets.QWidget): """A single-line view of the package information""" - from compact_view import Ui_CompactView - def __init__(self, parent=None): super().__init__(parent) self.ui = Ui_CompactView() self.ui.setupUi(self) -class ExpandedView(QWidget): +class ExpandedView(QtWidgets.QWidget): """A multi-line view of the package information""" - from expanded_view import Ui_ExpandedView - def __init__(self, parent=None): super().__init__(parent) self.ui = Ui_ExpandedView() self.ui.setupUi(self) -class PackageListItemDelegate(QStyledItemDelegate): +class PackageListItemDelegate(QtWidgets.QStyledItemDelegate): """Render the repo data as a formatted region""" def __init__(self, parent=None): @@ -352,11 +355,11 @@ class PackageListItemDelegate(QStyledItemDelegate): if self.displayStyle == ListDisplayStyle.EXPANDED: self.widget = self.expanded self.widget.ui.labelPackageName.setText(f"

{repo.display_name}

") - self.widget.ui.labelIcon.setPixmap(repo.icon.pixmap(QSize(48, 48))) + self.widget.ui.labelIcon.setPixmap(repo.icon.pixmap(QtCore.QSize(48, 48))) else: self.widget = self.compact self.widget.ui.labelPackageName.setText(f"{repo.display_name}") - self.widget.ui.labelIcon.setPixmap(repo.icon.pixmap(QSize(16, 16))) + self.widget.ui.labelIcon.setPixmap(repo.icon.pixmap(QtCore.QSize(16, 16))) self.widget.ui.labelIcon.setText("") if self.displayStyle == ListDisplayStyle.EXPANDED: @@ -480,9 +483,9 @@ class PackageListItemDelegate(QStyledItemDelegate): "
" + translate("AddonsInstaller", "Installed on") + ": " ) installed_date_string += ( - QDateTime.fromTime_t(repo.updated_timestamp) + QtCore.QDateTime.fromTime_t(repo.updated_timestamp) .date() - .toString(Qt.SystemLocaleShortDate) + .toString(QtCore.Qt.SystemLocaleShortDate) ) available_version_string = "" @@ -520,24 +523,31 @@ class PackageListItemDelegate(QStyledItemDelegate): return result - def paint(self, painter: QPainter, option: QStyleOptionViewItem, _: QModelIndex): + def paint( + self, + painter: QtGui.QPainter, + option: QtWidgets.QStyleOptionViewItem, + _: QtCore.QModelIndex, + ): """Main paint function: renders this widget into a given rectangle, successively drawing all of its children.""" painter.save() self.widget.resize(option.rect.size()) painter.translate(option.rect.topLeft()) - self.widget.render(painter, QPoint(), QRegion(), QWidget.DrawChildren) + self.widget.render( + painter, QtCore.QPoint(), QtGui.QRegion(), QtWidgets.QWidget.DrawChildren + ) painter.restore() -class PackageListFilter(QSortFilterProxyModel): +class PackageListFilter(QtCore.QSortFilterProxyModel): """Handle filtering the item list on various criteria""" def __init__(self): super().__init__() self.package_type = 0 # Default to showing everything self.status = 0 # Default to showing any - self.setSortCaseSensitivity(Qt.CaseInsensitive) + self.setSortCaseSensitivity(QtCore.Qt.CaseInsensitive) self.hide_obsolete = False self.hide_py2 = False self.hide_newer_freecad_required = False @@ -557,30 +567,32 @@ class PackageListFilter(QSortFilterProxyModel): self.invalidateFilter() def setHidePy2(self, hide_py2: bool) -> None: - """Sets whether or not to hide Python 2-only Addons""" + """Sets whether to hide Python 2-only Addons""" self.hide_py2 = hide_py2 self.invalidateFilter() def setHideObsolete(self, hide_obsolete: bool) -> None: - """Sets whether or not to hide Addons marked obsolete""" + """Sets whether to hide Addons marked obsolete""" self.hide_obsolete = hide_obsolete self.invalidateFilter() def setHideNewerFreeCADRequired(self, hide_nfr: bool) -> None: - """Sets whether or not to hide packages that have indicated they need a newer version + """Sets whether to hide packages that have indicated they need a newer version of FreeCAD than the one currently running.""" self.hide_newer_freecad_required = hide_nfr self.invalidateFilter() - def lessThan(self, left, right) -> bool: - """Enable sorting of display name (not case sensitive).""" - l = self.sourceModel().data(left, PackageListItemModel.DataAccessRole) - r = self.sourceModel().data(right, PackageListItemModel.DataAccessRole) + def lessThan(self, left_in, right_in) -> bool: + """Enable sorting of display name (not case-sensitive).""" - return l.display_name.lower() < r.display_name.lower() + left = self.sourceModel().data(left_in, PackageListItemModel.DataAccessRole) + right = self.sourceModel().data(right_in, PackageListItemModel.DataAccessRole) - def filterAcceptsRow(self, row, parent=QModelIndex()): + return left.display_name.lower() < right.display_name.lower() + + def filterAcceptsRow(self, row, _parent=QtCore.QModelIndex()): """Do the actual filtering (called automatically by Qt when drawing the list)""" + index = self.sourceModel().createIndex(row, 0) data = self.sourceModel().data(index, PackageListItemModel.DataAccessRole) if self.package_type == 1: @@ -646,7 +658,7 @@ class PackageListFilter(QSortFilterProxyModel): if hasattr(self, "filterRegularExpression"): # Added in Qt 5.12 re = self.filterRegularExpression() if re.isValid(): - re.setPatternOptions(QRegularExpression.CaseInsensitiveOption) + re.setPatternOptions(QtCore.QRegularExpression.CaseInsensitiveOption) if re.match(name).hasMatch(): return True if re.match(desc).hasMatch(): @@ -664,7 +676,7 @@ class PackageListFilter(QSortFilterProxyModel): # Only get here for Qt < 5.12 re = self.filterRegExp() if re.isValid(): - re.setCaseSensitivity(Qt.CaseInsensitive) + re.setCaseSensitivity(QtCore.Qt.CaseInsensitive) if re.indexIn(name) != -1: return True if re.indexIn(desc) != -1: @@ -680,44 +692,49 @@ class PackageListFilter(QSortFilterProxyModel): return True return False +# pylint: disable=attribute-defined-outside-init, missing-function-docstring -class Ui_PackageList(object): +class Ui_PackageList(): """The contents of the PackageList widget""" - def setupUi(self, Form): - if not Form.objectName(): - Form.setObjectName("PackageList") - self.verticalLayout = QVBoxLayout(Form) + def setupUi(self, form): + if not form.objectName(): + form.setObjectName("PackageList") + self.verticalLayout = QtWidgets.QVBoxLayout(form) self.verticalLayout.setObjectName("verticalLayout") - self.horizontalLayout_6 = QHBoxLayout() + self.horizontalLayout_6 = QtWidgets.QHBoxLayout() self.horizontalLayout_6.setObjectName("horizontalLayout_6") - self.buttonCompactLayout = QToolButton(Form) + self.buttonCompactLayout = QtWidgets.QToolButton(form) self.buttonCompactLayout.setObjectName("buttonCompactLayout") self.buttonCompactLayout.setCheckable(True) self.buttonCompactLayout.setAutoExclusive(True) self.buttonCompactLayout.setIcon( - QIcon.fromTheme("expanded_view", QIcon(":/icons/compact_view.svg")) + QtGui.QIcon.fromTheme( + "expanded_view", QtGui.QIcon(":/icons/compact_view.svg") + ) ) self.horizontalLayout_6.addWidget(self.buttonCompactLayout) - self.buttonExpandedLayout = QToolButton(Form) + self.buttonExpandedLayout = QtWidgets.QToolButton(form) self.buttonExpandedLayout.setObjectName("buttonExpandedLayout") self.buttonExpandedLayout.setCheckable(True) self.buttonExpandedLayout.setChecked(True) self.buttonExpandedLayout.setAutoExclusive(True) self.buttonExpandedLayout.setIcon( - QIcon.fromTheme("expanded_view", QIcon(":/icons/expanded_view.svg")) + QtGui.QIcon.fromTheme( + "expanded_view", QtGui.QIcon(":/icons/expanded_view.svg") + ) ) self.horizontalLayout_6.addWidget(self.buttonExpandedLayout) - self.labelPackagesContaining = QLabel(Form) + self.labelPackagesContaining = QtWidgets.QLabel(form) self.labelPackagesContaining.setObjectName("labelPackagesContaining") self.horizontalLayout_6.addWidget(self.labelPackagesContaining) - self.comboPackageType = QComboBox(Form) + self.comboPackageType = QtWidgets.QComboBox(form) self.comboPackageType.addItem("") self.comboPackageType.addItem("") self.comboPackageType.addItem("") @@ -726,12 +743,12 @@ class Ui_PackageList(object): self.horizontalLayout_6.addWidget(self.comboPackageType) - self.labelStatus = QLabel(Form) + self.labelStatus = QtWidgets.QLabel(form) self.labelStatus.setObjectName("labelStatus") self.horizontalLayout_6.addWidget(self.labelStatus) - self.comboStatus = QComboBox(Form) + self.comboStatus = QtWidgets.QComboBox(form) self.comboStatus.addItem("") self.comboStatus.addItem("") self.comboStatus.addItem("") @@ -740,74 +757,80 @@ class Ui_PackageList(object): self.horizontalLayout_6.addWidget(self.comboStatus) - self.lineEditFilter = QLineEdit(Form) + self.lineEditFilter = QtWidgets.QLineEdit(form) self.lineEditFilter.setObjectName("lineEditFilter") self.lineEditFilter.setClearButtonEnabled(True) self.horizontalLayout_6.addWidget(self.lineEditFilter) - self.labelFilterValidity = QLabel(Form) + self.labelFilterValidity = QtWidgets.QLabel(form) self.labelFilterValidity.setObjectName("labelFilterValidity") self.horizontalLayout_6.addWidget(self.labelFilterValidity) self.verticalLayout.addLayout(self.horizontalLayout_6) - self.listPackages = QListView(Form) + self.listPackages = QtWidgets.QListView(form) self.listPackages.setObjectName("listPackages") - self.listPackages.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.listPackages.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.listPackages.setProperty("showDropIndicator", False) - self.listPackages.setSelectionMode(QAbstractItemView.NoSelection) - self.listPackages.setResizeMode(QListView.Adjust) + self.listPackages.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) + self.listPackages.setResizeMode(QtWidgets.QListView.Adjust) self.listPackages.setUniformItemSizes(False) self.listPackages.setAlternatingRowColors(True) - self.listPackages.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.listPackages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.verticalLayout.addWidget(self.listPackages) - self.retranslateUi(Form) + self.retranslateUi(form) - QMetaObject.connectSlotsByName(Form) + QtCore.QMetaObject.connectSlotsByName(form) - def retranslateUi(self, Form): + def retranslateUi(self, _): self.labelPackagesContaining.setText( - QCoreApplication.translate( + QtCore.QCoreApplication.translate( "AddonsInstaller", "Show Addons containing:", None ) ) self.comboPackageType.setItemText( - 0, QCoreApplication.translate("AddonsInstaller", "All", None) + 0, QtCore.QCoreApplication.translate("AddonsInstaller", "All", None) ) self.comboPackageType.setItemText( - 1, QCoreApplication.translate("AddonsInstaller", "Workbenches", None) + 1, QtCore.QCoreApplication.translate("AddonsInstaller", "Workbenches", None) ) self.comboPackageType.setItemText( - 2, QCoreApplication.translate("AddonsInstaller", "Macros", None) + 2, QtCore.QCoreApplication.translate("AddonsInstaller", "Macros", None) ) self.comboPackageType.setItemText( - 3, QCoreApplication.translate("AddonsInstaller", "Preference Packs", None) + 3, + QtCore.QCoreApplication.translate( + "AddonsInstaller", "Preference Packs", None + ), ) self.labelStatus.setText( - QCoreApplication.translate("AddonsInstaller", "Status:", None) + QtCore.QCoreApplication.translate("AddonsInstaller", "Status:", None) ) self.comboStatus.setItemText( - StatusFilter.ANY, QCoreApplication.translate("AddonsInstaller", "Any", None) + StatusFilter.ANY, + QtCore.QCoreApplication.translate("AddonsInstaller", "Any", None), ) self.comboStatus.setItemText( StatusFilter.INSTALLED, - QCoreApplication.translate("AddonsInstaller", "Installed", None), + QtCore.QCoreApplication.translate("AddonsInstaller", "Installed", None), ) self.comboStatus.setItemText( StatusFilter.NOT_INSTALLED, - QCoreApplication.translate("AddonsInstaller", "Not installed", None), + QtCore.QCoreApplication.translate("AddonsInstaller", "Not installed", None), ) self.comboStatus.setItemText( StatusFilter.UPDATE_AVAILABLE, - QCoreApplication.translate("AddonsInstaller", "Update available", None), + QtCore.QCoreApplication.translate( + "AddonsInstaller", "Update available", None + ), ) self.lineEditFilter.setPlaceholderText( - QCoreApplication.translate("AddonsInstaller", "Filter", None) + QtCore.QCoreApplication.translate("AddonsInstaller", "Filter", None) ) self.labelFilterValidity.setText( - QCoreApplication.translate("AddonsInstaller", "OK", None) + QtCore.QCoreApplication.translate("AddonsInstaller", "OK", None) )