mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Moved stateManageButton logic out of the packageModel
Contributes to: CURA-8587
This commit is contained in:
parent
59470814e2
commit
51a77f683d
4 changed files with 37 additions and 71 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue