Просмотр исходного кода

Persistent handled state across Package Lists

Contributes to: CURA-8587
Jelle Spijker 3 лет назад
Родитель
Сommit
325783ca46

+ 4 - 1
plugins/Marketplace/LocalPackageList.py

@@ -57,10 +57,13 @@ class LocalPackageList(PackageList):
 
     def _makePackageModel(self, package_info: Dict[str, Any]) -> PackageModel:
         """ Create a PackageModel from the package_info and determine its section_title"""
-        bundled_or_installed = "installed" if self._manager.isUserInstalledPackage(package_info["package_id"]) else "bundled"
+
+        bundled_or_installed = "bundled" if self._manager.isBundledPackage(package_info["package_id"]) else "installed"
         package_type = package_info["package_type"]
         section_title = self.PACKAGE_CATEGORIES[bundled_or_installed][package_type]
         package = PackageModel(package_info, section_title = section_title, parent = self)
+        if package_info["package_id"] in self._manager.getPackagesToRemove() or package_info["package_id"] in self._manager.getPackagesToInstall():
+            package.is_recently_managed = True
         self._connectManageButtonSignals(package)
         return package
 

+ 7 - 4
plugins/Marketplace/PackageList.py

@@ -4,7 +4,7 @@ import tempfile
 import json
 
 from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, Qt
-from typing import Dict, Optional, TYPE_CHECKING
+from typing import Dict, Optional, Set, TYPE_CHECKING
 
 from UM.i18n import i18nCatalog
 from UM.Qt.ListModel import ListModel
@@ -43,6 +43,7 @@ class PackageList(ListModel):
         self._has_footer = True
         self._to_install: Dict[str, str] = {}
         self.canInstallChanged.connect(self._install)
+        self._local_packages: Set[str] = {p["package_id"] for p in self._manager.local_packages}
 
         self._ongoing_request: Optional[HttpRequestData] = None
         self._scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))
@@ -128,7 +129,8 @@ class PackageList(ListModel):
         if update:
             package.is_updating = False
         else:
-            package.is_recently_installed = True
+            Logger.debug(f"Setting recently installed for package: {package_id}")
+            package.is_recently_managed = True
             package.is_installing = False
         self.subscribeUserToPackage(package_id, str(package.sdk_version))
 
@@ -201,7 +203,7 @@ class PackageList(ListModel):
         package.is_installing = True
         url = package.download_url
         Logger.debug(f"Trying to download and install {package_id} from {url}")
-        self.download(package_id, url)
+        self.download(package_id, url, False)
 
     @pyqtSlot(str)
     def uninstallPackage(self, package_id: str) -> None:
@@ -209,8 +211,9 @@ class PackageList(ListModel):
         package = self.getPackageModel(package_id)
         package.is_installing = True
         self._manager.removePackage(package_id)
-        package.is_installing = False
         self.unsunscribeUserFromPackage(package_id)
+        package.is_installing = False
+        package.is_recently_managed = True
 
     @pyqtSlot(str)
     def updatePackage(self, package_id: str) -> None:

+ 14 - 4
plugins/Marketplace/PackageModel.py

@@ -62,7 +62,7 @@ class PackageModel(QObject):
             self._icon_url = author_data.get("icon_url", "")
 
         self._is_installing = False
-        self.is_recently_installed = False
+        self._is_recently_managed = False
         self._can_update = False
         self._is_updating = False
         self._is_enabling = False
@@ -284,7 +284,7 @@ class PackageModel(QObject):
     def stateManageEnableButton(self) -> str:
         if self._is_enabling:
             return "busy"
-        if self.is_recently_installed:
+        if self._is_recently_managed:
             return "hidden"
         if self._package_type == "material":
             if self._is_bundled:  # TODO: Check if a bundled material can/should be un-/install en-/disabled
@@ -312,8 +312,8 @@ class PackageModel(QObject):
     def stateManageInstallButton(self) -> str:
         if self._is_installing:
             return "busy"
-        if self.is_recently_installed:
-            return "secondary"
+        if self._is_recently_managed:
+            return "hidden"
         if self._is_installed:
             if self._is_bundled:
                 return "hidden"
@@ -322,6 +322,16 @@ class PackageModel(QObject):
         else:
             return "primary"
 
+    @property
+    def is_recently_managed(self) -> bool:
+        return self._is_recently_managed
+
+    @is_recently_managed.setter
+    def is_recently_managed(self, value: bool) -> None:
+        if value != self._is_recently_managed:
+            self._is_recently_managed = value
+            self.stateManageButtonChanged.emit()
+
     @property
     def is_installing(self) -> bool:
         return self._is_installing

+ 1 - 2
plugins/Marketplace/RemotePackageList.py

@@ -3,7 +3,7 @@
 
 from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot
 from PyQt5.QtNetwork import QNetworkReply
-from typing import Optional, Set, TYPE_CHECKING
+from typing import Optional, TYPE_CHECKING
 
 from UM.i18n import i18nCatalog
 from UM.Logger import Logger
@@ -31,7 +31,6 @@ class RemotePackageList(PackageList):
         self._request_url = self._initialRequestUrl()
         self.isLoadingChanged.connect(self._onLoadingChanged)
         self.isLoadingChanged.emit()
-        self._local_packages: Set[str] = { p["package_id"] for p in self._manager.local_packages }
 
     def __del__(self) -> None:
         """

+ 0 - 2
plugins/Marketplace/resources/qml/ManageButton.qml

@@ -21,8 +21,6 @@ RowLayout
 
     signal clicked(bool primary_action)
 
-    state: busy ? "busy" : mainState
-
     Cura.PrimaryButton
     {
         id: primaryButton