Removed the 'workaround' that I've added earlier. Simplified the flow. The dialog is now showing display_name instead of package_id

CURA-7038
This commit is contained in:
Dimitriovski 2019-12-31 14:02:41 +01:00
parent 96311c974b
commit dde0dd8ce3
No known key found for this signature in database
GPG key ID: 4E62757E2B0D304D
2 changed files with 38 additions and 33 deletions

View file

@ -1,20 +1,46 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import Qt
from UM.Qt.ListModel import ListModel
from UM.PluginRegistry import PluginRegistry
from cura import ApplicationMetadata
## Model that holds Cura packages. By setting the filter property the instances held by this model can be changed.
class SubscribedPackagesModel(ListModel):
def __init__(self, parent = None):
super().__init__(parent)
self._metadata = None
self._discrepancies = None
self._sdk_version = ApplicationMetadata.CuraSDKVersion
self.addRoleName(Qt.UserRole + 1, "name")
self.addRoleName(Qt.UserRole + 2, "icon_url")
self.addRoleName(Qt.UserRole + 3, "is_compatible")
def setMetadata(self, data):
if self._metadata != data:
self._metadata = data
def addValue(self, discrepancy):
if self._discrepancies != discrepancy:
self._discrepancies = discrepancy
def update(self):
toolbox = PluginRegistry.getInstance().getPluginObject("Toolbox")
self.setItems(toolbox.subscribed_packages)
items = []
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"})
else:
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)