mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-30 04:15:12 +08:00

The server is queried using the local packages_id and version to determine if they can be updated. The Manage button state is set accordingly. This is done in an async way to keep the UI responsive A.t.m I'm not sure if I might need to move this logic out, since we also need to make this query when check periodically for updates. when the list is not shown. But that would also entail creating the installed packages list before the Manage Packages tab is ever created in the Marketplace. Contributes to: CURA-8587
56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
# Copyright (c) 2021 Ultimaker B.V.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
|
import os.path
|
|
from PyQt5.QtCore import pyqtSlot
|
|
from PyQt5.QtQml import qmlRegisterType
|
|
from typing import Optional, TYPE_CHECKING
|
|
|
|
from cura.ApplicationMetadata import CuraSDKVersion
|
|
from cura.CuraApplication import CuraApplication # Creating QML objects and managing packages.
|
|
from cura.UltimakerCloud import UltimakerCloudConstants
|
|
|
|
from UM.Extension import Extension # We are implementing the main object of an extension here.
|
|
from UM.PluginRegistry import PluginRegistry # To find out where we are stored (the proper way).
|
|
|
|
from .RemotePackageList import RemotePackageList # To register this type with QML.
|
|
from .LocalPackageList import LocalPackageList # To register this type with QML.
|
|
|
|
if TYPE_CHECKING:
|
|
from PyQt5.QtCore import QObject
|
|
|
|
ROOT_URL = f"{UltimakerCloudConstants.CuraCloudAPIRoot}/cura-packages/v{UltimakerCloudConstants.CuraCloudAPIVersion}/cura/v{CuraSDKVersion}" # Root of all Marketplace API requests.
|
|
PACKAGES_URL = f"{ROOT_URL}/packages" # URL to use for requesting the list of packages.
|
|
PACKAGE_UPDATES_URL = f"{PACKAGES_URL}/package-updates" # URL to use for requesting the list of packages that can be updated.
|
|
|
|
|
|
class Marketplace(Extension):
|
|
"""
|
|
The main managing object for the Marketplace plug-in.
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here.
|
|
|
|
qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList")
|
|
qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList")
|
|
|
|
@pyqtSlot()
|
|
def show(self) -> None:
|
|
"""
|
|
Opens the window of the Marketplace.
|
|
|
|
If the window hadn't been loaded yet into Qt, it will be created lazily.
|
|
"""
|
|
if self._window is None:
|
|
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
|
|
if plugin_path is None:
|
|
plugin_path = os.path.dirname(__file__)
|
|
path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml")
|
|
self._window = CuraApplication.getInstance().createQmlComponent(path, {})
|
|
if self._window is None: # Still None? Failed to load the QML then.
|
|
return
|
|
self._window.show()
|
|
self._window.requestActivate() # Bring window into focus, if it was already open in the background.
|