MissingPackageList.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) 2022 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional, TYPE_CHECKING, Dict, List
  4. from .Constants import PACKAGES_URL
  5. from .PackageModel import PackageModel
  6. from .RemotePackageList import RemotePackageList
  7. from PyQt6.QtCore import pyqtSignal, QObject, pyqtProperty, QCoreApplication
  8. from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To request the package list from the API.
  9. from UM.i18n import i18nCatalog
  10. if TYPE_CHECKING:
  11. from PyQt6.QtCore import QObject, pyqtProperty, pyqtSignal
  12. catalog = i18nCatalog("cura")
  13. class MissingPackageList(RemotePackageList):
  14. def __init__(self, packages_metadata: List[Dict[str, str]], parent: Optional["QObject"] = None) -> None:
  15. super().__init__(parent)
  16. self._packages_metadata: List[Dict[str, str]] = packages_metadata
  17. self._package_type_filter = "material"
  18. self._search_type = "package_ids"
  19. self._requested_search_string = ",".join(map(lambda package: package["id"], packages_metadata))
  20. def _parseResponse(self, reply: "QNetworkReply") -> None:
  21. super()._parseResponse(reply)
  22. # At the end of the list we want to show some information about packages the user is missing that can't be found
  23. # This will add cards with some information about the missing packages
  24. if not self.hasMore:
  25. self._addPackagesMissingFromRequest()
  26. def _addPackagesMissingFromRequest(self) -> None:
  27. """Create cards for packages the user needs to install that could not be found"""
  28. returned_packages_ids = [item["package"].packageId for item in self._items]
  29. for package_metadata in self._packages_metadata:
  30. if package_metadata["id"] not in returned_packages_ids:
  31. package = PackageModel.fromIncompletePackageInformation(package_metadata["display_name"], package_metadata["package_version"], self._package_type_filter)
  32. self.appendItem({"package": package})
  33. self.itemsChanged.emit()