diff --git a/DiscoverUM3Action.py b/DiscoverUM3Action.py index 7115822582..747b568e25 100644 --- a/DiscoverUM3Action.py +++ b/DiscoverUM3Action.py @@ -1,8 +1,13 @@ from cura.MachineAction import MachineAction from UM.Application import Application +from UM.PluginRegistry import PluginRegistry +from UM.Logger import Logger -from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot +from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QUrl, QObject +from PyQt5.QtQml import QQmlComponent, QQmlContext + +import os.path from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") @@ -14,6 +19,12 @@ class DiscoverUM3Action(MachineAction): self._network_plugin = None + self._context = None + self._additional_component = None + self._additional_components_view = None + + Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView) + printersChanged = pyqtSignal() @pyqtSlot() @@ -68,4 +79,18 @@ class DiscoverUM3Action(MachineAction): if "um_network_key" in meta_data: return global_container_stack.getMetaDataEntry("um_network_key") - return "" \ No newline at end of file + return "" + + def _createAdditionalComponentsView(self): + Logger.log("d", "Creating additional ui components for UM3.") + + path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("JediWifiPrintingPlugin"), "UM3InfoComponents.qml")) + self._additional_component = QQmlComponent(Application.getInstance()._engine, path) + + # We need access to engine (although technically we can't) + self._context = QQmlContext(Application.getInstance()._engine.rootContext()) + self._context.setContextProperty("manager", self) + self._additional_components_view = self._additional_component.create(self._context) + + Application.getInstance().addAdditionalComponent("monitorButtons", self._additional_components_view.findChild(QObject, "networkPrinterConnectButton")) + Application.getInstance().addAdditionalComponent("machinesDetailPane", self._additional_components_view.findChild(QObject, "networkPrinterConnectionInfo")) diff --git a/UM3InfoComponents.qml b/UM3InfoComponents.qml new file mode 100644 index 0000000000..0106c8cffa --- /dev/null +++ b/UM3InfoComponents.qml @@ -0,0 +1,76 @@ +import UM 1.2 as UM +import Cura 1.0 as Cura + +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Window 2.1 + +Item +{ + id: base + + property bool isUM3: Cura.MachineManager.activeDefinitionId == "ultimaker3" + property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0 + property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands + + Row + { + objectName: "networkPrinterConnectButton" + visible: isUM3 + spacing: UM.Theme.getSize("default_marging").width + + Button + { + height: UM.Theme.getSize("save_button_save_to_button").height + tooltip: catalog.i18nc("@info:tooltip", "Send access request to the printer") + text: catalog.i18nc("@action:button", "Request Access") + style: UM.Theme.styles.sidebar_action_button + onClicked: Cura.MachineManager.printerOutputDevices[0].requestAuthentication() + visible: base.printerConnected && !base.printerAcceptsCommands + } + + Button + { + height: UM.Theme.getSize("save_button_save_to_button").height + tooltip: catalog.i18nc("@info:tooltip", "Connect to a printer") + text: catalog.i18nc("@action:button", "Connect") + style: UM.Theme.styles.sidebar_action_button + onClicked: connectActionDialog.show() + visible: !base.printerConnected + } + } + + UM.Dialog + { + id: connectActionDialog + Loader + { + anchors.fill: parent + source: "DiscoverUM3Action.qml" + } + rightButtons: Button + { + text: catalog.i18nc("@action:button", "Close") + iconName: "dialog-close" + onClicked: connectActionDialog.reject() + } + } + + + Item + { + objectName: "networkPrinterConnectionInfo" + visible: isUM3 + Button + { + height: UM.Theme.getSize("save_button_save_to_button").height + tooltip: catalog.i18nc("@info:tooltip", "Send access request to the printer") + text: catalog.i18nc("@action:button", "Request Access") + onClicked: Cura.MachineManager.printerOutputDevices[0].requestAuthentication() + visible: base.printerConnected && !base.printerAcceptsCommands + } + } + + UM.I18nCatalog{id: catalog; name:"cura"} +} \ No newline at end of file