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
This commit is contained in:
Jack Ha 2016-09-28 16:36:09 +02:00
parent 1ed3fc7c37
commit da4ea2e450
2 changed files with 8 additions and 4 deletions

View file

@ -104,7 +104,6 @@ class DiscoverUM3Action(MachineAction):
def _createAdditionalComponentsView(self): def _createAdditionalComponentsView(self):
Logger.log("d", "Creating additional ui components for UM3.") Logger.log("d", "Creating additional ui components for UM3.")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml")) path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml"))
self.__additional_component = QQmlComponent(Application.getInstance()._engine, path) self.__additional_component = QQmlComponent(Application.getInstance()._engine, path)

View file

@ -15,7 +15,7 @@ import time
class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._zero_conf = Zeroconf() self._zero_conf = None
self._browser = None self._browser = None
self._printers = {} self._printers = {}
@ -37,17 +37,22 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
self.startDiscovery() self.startDiscovery()
def startDiscovery(self): def startDiscovery(self):
self.stop()
if self._browser: if self._browser:
self._browser.cancel() self._browser.cancel()
self._browser = None self._browser = None
self._old_printers = [printer_name for printer_name in self._printers] self._old_printers = [printer_name for printer_name in self._printers]
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]) self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged])
## Stop looking for devices on network. ## Stop looking for devices on network.
def stop(self): def stop(self):
self._zero_conf.close() if self._zero_conf is not None:
self._zero_conf.close()
def getPrinters(self): def getPrinters(self):
return self._printers return self._printers