Remove a recently installed and then uninstalled package from the manage list

Contributes to CURA-8587
This commit is contained in:
Jelle Spijker 2021-12-16 12:21:36 +01:00
parent 62c6af1ef3
commit 8abeb24ccc
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
3 changed files with 11 additions and 2 deletions

View file

@ -41,11 +41,21 @@ class LocalPackageList(PackageList):
self._has_footer = False self._has_footer = False
self._ongoing_requests["check_updates"] = None self._ongoing_requests["check_updates"] = None
self._package_manager.packagesWithUpdateChanged.connect(self._sortSectionsOnUpdate) self._package_manager.packagesWithUpdateChanged.connect(self._sortSectionsOnUpdate)
self._package_manager.packageUninstalled.connect(self._removePackageModel)
def _sortSectionsOnUpdate(self) -> None: def _sortSectionsOnUpdate(self) -> None:
SECTION_ORDER = dict(zip([i for k, v in self.PACKAGE_CATEGORIES.items() for i in self.PACKAGE_CATEGORIES[k].values()], ["a", "b", "c", "d"])) SECTION_ORDER = dict(zip([i for k, v in self.PACKAGE_CATEGORIES.items() for i in self.PACKAGE_CATEGORIES[k].values()], ["a", "b", "c", "d"]))
self.sort(lambda model: f"{SECTION_ORDER[model.sectionTitle]}_{model._can_update}_{model.displayName}".lower(), key = "package") self.sort(lambda model: f"{SECTION_ORDER[model.sectionTitle]}_{model._can_update}_{model.displayName}".lower(), key = "package")
def _removePackageModel(self, package_id):
if package_id not in self._package_manager.local_packages_ids:
index = self.find("package", package_id)
if index < 0:
Logger.error(f"Could not find card in Listview corresponding with {package_id}")
self.updatePackages()
return
self.removeItem(index)
@pyqtSlot() @pyqtSlot()
def updatePackages(self) -> None: def updatePackages(self) -> None:
"""Update the list with local packages, these are materials or plugin, either bundled or user installed. The list """Update the list with local packages, these are materials or plugin, either bundled or user installed. The list

View file

@ -47,7 +47,6 @@ class PackageList(ListModel):
self._has_footer = True self._has_footer = True
self._to_install: Dict[str, str] = {} self._to_install: Dict[str, str] = {}
self.canInstallChanged.connect(self._requestInstall) self.canInstallChanged.connect(self._requestInstall)
self._local_packages: Set[str] = {p["package_id"] for p in self._package_manager.local_packages}
self._ongoing_requests: Dict[str, Optional[HttpRequestData]] = {"download_package": None} self._ongoing_requests: Dict[str, Optional[HttpRequestData]] = {"download_package": None}
self._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance())) self._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))

View file

@ -118,7 +118,7 @@ class RemotePackageList(PackageList):
for package_data in response_data["data"]: for package_data in response_data["data"]:
package_id = package_data["package_id"] package_id = package_data["package_id"]
if package_id in self._local_packages: if package_id in self._package_manager.local_packages_ids:
continue # We should only show packages which are not already installed continue # We should only show packages which are not already installed
try: try:
package = PackageModel(package_data, parent = self) package = PackageModel(package_data, parent = self)