From 3d5bf4bcf4cc512884be010bc9ef9525e0acb14e Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 19 Feb 2024 14:28:10 -0800 Subject: add optional indicator when input device is available --- panel.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'panel.py') diff --git a/panel.py b/panel.py index 32fc037..aad51eb 100755 --- a/panel.py +++ b/panel.py @@ -246,11 +246,17 @@ class ModHLWMTitle(ModHLWMBase): else title) self.repaint() -class ModInputUnavail(Mod): - def __init__(self, path, label='', **kwargs): +class ModInputAvail(Mod): + def __init__(self, path, + avail_text=None, avail_bg='#207000', + unavail_text=None, unavail_bg='#a03000', + **kwargs): super().__init__(**kwargs) self.path = path - self.label = label + self.avail_text = avail_text + self.avail_bg = avail_bg + self.unavail_text = unavail_text + self.unavail_bg = unavail_bg def work(self): p = subprocess.Popen( @@ -284,10 +290,12 @@ class ModInputUnavail(Mod): self._update_state(False) def _update_state(self, avail): - if avail: - self.out = None + if avail and self.avail_text is not None: + self.out = Fmt.bg(self.avail_bg, Fmt.pad(self.avail_text)) + elif not avail and self.unavail_text is not None: + self.out = Fmt.bg(self.unavail_bg, Fmt.pad(self.unavail_text)) else: - self.out = Fmt.bg('#a03000', Fmt.pad(self.label)) + self.out = None self.repaint() class Panel: @@ -336,9 +344,9 @@ Panel( ModHLWMTags(spacing=0), ModHLWMTitle(max_len=96), ModRight(), - ModInputUnavail( + ModInputAvail( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', - label='NO KEYBOARD'), + unavail_text='NO KEYBOARD'), ModDate( fmts=('%Y-%m-%d %H:%M:%S', '%H:%M'), tzs=({'id': None}, {'id': 'UTC'}, -- cgit v1.2.3-70-g09d2