I attached it in the last message. Are attachments not allowed?In any
case.. it's below.
--J
import netifaces
from libqtile.log_utils import logger
from libqtile.widget import base
from typing import Tuple
from math import log
class NetIP(base.ThreadedPollText):
"""Displays interface status and IPv4 address"""
orientations = base.ORIENTATION_HORIZONTAL
defaults = [
('interface', None, 'List of interfaces or single NIC as
string to monitor, \
None to displays all active NICs combined'),
('update_interval', 10, 'The update interval.'),
]
def __init__(self, **config):
base.ThreadedPollText.__init__(self, **config)
self.add_defaults(NetIP.defaults)
if not isinstance(self.interface, list):
if self.interface is None:
ifaces = netifaces.interfaces()
#no one cares about loopback
ifaces.remove('lo')
self.interface = ifaces
elif isinstance(self.interface, str):
self.interface = [self.interface]
else:
raise AttributeError("Invalid Argument passed:
%s\nAllowed Types: List, String, None" % self.interface)
def poll(self):
ret_stat = []
try:
for intf in self.interface:
addr = netifaces.ifaddresses(intf)
#Unable to get IP address
if not addr:
ret_stat.append("{0} : X.X.X.X".format(intf))
continue
ip_addrs = [ip['addr'] for ip in addr[netifaces.AF_INET]]
ret_stat.append("{0} : {1}".format(intf, ",".join(ip_addrs)))
return " | ".join(ret_stat)
except Exception as excp:
logger.error('%s: Caught Exception:\n%s',
self.__class__.__name__, excp)
On Sat, 28 Dec 2019 at 13:13, Tycho Andersen <[email protected]> wrote:
> On Fri, Dec 27, 2019 at 10:41:06PM -0800, J A wrote:
> > The first stab at a new widget was actually fairly straight forward and
> > easy. I'm loving qtile extensibility. I repurposed the Net widget and
> > trimmed it down. It seems to work when I refresh my config but it
> doesn't
> > automatically update when new interfaces are added as I would have
> presumed.
> >
> > Thoughts?
>
> Hard to say without seeing the code...
>
> Tycho
>
> --
> You received this message because you are subscribed to the Google Groups
> "qtile-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/qtile-dev/20191228181256.GH15663%40cisco
> .
>
--
You received this message because you are subscribed to the Google Groups
"qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/qtile-dev/CAJD0NiScjRbfVw6Ys8X06UKR3cxCe3wN4SehrahgObW2TFxW2A%40mail.gmail.com.