Marketplace.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os.path
  4. from PyQt5.QtCore import pyqtSlot
  5. from PyQt5.QtQml import qmlRegisterType
  6. from typing import Optional, TYPE_CHECKING
  7. from cura.CuraApplication import CuraApplication # Creating QML objects and managing packages.
  8. from UM.Extension import Extension # We are implementing the main object of an extension here.
  9. from UM.PluginRegistry import PluginRegistry # To find out where we are stored (the proper way).
  10. from .RemotePackageList import RemotePackageList # To register this type with QML.
  11. from .LocalPackageList import LocalPackageList # To register this type with QML.
  12. from .RestartManager import RestartManager # To register this type with QML.
  13. if TYPE_CHECKING:
  14. from PyQt5.QtCore import QObject
  15. class Marketplace(Extension):
  16. """
  17. The main managing object for the Marketplace plug-in.
  18. """
  19. def __init__(self) -> None:
  20. super().__init__()
  21. self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here.
  22. self.plugin_registry: Optional[PluginRegistry] = None
  23. qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList")
  24. qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList")
  25. qmlRegisterType(RestartManager, "Marketplace", 1, 0, "RestartManager")
  26. @pyqtSlot()
  27. def show(self) -> None:
  28. """
  29. Opens the window of the Marketplace.
  30. If the window hadn't been loaded yet into Qt, it will be created lazily.
  31. """
  32. if self._window is None:
  33. self.plugin_registry = PluginRegistry.getInstance()
  34. plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
  35. if plugin_path is None:
  36. plugin_path = os.path.dirname(__file__)
  37. path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml")
  38. self._window = CuraApplication.getInstance().createQmlComponent(path, {})
  39. if self._window is None: # Still None? Failed to load the QML then.
  40. return
  41. self._window.show()
  42. self._window.requestActivate() # Bring window into focus, if it was already open in the background.