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)

View File

@ -5,7 +5,6 @@ import json
import os
import tempfile
import platform
import functools
from typing import cast, Any, Dict, List, Set, TYPE_CHECKING, Tuple, Optional, Union
from PyQt5.QtCore import QUrl, QObject, pyqtProperty, pyqtSignal, pyqtSlot
@ -665,10 +664,8 @@ class Toolbox(QObject, Extension):
Logger.log("e", "Could not find the %s model.", response_type)
break
# Workaround: Do not add Metadata for "subscribed_packages" check JUST YET
if response_type != "subscribed_packages":
self._server_response_data[response_type] = json_data["data"]
self._models[response_type].setMetadata(self._server_response_data[response_type])
self._server_response_data[response_type] = json_data["data"]
self._models[response_type].setMetadata(self._server_response_data[response_type])
if response_type == "packages":
self._models[response_type].setFilter({"type": "plugin"})
@ -708,6 +705,8 @@ class Toolbox(QObject, Extension):
# We check if there are packages installed in Cloud Marketplace but not in Cura marketplace (discrepancy)
package_discrepancy = list(set(user_subscribed_packages).difference(user_installed_packages))
if package_discrepancy:
self._models["subscribed_packages"].addValue(package_discrepancy)
self._models["subscribed_packages"].update()
Logger.log("d", "Discrepancy found between Cloud subscribed packages and Cura installed packages")
sync_message = Message(i18n_catalog.i18nc(
"@info:generic",
@ -720,31 +719,11 @@ class Toolbox(QObject, Extension):
description="Sync your Cloud subscribed packages to your local environment.",
button_align=Message.ActionButtonAlignment.ALIGN_RIGHT)
self._onSyncButtonClickedHelper = functools.partial(self._onSyncButtonClicked, json_data, package_discrepancy)
sync_message.actionTriggered.connect(self._onSyncButtonClickedHelper)
sync_message.actionTriggered.connect(self._onSyncButtonClicked)
sync_message.show()
def _onSyncButtonClicked(self, json_data, package_discrepancy, sync_message: Message, actionId: str) -> None:
def _onSyncButtonClicked(self, sync_message: Message, sync_message_action: str) -> None:
sync_message.hide()
self.subscribed_packages.clear()
# We 'create' the packages from the HTTP payload
for item in json_data:
if item["package_id"] not in package_discrepancy: # But we skip packages that the user has locally installed
continue
package = {"name": item["package_id"], "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": ""})
self.subscribed_packages.append(package)
Logger.log("d", "Package '{}' scheduled for installing.".format(package['name']))
self._models["subscribed_packages"].update()
compatibility_dialog_path = "resources/qml/dialogs/CompatibilityDialog.qml"
plugin_path_prefix = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
if plugin_path_prefix: