mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 13:35:56 +08:00
Add property to tell if the list is currently loading or loading more
We'll need to display a spinner of some kind in the front-end, I think. Contributes to issue CURA-8556.
This commit is contained in:
parent
0f5c923d93
commit
5851ad52c6
@ -1,7 +1,7 @@
|
|||||||
# Copyright (c) 2021 Ultimaker B.V.
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# 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 typing import List, TYPE_CHECKING
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
@ -20,10 +20,39 @@ class PackageList(ListModel):
|
|||||||
|
|
||||||
PackageRole = Qt.UserRole + 1
|
PackageRole = Qt.UserRole + 1
|
||||||
|
|
||||||
|
ITEMS_PER_PAGE = 20 # Pagination of number of elements to download at once.
|
||||||
|
|
||||||
def __init__(self, parent: "QObject" = None):
|
def __init__(self, parent: "QObject" = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._packages: List[PackageModel] = []
|
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:
|
def _update(self) -> None:
|
||||||
# TODO: Get list of packages from Marketplace class.
|
# TODO: Get list of packages from Marketplace class.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user