summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-02-19 14:28:10 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-02-19 14:28:10 -0800
commit3d5bf4bcf4cc512884be010bc9ef9525e0acb14e (patch)
treeb32b7452e19031c0a03c622ff14e3299f21b7ae6
parentd9d5397f360b7b57353c381a9bbbe2e283650439 (diff)
downloadpanel-3d5bf4bcf4cc512884be010bc9ef9525e0acb14e.tar.gz
panel-3d5bf4bcf4cc512884be010bc9ef9525e0acb14e.tar.xz
add optional indicator when input device is available
-rwxr-xr-xpanel.py24
1 files changed, 16 insertions, 8 deletions
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'},