From da4ea2e45024bc811d079aec889ecd4d7dcd96a3 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 28 Sep 2016 16:36:09 +0200 Subject: [PATCH] Better refresh button: now emits signal and re-instantiates zeroconf. Signal emits let the UI display an empty list. Re-instantiation copes with network changes. Contributes to CURA-2372 --- DiscoverUM3Action.py | 1 - NetworkPrinterOutputDevicePlugin.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/DiscoverUM3Action.py b/DiscoverUM3Action.py index cda6ea386a..6c6757d28b 100644 --- a/DiscoverUM3Action.py +++ b/DiscoverUM3Action.py @@ -104,7 +104,6 @@ class DiscoverUM3Action(MachineAction): def _createAdditionalComponentsView(self): Logger.log("d", "Creating additional ui components for UM3.") - path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml")) self.__additional_component = QQmlComponent(Application.getInstance()._engine, path) diff --git a/NetworkPrinterOutputDevicePlugin.py b/NetworkPrinterOutputDevicePlugin.py index a168f2ae43..f0966c9fe3 100644 --- a/NetworkPrinterOutputDevicePlugin.py +++ b/NetworkPrinterOutputDevicePlugin.py @@ -15,7 +15,7 @@ import time class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): def __init__(self): super().__init__() - self._zero_conf = Zeroconf() + self._zero_conf = None self._browser = None self._printers = {} @@ -37,17 +37,22 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): self.startDiscovery() def startDiscovery(self): + self.stop() if self._browser: self._browser.cancel() self._browser = None self._old_printers = [printer_name for printer_name in self._printers] self._printers = {} - + self.printerListChanged.emit() + # After network switching, one must make a new instance of Zeroconf + # On windows, the instance creation is very fast (unnoticable). Other platforms? + self._zero_conf = Zeroconf() self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged]) ## Stop looking for devices on network. def stop(self): - self._zero_conf.close() + if self._zero_conf is not None: + self._zero_conf.close() def getPrinters(self): return self._printers