mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 19:28:07 -06:00
Get a list of ipadresses/hosts to check for UM3 printers...
...in case discovery does not work. This uses the API to look up info on the printer instead of relying on zeroconf. CURA-2483
This commit is contained in:
parent
1ed3fc7c37
commit
8e26d63390
1 changed files with 37 additions and 0 deletions
|
@ -5,6 +5,10 @@ from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Signal import Signal, signalemitter
|
from UM.Signal import Signal, signalemitter
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
from UM.Preferences import Preferences
|
||||||
|
|
||||||
|
from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager, QNetworkReply
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -19,6 +23,12 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
self._browser = None
|
self._browser = None
|
||||||
self._printers = {}
|
self._printers = {}
|
||||||
|
|
||||||
|
self._api_version = "1"
|
||||||
|
self._api_prefix = "/api/v" + self._api_version + "/"
|
||||||
|
|
||||||
|
self._network_manager = QNetworkAccessManager()
|
||||||
|
self._network_manager.finished.connect(self._onNetworkRequestFinished)
|
||||||
|
|
||||||
# List of old printer names. This is used to ensure that a refresh of zeroconf does not needlessly forces
|
# List of old printer names. This is used to ensure that a refresh of zeroconf does not needlessly forces
|
||||||
# authentication requests.
|
# authentication requests.
|
||||||
self._old_printers = []
|
self._old_printers = []
|
||||||
|
@ -28,6 +38,11 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
self.removePrinterSignal.connect(self.removePrinter)
|
self.removePrinterSignal.connect(self.removePrinter)
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
|
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
|
||||||
|
|
||||||
|
# Get list of manual printers from preferences
|
||||||
|
preferences = Preferences.getInstance()
|
||||||
|
preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
|
||||||
|
self._manual_instances = preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||||
|
|
||||||
addPrinterSignal = Signal()
|
addPrinterSignal = Signal()
|
||||||
removePrinterSignal = Signal()
|
removePrinterSignal = Signal()
|
||||||
printerListChanged = Signal()
|
printerListChanged = Signal()
|
||||||
|
@ -45,6 +60,28 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged])
|
self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged])
|
||||||
|
|
||||||
|
# Look for manual instances from preference
|
||||||
|
for address in self._manual_instances:
|
||||||
|
url = QUrl("http://" + address + self._api_prefix + "system/name")
|
||||||
|
|
||||||
|
name_request = QNetworkRequest(url)
|
||||||
|
self._network_manager.get(name_request)
|
||||||
|
|
||||||
|
## Handler for all requests that have finished.
|
||||||
|
def _onNetworkRequestFinished(self, reply):
|
||||||
|
reply_url = reply.url().toString()
|
||||||
|
status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
|
||||||
|
|
||||||
|
if reply.operation() == QNetworkAccessManager.GetOperation:
|
||||||
|
if "system/name" in reply_url: # Name returned from printer.
|
||||||
|
if status_code == 200:
|
||||||
|
address = reply.url().host()
|
||||||
|
name = reply.readAll()
|
||||||
|
|
||||||
|
instance_name = "manual:%s" % address
|
||||||
|
properties = { b"name": name.data() }
|
||||||
|
self.addPrinter(instance_name, address, properties)
|
||||||
|
|
||||||
## Stop looking for devices on network.
|
## Stop looking for devices on network.
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._zero_conf.close()
|
self._zero_conf.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue