From a027b999e71532be9562fe733b745c09a8640868 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 5 Feb 2024 15:54:52 -0800 Subject: allow multiple clickable modules of same type --- panel.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'panel.py') diff --git a/panel.py b/panel.py index 7c8fa2e..34beed3 100755 --- a/panel.py +++ b/panel.py @@ -58,9 +58,9 @@ class ModDate(Mod): dt = datetime.now().astimezone(ZoneInfo(tz_id) if tz_id else None) label = tz_label or dt.strftime('%Z') - buf = ('%{A4:ModDate tz +1:}%{A5:ModDate tz -1:}' - f'%{{A:ModDate tz:}}{fmt_label(label)}%{{A}}{spacing()}' - f'%{{A:ModDate fmt:}}{dt.strftime(fmt)}%{{A}}' + buf = (f'%{{A4:{id(self)} tz +1:}}%{{A5:{id(self)} tz -1:}}' + f'%{{A:{id(self)} tz:}}{fmt_label(label)}%{{A}}{spacing()}' + f'%{{A:{id(self)} fmt:}}{dt.strftime(fmt)}%{{A}}' '%{A}%{A}') with self.cv: @@ -88,7 +88,7 @@ class ModHLWM(Mod): self.out = f'{self.out_tags}{spacing()}{self.out_title}' def fmt_tag(self, sym, tag, tagstr): - buf = f'%{{A:ModHLWM use {tag}:}}' + buf = f'%{{A:{id(self)} use {tag}:}}' match sym: case '.': buf += f'%{{F#777777}}%{{O7}}{tag}%{{O7}}%{{F-}}' @@ -113,7 +113,8 @@ class ModHLWM(Mod): stdout=subprocess.PIPE, text=True) tagstr = res.stdout.strip() tags = tagstr.split('\t') - buf = '%{A4:ModHLWM use_index +1:}%{A5:ModHLWM use_index -1:}' + buf = (f'%{{A4:{id(self)} use_index +1:}}' + f'%{{A5:{id(self)} use_index -1:}}') for tag in tags: buf += self.fmt_tag(tag[0], tag[1:], tagstr) buf += '%{A}%{A}' @@ -176,16 +177,16 @@ class Bar: self.mods = mods for m in self.mods: m.cv = self.cv + self.mod_by_id = {id(m): m for m in self.mods} def process_cmds(self, pipe): while True: line = pipe.readline() if not line: break - cmd_mod, cmd = line.rstrip().split(' ', 1) - for mod in self.mods: - if mod.__class__.__name__ == cmd_mod: - mod.process_cmd(cmd) + mod_id, cmd = line.rstrip().split(' ', 1) + if mod := self.mod_by_id.get(int(mod_id)): + mod.process_cmd(cmd) def run(self): for mod in self.mods: -- cgit v1.2.3-70-g09d2