diff --git a/plugins/Marketplace/LocalPackageList.py b/plugins/Marketplace/LocalPackageList.py index 6acbaa8500..7e9bd82cdb 100644 --- a/plugins/Marketplace/LocalPackageList.py +++ b/plugins/Marketplace/LocalPackageList.py @@ -90,4 +90,4 @@ class LocalPackageList(PackageList): bundled_or_installed = "installed" if self._manager.isUserInstalledPackage(package_info["package_id"]) else "bundled" package_type = package_info["package_type"] section_title = self.PACKAGE_SECTION_HEADER[bundled_or_installed][package_type] - return PackageModel(package_info, section_title = section_title, parent = self) + return PackageModel(package_info, installation_status = bundled_or_installed, section_title = section_title, parent = self) diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py index 7528a71440..c4389434e4 100644 --- a/plugins/Marketplace/PackageModel.py +++ b/plugins/Marketplace/PackageModel.py @@ -17,10 +17,11 @@ class PackageModel(QObject): QML. The model can also be constructed directly from a response received by the API. """ - def __init__(self, package_data: Dict[str, Any], section_title: Optional[str] = None, parent: Optional[QObject] = None) -> None: + def __init__(self, package_data: Dict[str, Any], installation_status: str, section_title: Optional[str] = None, parent: Optional[QObject] = None) -> None: """ Constructs a new model for a single package. :param package_data: The data received from the Marketplace API about the package to create. + :param installation_status: Whether the package is `not_installed`, `installed` or `bundled`. :param section_title: If the packages are to be categorized per section provide the section_title :param parent: The parent QML object that controls the lifetime of this model (normally a PackageList). """ @@ -46,6 +47,7 @@ class PackageModel(QObject): if not self._icon_url or self._icon_url == "": self._icon_url = author_data.get("icon_url", "") + self._installation_status = installation_status self._section_title = section_title # Note that there's a lot more info in the package_data than just these specified here. @@ -108,6 +110,10 @@ class PackageModel(QObject): def authorInfoUrl(self): return self._author_info_url + @pyqtProperty(str, constant = True) + def installationStatus(self) -> str: + return self._installation_status + @pyqtProperty(str, constant = True) def sectionTitle(self) -> Optional[str]: return self._section_title diff --git a/plugins/Marketplace/RemotePackageList.py b/plugins/Marketplace/RemotePackageList.py index e7df498fbf..6241ce0d2c 100644 --- a/plugins/Marketplace/RemotePackageList.py +++ b/plugins/Marketplace/RemotePackageList.py @@ -134,8 +134,9 @@ class RemotePackageList(PackageList): return for package_data in response_data["data"]: + installation_status = "installed" if CuraApplication.getInstance().getPackageManager().isUserInstalledPackage(package_data["package_id"]) else "not_installed" try: - package = PackageModel(package_data, parent = self) + package = PackageModel(package_data, installation_status, parent = self) self.appendItem({"package": package}) # Add it to this list model. except RuntimeError: # Setting the ownership of this object to not qml can still result in a RuntimeError. Which can occur when quickly toggling diff --git a/plugins/Marketplace/resources/qml/PackageCard.qml b/plugins/Marketplace/resources/qml/PackageCard.qml index bb43f926b6..1c4066f64e 100644 --- a/plugins/Marketplace/resources/qml/PackageCard.qml +++ b/plugins/Marketplace/resources/qml/PackageCard.qml @@ -303,6 +303,7 @@ Rectangle width: UM.Theme.getSize("card_tiny_icon").width height: UM.Theme.getSize("card_tiny_icon").height + visible: packageData.installationStatus !== "bundled" //Don't show download count for packages that are bundled. It'll usually be 0. source: UM.Theme.getIcon("Download") color: UM.Theme.getColor("text") } @@ -311,6 +312,7 @@ Rectangle { anchors.verticalCenter: downloadsIcon.verticalCenter + visible: packageData.installationStatus !== "bundled" //Don't show download count for packages that are bundled. It'll usually be 0. color: UM.Theme.getColor("text") font: UM.Theme.getFont("default") text: packageData.downloadCount