Browse Source

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

Contributes to CURA-8587
Jelle Spijker 3 years ago
parent
commit
8abeb24ccc

+ 10 - 0
plugins/Marketplace/LocalPackageList.py

@@ -41,11 +41,21 @@ class LocalPackageList(PackageList):
         self._has_footer = False
         self._ongoing_requests["check_updates"] = None
         self._package_manager.packagesWithUpdateChanged.connect(self._sortSectionsOnUpdate)
+        self._package_manager.packageUninstalled.connect(self._removePackageModel)
 
     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"]))
         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()
     def updatePackages(self) -> None:
         """Update the list with local packages, these are materials or plugin, either bundled or user installed. The list

+ 0 - 1
plugins/Marketplace/PackageList.py

@@ -47,7 +47,6 @@ class PackageList(ListModel):
         self._has_footer = True
         self._to_install: Dict[str, str] = {}
         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._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))

+ 1 - 1
plugins/Marketplace/RemotePackageList.py

@@ -118,7 +118,7 @@ class RemotePackageList(PackageList):
 
         for package_data in response_data["data"]:
             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
             try:
                 package = PackageModel(package_data, parent = self)