Make new Marktetplace react to 'get more materials'.

part of CURA-8588
This commit is contained in:
Remco Burema 2021-12-30 11:53:42 +01:00
parent b794ad6ed2
commit 1cdeaffab7
No known key found for this signature in database
GPG Key ID: 215C49431D43F98C
3 changed files with 33 additions and 9 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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")
}
}
}
}