Browse Source

Remove the label(s) from the compatibility dialog if there are no packages

CURA-7038
Dimitriovski 5 years ago
parent
commit
75d2a72424

+ 6 - 4
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 === "True" ? true : false
                             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 === "True" ? false : true
                             height: visible ? (lineHeight + UM.Theme.getSize("default_margin").height) : 0 // We only show the incompatible packages here
                             Image
                             {

+ 19 - 3
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,7 +28,7 @@ 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:
@@ -42,5 +43,20 @@ class SubscribedPackagesModel(ListModel):
             except KeyError:  # There is no 'icon_url" in the response payload for this package
                 package.update({"icon_url": ""})
 
-            items.append(package)
-        self.setItems(items)
+            self._items.append(package)
+        self.setItems(self._items)
+        print(self._items)
+
+    def has_compatible_packages(self):
+        has_compatible_items  = False
+        for item in self._items:
+            if item['is_compatible'] == 'True':
+                has_compatible_items = True
+        return has_compatible_items
+
+    def has_incompatible_packages(self):
+        has_incompatible_items  = False
+        for item in self._items:
+            if item['is_compatible'] == 'False':
+                has_incompatible_items = True
+        return has_incompatible_items

+ 8 - 0
plugins/Toolbox/src/Toolbox.py

@@ -792,6 +792,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"].has_compatible_packages()
+
+    @pyqtProperty(bool, constant=True)
+    def has_incompatible_packages(self) -> str:
+        return self._models["subscribed_packages"].has_incompatible_packages()
+
     @pyqtProperty(QObject, constant = True)
     def packagesModel(self) -> PackagesModel:
         return cast(PackagesModel, self._models["packages"])