From 72e375ac8bd5c82008ecd3fe15c97a20646ff8a2 Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 10 Dec 2016 11:33:35 +0100 Subject: [PATCH] [modules/nic] Check for vanished interfaces If a widget exists for an interface that is not there anymore (i.e. a tunnel interface that has been removed, or a USB device that has been unplugged), remove that widget from the list. see #23 --- bumblebee/modules/nic.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index 272bd25..2459be7 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -45,6 +45,10 @@ class Module(bumblebee.engine.Module): def _update_widgets(self, widgets): interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ] + + for widget in widgets: + widget.set("visited", False) + for intf in interfaces: addr = [] state = "down" @@ -63,5 +67,10 @@ class Module(bumblebee.engine.Module): widget.full_text("{} {} {}".format(intf, state, ", ".join(addr))) widget.set("intf", intf) widget.set("state", state) + widget.set("visited", True) + + for widget in widgets: + if widget.get("visited") == False: + widgets.remove(widget) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4