mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-05 13:03:59 -06: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 changed files with 30 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue