From 67efb32979524fb5b5f3764ef058e40274bb5947 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 9 Mar 2024 01:12:38 -0800 Subject: add colour and optional limit to volume --- panel.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'panel.py') diff --git a/panel.py b/panel.py index c518d74..0dcfade 100755 --- a/panel.py +++ b/panel.py @@ -465,10 +465,12 @@ class ModMem(ModInterval): self.out = Fmt.labelled('MEM', f'{percent:.0f}%%') class ModPWVol(ModInterval): - def __init__(self, sink='@DEFAULT_AUDIO_SINK@', step='0.05', **kwargs): + def __init__(self, sink='@DEFAULT_AUDIO_SINK@', step='0.05', limit=None, + **kwargs): super().__init__(**kwargs) self.sink = sink self.step = step + self.limit = limit def refresh(self): res = subprocess.run( @@ -477,8 +479,9 @@ class ModPWVol(ModInterval): if (m := re.match('Volume: ([0-9.]*)( \[MUTED\])?', res.stdout)): vol = float(m.group(1)) * 100 buf = f'{vol:.0f}%%' - if m.group(2): - buf += ' [muted]' + buf = (Fmt.fg('#777777', buf + ' [muted]') if m.group(2) + else Fmt.fg('#ff4000', buf) if vol > 100 + else buf) else: buf = Fmt.bg('#a03000', ' error ') @@ -494,7 +497,10 @@ class ModPWVol(ModInterval): if cmd == 'toggle-mute': subprocess.run(('wpctl', 'set-mute', self.sink, 'toggle')) elif cmd.startswith('set'): - subprocess.run(('wpctl', 'set-volume', self.sink, cmd[4:])) + args = ('wpctl', 'set-volume', self.sink, cmd[4:]) + if self.limit: + args = (*args, '-l', str(self.limit)) + subprocess.run(args) self.refresh() self.repaint() @@ -563,7 +569,7 @@ Panel( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', unavail_text='NO KEYBOARD'), ModNetIf('wg(?!0$).*', regex=True, label='wg*'), - ModPWVol(), + ModPWVol(limit=1.5), ModCPU(interval=0.5), ModMem(interval=0.5), ModDate( -- cgit v1.2.3-70-g09d2