Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Spijker <spijker.jelle@gmail.com>2021-12-09 11:56:41 +0300
committerJelle Spijker <spijker.jelle@gmail.com>2021-12-09 11:56:41 +0300
commit51a77f683dc0b227089825af9c3235d557a56ba4 (patch)
tree43f3c8f14ebca2f447f8d5601e106814bd29d685
parent59470814e2be076e10afa717190a4e39fe267a6e (diff)
Moved stateManageButton logic out of the packageModel
Contributes to: CURA-8587
-rw-r--r--cura/CuraPackageManager.py13
-rw-r--r--plugins/Marketplace/PackageList.py24
-rw-r--r--plugins/Marketplace/PackageModel.py59
-rw-r--r--plugins/Marketplace/resources/qml/PackageCardHeader.qml12
4 files changed, 37 insertions, 71 deletions
diff --git a/cura/CuraPackageManager.py b/cura/CuraPackageManager.py
index bca6494f37..386d249925 100644
--- a/cura/CuraPackageManager.py
+++ b/cura/CuraPackageManager.py
@@ -1,7 +1,7 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
-from typing import Any, cast, Dict, List, Tuple, TYPE_CHECKING, Optional
+from typing import Any, cast, Dict, List, Set, Tuple, TYPE_CHECKING, Optional
from cura.CuraApplication import CuraApplication # To find some resource types.
from cura.Settings.GlobalStack import GlobalStack
@@ -20,10 +20,12 @@ class CuraPackageManager(PackageManager):
def __init__(self, application: "QtApplication", parent: Optional["QObject"] = None) -> None:
super().__init__(application, parent)
self._local_packages: Optional[List[Dict[str, Any]]] = None
+ self._local_packages_id: Optional[Set[str]] = None
self.installedPackagesChanged.connect(self._updateLocalPackages)
def _updateLocalPackages(self) -> None:
self._local_packages = self.getAllLocalPackages()
+ self._local_packages_id = set(pkg["package_id"] for pkg in self._local_packages)
@property
def local_packages(self) -> List[Dict[str, Any]]:
@@ -34,6 +36,15 @@ class CuraPackageManager(PackageManager):
# It's guaranteed to be a list now.
return cast(List[Dict[str, Any]], self._local_packages)
+ @property
+ def local_packages_id(self) -> Set[str]:
+ """locally installed packages, lazy execution"""
+ if self._local_packages_id is None:
+ self._updateLocalPackages()
+ # _updateLocalPackages always results in a list of packages, not None.
+ # It's guaranteed to be a list now.
+ return cast(Set[str], self._local_packages_id)
+
def initialize(self) -> None:
self._installation_dirs_dict["materials"] = Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer)
self._installation_dirs_dict["qualities"] = Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer)
diff --git a/plugins/Marketplace/PackageList.py b/plugins/Marketplace/PackageList.py
index e6e5e78ba9..4271166318 100644
--- a/plugins/Marketplace/PackageList.py
+++ b/plugins/Marketplace/PackageList.py
@@ -184,7 +184,6 @@ class PackageList(ListModel):
to_be_installed = self._manager.installPackage(package_path) is not None
package = self.getPackageModel(package_id)
# TODO handle failure
- package.isRecentlyInstalledChanged.emit(update)
self.subscribeUserToPackage(package_id, str(package.sdk_version))
def download(self, package_id: str, url: str, update: bool = False) -> None:
@@ -268,8 +267,8 @@ class PackageList(ListModel):
package.installPackageTriggered.connect(self.installPackage)
package.uninstallPackageTriggered.connect(self.uninstallPackage)
package.updatePackageTriggered.connect(self.updatePackage)
- package.enablePackageTriggered.connect(self.enablePackage)
- package.disablePackageTriggered.connect(self.disablePackage)
+ package.enablePackageTriggered.connect(self._plugin_registry.enablePlugin)
+ package.disablePackageTriggered.connect(self._plugin_registry.disablePlugin)
def installPackage(self, package_id: str) -> None:
"""Install a package from the Marketplace
@@ -288,7 +287,6 @@ class PackageList(ListModel):
package = self.getPackageModel(package_id)
self._manager.removePackage(package_id)
self.unsunscribeUserFromPackage(package_id)
- package.isRecentlyInstalledChanged.emit(False)
def updatePackage(self, package_id: str) -> None:
"""Update a package from the Marketplace
@@ -299,21 +297,3 @@ class PackageList(ListModel):
self._manager.removePackage(package_id, force_add = True)
url = package.download_url
self.download(package_id, url, True)
-
- def enablePackage(self, package_id: str) -> None:
- """Enable a package in the plugin registry
-
- :param package_id: the package identification string
- """
- package = self.getPackageModel(package_id)
- self._plugin_registry.enablePlugin(package_id)
- package.is_active = True
-
- def disablePackage(self, package_id: str) -> None:
- """Disable a package in the plugin registry
-
- :param package_id: the package identification string
- """
- package = self.getPackageModel(package_id)
- self._plugin_registry.disablePlugin(package_id)
- package.is_active = False
diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py
index 9996a8e1df..6d20cd7f91 100644
--- a/plugins/Marketplace/PackageModel.py
+++ b/plugins/Marketplace/PackageModel.py
@@ -3,22 +3,21 @@
import re
from enum import Enum
-from typing import Any, Dict, List, Optional
+from typing import Any, cast, Dict, List, Optional
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
from cura.CuraApplication import CuraApplication
+from cura.CuraPackageManager import CuraPackageManager
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To get names of materials we're compatible with.
from UM.i18n import i18nCatalog # To translate placeholder names if data is not present.
+from UM.PluginRegistry import PluginRegistry
catalog = i18nCatalog("cura")
class PackageModel(QObject):
"""
Represents a package, containing all the relevant information to be displayed about a package.
-
- Effectively this behaves like a glorified named tuple, but as a QObject so that its properties can be obtained from
- QML. The model can also be constructed directly from a response received by the API.
"""
def __init__(self, package_data: Dict[str, Any], section_title: Optional[str] = None, parent: Optional[QObject] = None) -> None:
@@ -29,10 +28,11 @@ class PackageModel(QObject):
:param parent: The parent QML object that controls the lifetime of this model (normally a PackageList).
"""
super().__init__(parent)
+ self._package_manager: CuraPackageManager = cast(CuraPackageManager, CuraApplication.getInstance().getPackageManager())
+ self._plugin_registry: PluginRegistry = CuraApplication.getInstance().getPluginRegistry()
+
self._package_id = package_data.get("package_id", "UnknownPackageId")
self._package_type = package_data.get("package_type", "")
- self._is_installed = package_data.get("is_installed", False)
- self._is_active = package_data.get("is_active", False)
self._is_bundled = package_data.get("is_bundled", False)
self._icon_url = package_data.get("icon_url", "")
self._display_name = package_data.get("display_name", catalog.i18nc("@label:property", "Unknown Package"))
@@ -89,13 +89,11 @@ class PackageModel(QObject):
self.updatePackageTriggered.connect(update_clicked)
- def finished_installed(is_updating):
- if is_updating:
- self.setIsUpdating(False)
- else:
- self.setIsInstalling(False)
+ def finished_installed():
+ self.setIsUpdating(False)
+ self.setIsInstalling(False)
- self.isRecentlyInstalledChanged.connect(finished_installed)
+ self._package_manager.installedPackagesChanged.connect(finished_installed)
def __eq__(self, other: object):
if isinstance(other, PackageModel):
@@ -313,30 +311,9 @@ class PackageModel(QObject):
isRecentlyInstalledChanged = pyqtSignal(bool)
- # --- enabling ---
-
- @pyqtProperty(bool, notify = stateManageButtonChanged)
- def stateManageEnableButton(self) -> bool:
- """The state of the manage Enable Button of this package"""
- return not (self._is_installed and self._is_active)
-
- @property
- def is_active(self) -> bool:
- """Flag if the package is currently active"""
- return self._is_active
-
- @is_active.setter
- def is_active(self, value: bool) -> None:
- if value != self._is_active:
- self._is_active = value
- self.stateManageButtonChanged.emit()
-
- # --- Installing ---
-
@pyqtProperty(bool, notify = stateManageButtonChanged)
- def stateManageInstallButton(self) -> bool:
- """The state of the Manage Install package card"""
- return not self._is_installed
+ def isActive(self):
+ return not self._package_id in self._plugin_registry.getDisabledPlugins()
def setIsInstalling(self, value: bool) -> None:
if value != self._is_installing:
@@ -358,15 +335,15 @@ class PackageModel(QObject):
@pyqtProperty(bool, notify = stateManageButtonChanged)
def isInstalled(self) -> bool:
- return self._package_id in CuraApplication.getInstance().getPackageManager().local_packages
+ return self._package_id in self._package_manager.local_packages_id
@pyqtProperty(bool, notify = stateManageButtonChanged)
def isRecentlyInstalled(self) -> bool:
- return self._package_id in CuraApplication.getInstance().getPackageManager().getPackagesToInstall() or self._package_id in CuraApplication.getInstance().getPackageManager().getPackagesToRemove()
+ return self._package_id in self._package_manager.getPackagesToInstall()
@pyqtProperty(bool, notify = stateManageButtonChanged)
- def isUninstalled(self) -> bool:
- return self._package_id in CuraApplication.getInstance().getPackageManager().getPackagesToRemove()
+ def isRecentlyUninstalled(self) -> bool:
+ return self._package_id in self._package_manager.getPackagesToRemove()
def setCanDowngrade(self, value: bool) -> None:
if value != self._can_downgrade:
@@ -378,8 +355,6 @@ class PackageModel(QObject):
"""Flag if the installed package can be downgraded to a bundled version"""
return self._can_downgrade
- # --- Updating ---
-
def setIsUpdating(self, value):
if value != self._is_updating:
self._is_updating = value
@@ -391,7 +366,7 @@ class PackageModel(QObject):
@pyqtProperty(bool, notify = stateManageButtonChanged)
def isRecentlyUpdated(self):
- return self._package_id in CuraApplication.getInstance().getPackageManager().getPackagesToInstall() and self._package_id in CuraApplication.getInstance().getPackageManager().getPackagesToRemove()
+ return self._package_id in self._package_manager.getPackagesToInstall() and self._package_id in self._package_manager.getPackagesToRemove()
@property
def can_update(self) -> bool:
diff --git a/plugins/Marketplace/resources/qml/PackageCardHeader.qml b/plugins/Marketplace/resources/qml/PackageCardHeader.qml
index 5859fbcd8e..4964338ab2 100644
--- a/plugins/Marketplace/resources/qml/PackageCardHeader.qml
+++ b/plugins/Marketplace/resources/qml/PackageCardHeader.qml
@@ -187,7 +187,7 @@ Item
busy: false
confirmed: false
- button_style: packageData.stateManageEnableButton
+ button_style: packageData.isInstalled && packageData.isActive
Layout.alignment: Qt.AlignTop
text: packageData.stateManageEnableButton ? catalog.i18nc("@button", "Enable") : catalog.i18nc("@button", "Disable")
@@ -213,23 +213,23 @@ Item
enabled: !packageData.isUpdating
busy: packageData.isInstalling
- confirmed: packageData.isRecentlyInstalled
+ confirmed: packageData.isRecentlyInstalled || packageData.isRecentlyUninstalled
- button_style: packageData.stateManageInstallButton
+ button_style: !packageData.isInstalled
Layout.alignment: Qt.AlignTop
text:
{
- if (packageData.stateManageInstallButton)
+ if (packageData.isRecentlyInstalled) { return catalog.i18nc("@button", "Installed"); }
+ if (packageData.isRecentlyUninstalled) { return catalog.i18nc("@button", "Uninstalled"); }
+ if (button_style)
{
if (packageData.isInstalling) { return catalog.i18nc("@button", "Installing..."); }
- else if (packageData.isRecentlyInstalled) { return catalog.i18nc("@button", "Installed"); }
else { return catalog.i18nc("@button", "Install"); }
}
else
{
if (packageData.isInstalling) { return catalog.i18nc("@button", "Uninstalling..."); }
- else if (packageData.isUninstalled) { return catalog.i18nc("@button", "Uninstalled"); }
else { return catalog.i18nc("@button", "Uninstall"); }
}
}