From 5897b3de3841c4ca6695090234d3c780efc73ec7 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Oct 2021 13:43:41 +0200 Subject: [PATCH] Add function to open Marketplace window This will now load in a QML file, cache it, and create an empty window with the title 'Marketplace'. Contributes to issue CURA-8556. --- plugins/Marketplace/Marketplace.py | 37 +++++++++++++++++-- .../Marketplace/resources/qml/Marketplace.qml | 21 +++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 plugins/Marketplace/resources/qml/Marketplace.qml diff --git a/plugins/Marketplace/Marketplace.py b/plugins/Marketplace/Marketplace.py index a113e46597..5fd976cbfc 100644 --- a/plugins/Marketplace/Marketplace.py +++ b/plugins/Marketplace/Marketplace.py @@ -1,10 +1,41 @@ # Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from UM.PluginObject import PluginObject +import os.path +from PyQt5.QtCore import pyqtSlot +from typing import Optional, TYPE_CHECKING -class Marketplace(PluginObject): +from cura.CuraApplication import CuraApplication # Creating QML objects and managing packages. +from UM.Extension import Extension # We are implementing the main object of an extension here. +from UM.Logger import Logger +from UM.PluginRegistry import PluginRegistry # To find out where we are stored (the proper way). + +if TYPE_CHECKING: + from PyQt5.QtCore import QObject + +class Marketplace(Extension): """ The main managing object for the Marketplace plug-in. """ - pass # TODO \ No newline at end of file + + def __init__(self): + super().__init__() + self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here. + + @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. + Logger.error(f"Failed to load QML for Marketplace window.") + return + self._window.show() \ No newline at end of file diff --git a/plugins/Marketplace/resources/qml/Marketplace.qml b/plugins/Marketplace/resources/qml/Marketplace.qml new file mode 100644 index 0000000000..96b13d5522 --- /dev/null +++ b/plugins/Marketplace/resources/qml/Marketplace.qml @@ -0,0 +1,21 @@ +// Copyright (c) 2021 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.15 +import QtQuick.Window 2.2 + +import UM 1.2 as UM + +Window +{ + id: marketplaceDialog + property variant catalog: UM.I18nCatalog { name: "cura" } + + minimumWidth: UM.Theme.getSize("modal_window_minimum").width + minimumHeight: UM.Theme.getSize("modal_window_minimum").height + width: minimumWidth + height: minimumHeight + + title: "Marketplace" //Seen by Ultimaker as a brand name, so this doesn't get translated. + modality: Qt.NonModal +} \ No newline at end of file