diff --git a/plugins/Marketplace/Marketplace.py b/plugins/Marketplace/Marketplace.py index 143469d82e..ea1f94be1d 100644 --- a/plugins/Marketplace/Marketplace.py +++ b/plugins/Marketplace/Marketplace.py @@ -2,7 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. import os.path -from PyQt5.QtCore import pyqtSlot +from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from PyQt5.QtQml import qmlRegisterType from typing import Optional, TYPE_CHECKING @@ -15,19 +15,33 @@ from .RemotePackageList import RemotePackageList # To register this type with Q from .LocalPackageList import LocalPackageList # To register this type with QML. from .RestartManager import RestartManager # To register this type with QML. -if TYPE_CHECKING: - from PyQt5.QtCore import QObject - class Marketplace(Extension): """ The main managing object for the Marketplace plug-in. """ + class TabManager(QObject): + def __init__(self) -> None: + super().__init__(parent=CuraApplication.getInstance()) + self._tab_shown = 0 + + def getTabShown(self): + return self._tab_shown + + def setTabShown(self, tab_shown): + if tab_shown != self._tab_shown: + self._tab_shown = tab_shown + self.tabShownChanged.emit() + + tabShownChanged = pyqtSignal() + tabShown = pyqtProperty(int, fget=getTabShown, fset=setTabShown, notify=tabShownChanged) + def __init__(self) -> None: super().__init__() self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here. self._plugin_registry: Optional[PluginRegistry] = None + self._tab_manager = Marketplace.TabManager() qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList") qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList") @@ -46,8 +60,17 @@ class Marketplace(Extension): 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, {}) + self._window = CuraApplication.getInstance().createQmlComponent(path, {"tabManager": self._tab_manager}) if self._window is None: # Still None? Failed to load the QML then. return + self._tab_manager.setTabShown(0) self._window.show() self._window.requestActivate() # Bring window into focus, if it was already open in the background. + + @pyqtSlot() + def setVisibleTabToMaterials(self) -> None: + """ + Set the tab shown to the remote materials one. + Not implemented in a more generic way because it needs the ability to be called with 'callExtensionMethod'. + """ + self._tab_manager.setTabShown(1) diff --git a/plugins/Marketplace/resources/qml/Marketplace.qml b/plugins/Marketplace/resources/qml/Marketplace.qml index 017a9e3dde..9027a02121 100644 --- a/plugins/Marketplace/resources/qml/Marketplace.qml +++ b/plugins/Marketplace/resources/qml/Marketplace.qml @@ -25,7 +25,6 @@ Window onVisibleChanged: { - pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab. while(contextStack.depth > 1) { contextStack.pop(); //Do NOT use the StackView.Immediate transition here, since it causes the window to stay empty. Seemingly a Qt bug: https://bugreports.qt.io/browse/QTBUG-60670? @@ -131,9 +130,11 @@ Window height: UM.Theme.getSize("button_icon").height spacing: 0 background: Rectangle { color: "transparent" } + currentIndex: tabManager.tabShown onCurrentIndexChanged: { + tabManager.tabShown = currentIndex searchBar.text = ""; searchBar.visible = currentItem.hasSearch; content.source = currentItem.sourcePage; diff --git a/resources/qml/MainWindow/ApplicationMenu.qml b/resources/qml/MainWindow/ApplicationMenu.qml index b0dabd42cc..497c5e1541 100644 --- a/resources/qml/MainWindow/ApplicationMenu.qml +++ b/resources/qml/MainWindow/ApplicationMenu.qml @@ -212,8 +212,8 @@ Item target: Cura.Actions.marketplaceMaterials function onTriggered() { - curaExtensions.callExtensionMethod("Toolbox", "launch") - curaExtensions.callExtensionMethod("Toolbox", "setViewCategoryToMaterials") + curaExtensions.callExtensionMethod("Marketplace", "show") + curaExtensions.callExtensionMethod("Marketplace", "setVisibleTabToMaterials") } } -} \ No newline at end of file +}