diff --git a/plugins/Marketplace/PackageList.py b/plugins/Marketplace/PackageList.py index 8a70096802..df663a4bd4 100644 --- a/plugins/Marketplace/PackageList.py +++ b/plugins/Marketplace/PackageList.py @@ -1,7 +1,7 @@ # Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from PyQt5.QtCore import Qt +from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, Qt from typing import List, TYPE_CHECKING from UM.Qt.ListModel import ListModel @@ -20,10 +20,39 @@ class PackageList(ListModel): PackageRole = Qt.UserRole + 1 + ITEMS_PER_PAGE = 20 # Pagination of number of elements to download at once. + def __init__(self, parent: "QObject" = None): super().__init__(parent) self._packages: List[PackageModel] = [] + self.setIsLoading(True) + + self.requestFirst() + + def requestFirst(self) -> None: + """ + Make a request for the first paginated page of packages. + + When the request is done, the list will get updated with the new package models. + """ + self.setIsLoading(True) + + isLoadingChanged = pyqtSignal() + + @pyqtSlot(bool) + def setIsLoading(self, is_loading: bool) -> None: + if(is_loading != self._is_loading): + self._is_loading = is_loading + self.isLoadingChanged.emit() + + @pyqtProperty(bool, notify = isLoadingChanged, fset = setIsLoading) + def isLoading(self) -> bool: + """ + Gives whether the list is currently loading the first page or loading more pages. + :return: ``True`` if the list is downloading, or ``False`` if not downloading. + """ + return self._is_loading def _update(self) -> None: # TODO: Get list of packages from Marketplace class.