mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Make new Marktetplace react to 'get more materials'.
part of CURA-8588
This commit is contained in:
parent
b794ad6ed2
commit
1cdeaffab7
@ -2,7 +2,7 @@
|
|||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from PyQt5.QtCore import pyqtSlot
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
|
||||||
from PyQt5.QtQml import qmlRegisterType
|
from PyQt5.QtQml import qmlRegisterType
|
||||||
from typing import Optional, TYPE_CHECKING
|
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 .LocalPackageList import LocalPackageList # To register this type with QML.
|
||||||
from .RestartManager import RestartManager # 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):
|
class Marketplace(Extension):
|
||||||
"""
|
"""
|
||||||
The main managing object for the Marketplace plug-in.
|
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:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._window: Optional["QObject"] = None # If the window has been loaded yet, it'll be cached in here.
|
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._plugin_registry: Optional[PluginRegistry] = None
|
||||||
|
self._tab_manager = Marketplace.TabManager()
|
||||||
|
|
||||||
qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList")
|
qmlRegisterType(RemotePackageList, "Marketplace", 1, 0, "RemotePackageList")
|
||||||
qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList")
|
qmlRegisterType(LocalPackageList, "Marketplace", 1, 0, "LocalPackageList")
|
||||||
@ -46,8 +60,17 @@ class Marketplace(Extension):
|
|||||||
if plugin_path is None:
|
if plugin_path is None:
|
||||||
plugin_path = os.path.dirname(__file__)
|
plugin_path = os.path.dirname(__file__)
|
||||||
path = os.path.join(plugin_path, "resources", "qml", "Marketplace.qml")
|
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.
|
if self._window is None: # Still None? Failed to load the QML then.
|
||||||
return
|
return
|
||||||
|
self._tab_manager.setTabShown(0)
|
||||||
self._window.show()
|
self._window.show()
|
||||||
self._window.requestActivate() # Bring window into focus, if it was already open in the background.
|
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)
|
||||||
|
@ -25,7 +25,6 @@ Window
|
|||||||
|
|
||||||
onVisibleChanged:
|
onVisibleChanged:
|
||||||
{
|
{
|
||||||
pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab.
|
|
||||||
while(contextStack.depth > 1)
|
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?
|
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
|
height: UM.Theme.getSize("button_icon").height
|
||||||
spacing: 0
|
spacing: 0
|
||||||
background: Rectangle { color: "transparent" }
|
background: Rectangle { color: "transparent" }
|
||||||
|
currentIndex: tabManager.tabShown
|
||||||
|
|
||||||
onCurrentIndexChanged:
|
onCurrentIndexChanged:
|
||||||
{
|
{
|
||||||
|
tabManager.tabShown = currentIndex
|
||||||
searchBar.text = "";
|
searchBar.text = "";
|
||||||
searchBar.visible = currentItem.hasSearch;
|
searchBar.visible = currentItem.hasSearch;
|
||||||
content.source = currentItem.sourcePage;
|
content.source = currentItem.sourcePage;
|
||||||
|
@ -212,8 +212,8 @@ Item
|
|||||||
target: Cura.Actions.marketplaceMaterials
|
target: Cura.Actions.marketplaceMaterials
|
||||||
function onTriggered()
|
function onTriggered()
|
||||||
{
|
{
|
||||||
curaExtensions.callExtensionMethod("Toolbox", "launch")
|
curaExtensions.callExtensionMethod("Marketplace", "show")
|
||||||
curaExtensions.callExtensionMethod("Toolbox", "setViewCategoryToMaterials")
|
curaExtensions.callExtensionMethod("Marketplace", "setVisibleTabToMaterials")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user