diff options
-rwxr-xr-x | panel.py | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -5,6 +5,7 @@ import os import psutil import queue +import re import subprocess import threading import time @@ -341,14 +342,19 @@ class ModInterval(Mod): self.timer.run() class ModNetIf(ModInterval): - def __init__(self, ifname, label=None, **kwargs): + def __init__(self, ifname, label=None, regex=False, **kwargs): super().__init__(**kwargs) self.ifname = ifname + self.regex = regex self.label = label or ifname def refresh(self): - stats = psutil.net_if_stats().get(self.ifname) - state = 'up' if stats and stats.isup else 'down' + stats = psutil.net_if_stats() + if self.regex: + arr = [v for k, v in stats.items() if re.fullmatch(self.ifname, k)] + else: + arr = [x] if (x := stats.get(self.ifname)) else [] + state = 'up' if any(x.isup for x in arr) else 'down' self.out = Fmt.labelled(self.label, state) class ModCPU(ModInterval): @@ -410,7 +416,7 @@ Panel( ModInputAvail( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', unavail_text='NO KEYBOARD'), - ModNetIf('wg0', interval=1), + ModNetIf('wg.*', regex=True, label='wg*', interval=1), ModCPU(interval=0.5), ModMem(interval=0.5), ModDate( |