mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-09 23:05:01 -06:00
Merge pull request #5460 from Ultimaker/WIP_onboarding_by_ip
'WIP-onboarding-by-ip' into 'parent' branch
This commit is contained in:
commit
139edbb0b7
12 changed files with 130 additions and 247 deletions
|
@ -13,6 +13,9 @@ from PyQt5.QtGui import QDesktopServices
|
|||
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
|
||||
from cura.Settings.GlobalStack import GlobalStack # typing
|
||||
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||
from UM.OutputDevice.OutputDeviceManager import ManualDeviceAdditionAttempt
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
from UM.Logger import Logger
|
||||
|
@ -38,8 +41,8 @@ i18n_catalog = i18nCatalog("cura")
|
|||
# If we discover a printer that has the same key as the active machine instance a connection is made.
|
||||
@signalemitter
|
||||
class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
addDeviceSignal = Signal()
|
||||
removeDeviceSignal = Signal()
|
||||
addDeviceSignal = Signal() # Called '...Signal' to avoid confusion with function-names.
|
||||
removeDeviceSignal = Signal() # Ditto ^^^.
|
||||
discoveredDevicesChanged = Signal()
|
||||
cloudFlowIsPossible = Signal()
|
||||
|
||||
|
@ -179,6 +182,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
self.checkCloudFlowIsPossible()
|
||||
else:
|
||||
self.getOutputDeviceManager().removeOutputDevice(key)
|
||||
if key.startswith("manual:"):
|
||||
self.removeManualDeviceSignal.emit(self.getPluginId(), key, self._discovered_devices[key].address)
|
||||
|
||||
def stop(self):
|
||||
if self._zero_conf is not None:
|
||||
|
@ -186,6 +191,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
self._zero_conf.close()
|
||||
self._cloud_output_device_manager.stop()
|
||||
|
||||
def canAddManualDevice(self, address: str = "") -> ManualDeviceAdditionAttempt:
|
||||
# This plugin should always be the fallback option (at least try it):
|
||||
return ManualDeviceAdditionAttempt.POSSIBLE
|
||||
|
||||
def removeManualDevice(self, key, address = None):
|
||||
if key in self._discovered_devices:
|
||||
if not address:
|
||||
|
@ -197,6 +206,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
self._manual_instances.remove(address)
|
||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
||||
|
||||
self.removeManualDeviceSignal.emit(self.getPluginId(), key, address)
|
||||
|
||||
def addManualDevice(self, address):
|
||||
if address not in self._manual_instances:
|
||||
self._manual_instances.append(address)
|
||||
|
@ -219,8 +230,6 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
self._checkManualDevice(address)
|
||||
|
||||
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
||||
# TODO: This needs to be implemented. It's supposed to create a machine given a unique key as already discovered
|
||||
# by this plugin.
|
||||
discovered_device = self._discovered_devices.get(key)
|
||||
if discovered_device is None:
|
||||
Logger.log("e", "Could not find discovered device with key [%s]", key)
|
||||
|
@ -249,6 +258,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
def _onNetworkRequestFinished(self, reply):
|
||||
reply_url = reply.url().toString()
|
||||
|
||||
address = ""
|
||||
device = None
|
||||
properties = {} # type: Dict[bytes, bytes]
|
||||
|
||||
if "system" in reply_url:
|
||||
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
|
||||
# Something went wrong with checking the firmware version!
|
||||
|
@ -308,6 +321,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
self._onRemoveDevice(instance_name)
|
||||
self._onAddDevice(instance_name, address, properties)
|
||||
|
||||
if device and address in self._manual_instances:
|
||||
self.getOutputDeviceManager().addOutputDevice(device)
|
||||
self.addManualDeviceSignal.emit(self.getPluginId(), device.getId(), address, properties)
|
||||
|
||||
def _onRemoveDevice(self, device_id):
|
||||
device = self._discovered_devices.pop(device_id, None)
|
||||
if device:
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import os
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtSlot
|
||||
|
||||
from UM.Extension import Extension
|
||||
from UM.Logger import Logger
|
||||
|
||||
|
||||
class UserAgreement(QObject, Extension):
|
||||
def __init__(self, application):
|
||||
super(UserAgreement, self).__init__()
|
||||
self._application = application
|
||||
self._user_agreement_window = None
|
||||
self._user_agreement_context = None
|
||||
self._application.engineCreatedSignal.connect(self._onEngineCreated)
|
||||
|
||||
self._application.getPreferences().addPreference("general/accepted_user_agreement", False)
|
||||
|
||||
def _onEngineCreated(self):
|
||||
if not self._application.getPreferences().getValue("general/accepted_user_agreement"):
|
||||
self.showUserAgreement()
|
||||
|
||||
def showUserAgreement(self):
|
||||
if not self._user_agreement_window:
|
||||
self.createUserAgreementWindow()
|
||||
|
||||
self._user_agreement_window.show()
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def didAgree(self, user_choice):
|
||||
if user_choice:
|
||||
Logger.log("i", "User agreed to the user agreement")
|
||||
self._application.getPreferences().setValue("general/accepted_user_agreement", True)
|
||||
self._user_agreement_window.hide()
|
||||
else:
|
||||
Logger.log("i", "User did NOT agree to the user agreement")
|
||||
self._application.getPreferences().setValue("general/accepted_user_agreement", False)
|
||||
self._application.quit()
|
||||
self._application.setNeedToShowUserAgreement(False)
|
||||
|
||||
def createUserAgreementWindow(self):
|
||||
path = os.path.join(self._application.getPluginRegistry().getPluginPath(self.getPluginId()), "UserAgreement.qml")
|
||||
self._user_agreement_window = self._application.createQmlComponent(path, {"manager": self})
|
|
@ -1,63 +0,0 @@
|
|||
// Copyright (c) 2017 Ultimaker B.V.
|
||||
// Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import QtQuick 2.2
|
||||
import QtQuick.Controls 1.4
|
||||
|
||||
import UM 1.3 as UM
|
||||
|
||||
UM.Dialog
|
||||
{
|
||||
id: baseDialog
|
||||
minimumWidth: Math.round(UM.Theme.getSize("modal_window_minimum").width * 0.75)
|
||||
minimumHeight: Math.round(UM.Theme.getSize("modal_window_minimum").height * 0.5)
|
||||
width: minimumWidth
|
||||
height: minimumHeight
|
||||
title: catalog.i18nc("@title:window", "User Agreement")
|
||||
|
||||
TextArea
|
||||
{
|
||||
anchors.top: parent.top
|
||||
width: parent.width
|
||||
anchors.bottom: buttonRow.top
|
||||
text: ' <center><h3>DISCLAIMER BY ULTIMAKER</h3></center>
|
||||
<p>PLEASE READ THIS DISCLAIMER CAREFULLY.</p>
|
||||
<p>EXCEPT WHEN OTHERWISE STATED IN WRITING, ULTIMAKER PROVIDES ANY ULTIMAKER SOFTWARE OR THIRD PARTY SOFTWARE “AS IS” WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF ULTIMAKER SOFTWARE IS WITH YOU.</p>
|
||||
<p>UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, IN NO EVENT WILL ULTIMAKER BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE ANY ULTIMAKER SOFTWARE OR THIRD PARTY SOFTWARE.</p>
|
||||
'
|
||||
readOnly: true;
|
||||
textFormat: TextEdit.RichText
|
||||
}
|
||||
|
||||
Item
|
||||
{
|
||||
id: buttonRow
|
||||
anchors.bottom: parent.bottom
|
||||
width: parent.width
|
||||
anchors.bottomMargin: UM.Theme.getSize("default_margin").height
|
||||
|
||||
UM.I18nCatalog { id: catalog; name: "cura" }
|
||||
|
||||
Button
|
||||
{
|
||||
anchors.right: parent.right
|
||||
text: catalog.i18nc("@action:button", "I understand and agree")
|
||||
onClicked: {
|
||||
baseDialog.accepted()
|
||||
}
|
||||
}
|
||||
|
||||
Button
|
||||
{
|
||||
anchors.left: parent.left
|
||||
text: catalog.i18nc("@action:button", "I don't agree")
|
||||
onClicked: {
|
||||
baseDialog.rejected()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAccepted: manager.didAgree(true)
|
||||
onRejected: manager.didAgree(false)
|
||||
onClosing: manager.didAgree(false)
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from . import UserAgreement
|
||||
|
||||
def getMetaData():
|
||||
return {}
|
||||
|
||||
def register(app):
|
||||
return {"extension": UserAgreement.UserAgreement(app)}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"name": "UserAgreement",
|
||||
"author": "Ultimaker B.V.",
|
||||
"version": "1.0.1",
|
||||
"description": "Ask the user once if he/she agrees with our license.",
|
||||
"api": "6.0",
|
||||
"i18n-catalog": "cura"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue