diff --git a/plugins/Toolbox/resources/qml/dialogs/CompatibilityDialog.qml b/plugins/Toolbox/resources/qml/dialogs/CompatibilityDialog.qml index f5a20986d1..a6ce7fc865 100644 --- a/plugins/Toolbox/resources/qml/dialogs/CompatibilityDialog.qml +++ b/plugins/Toolbox/resources/qml/dialogs/CompatibilityDialog.qml @@ -48,6 +48,7 @@ UM.Dialog{ { font: UM.Theme.getFont("default") text: catalog.i18nc("@label", "The following packages will be added:") + visible: toolbox.has_compatible_packages color: UM.Theme.getColor("text") height: contentHeight + UM.Theme.getSize("default_margin").height } @@ -59,8 +60,8 @@ UM.Dialog{ Item { width: parent.width - property var lineHeight: 60 - visible: model.is_compatible == "True" ? true : false + property int lineHeight: 60 + visible: model.is_compatible height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the compatible packages here Image { @@ -90,6 +91,7 @@ UM.Dialog{ { font: UM.Theme.getFont("default") text: catalog.i18nc("@label", "The following packages can not be installed because of incompatible Cura version:") + visible: toolbox.has_incompatible_packages color: UM.Theme.getColor("text") height: contentHeight + UM.Theme.getSize("default_margin").height } @@ -101,8 +103,8 @@ UM.Dialog{ Item { width: parent.width - property var lineHeight: 60 - visible: model.is_compatible == "True" ? false : true + property int lineHeight: 60 + visible: !model.is_compatible height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the incompatible packages here Image { diff --git a/plugins/Toolbox/src/SubscribedPackagesModel.py b/plugins/Toolbox/src/SubscribedPackagesModel.py index f8340ab7a0..2ae0f5399b 100644 --- a/plugins/Toolbox/src/SubscribedPackagesModel.py +++ b/plugins/Toolbox/src/SubscribedPackagesModel.py @@ -10,6 +10,7 @@ class SubscribedPackagesModel(ListModel): def __init__(self, parent = None): super().__init__(parent) + self._items = [] self._metadata = None self._discrepancies = None self._sdk_version = ApplicationMetadata.CuraSDKVersion @@ -27,20 +28,34 @@ class SubscribedPackagesModel(ListModel): self._discrepancies = discrepancy def update(self): - items = [] + self._items.clear() for item in self._metadata: if item["package_id"] not in self._discrepancies: continue package = {"name": item["display_name"], "sdk_versions": item["sdk_versions"]} if self._sdk_version not in item["sdk_versions"]: - package.update({"is_compatible": "False"}) + package.update({"is_compatible": False}) else: - package.update({"is_compatible": "True"}) + package.update({"is_compatible": True}) try: package.update({"icon_url": item["icon_url"]}) except KeyError: # There is no 'icon_url" in the response payload for this package package.update({"icon_url": ""}) - items.append(package) - self.setItems(items) \ No newline at end of file + self._items.append(package) + self.setItems(self._items) + + def hasCompatiblePackages(self): + has_compatible_items = False + for item in self._items: + if item['is_compatible'] == True: + has_compatible_items = True + return has_compatible_items + + def hasIncompatiblePackages(self): + has_incompatible_items = False + for item in self._items: + if item['is_compatible'] == False: + has_incompatible_items = True + return has_incompatible_items \ No newline at end of file diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 5502ece373..f28178b99e 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -796,6 +796,14 @@ class Toolbox(QObject, Extension): def subscribedPackagesModel(self) -> SubscribedPackagesModel: return cast(SubscribedPackagesModel, self._models["subscribed_packages"]) + @pyqtProperty(bool, constant=True) + def has_compatible_packages(self) -> str: + return self._models["subscribed_packages"].hasCompatiblePackages() + + @pyqtProperty(bool, constant=True) + def has_incompatible_packages(self) -> str: + return self._models["subscribed_packages"].hasIncompatiblePackages() + @pyqtProperty(QObject, constant = True) def packagesModel(self) -> PackagesModel: return cast(PackagesModel, self._models["packages"])