From a8ab4f9509a0eabacc9fd87bbe451ea499e539f2 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 1 May 2020 20:25:10 +0200 Subject: [PATCH] [core/output] allow specification of per-widget modified make it possible to specify the minimum width of all widgets via: `-m cpu -p cpu.theme.minwidth=20` or `-m cpu -p cpu.theme.minwidth=aaaaaa` multiple widgets are comma-separated (missing entries will have no minwidth) `-m sensors2 -p sensors2.theme.minwidth=10,20,10` see #606 TODO add to documentation --- core/output.py | 9 +++++++-- core/widget.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/output.py b/core/output.py index 6237f1d..af1a5b8 100644 --- a/core/output.py +++ b/core/output.py @@ -84,7 +84,7 @@ class block(object): for k in [ 'name', 'instance', 'separator_block_width', 'border', 'border_top', 'border_bottom', 'border_left', 'border_right', 'markup', - '_raw', '_suffix', '_prefix' + '_raw', '_suffix', '_prefix', 'min_width' ]: assign(self.__attributes, result, k) @@ -153,7 +153,12 @@ class i3(object): def __content_block(self, module, widget): blk = block(self.__theme, module, widget) - blk.set('min_width', widget.get('theme.minwidth')) + minwidth = widget.theme('minwidth') + if minwidth is not None: + try: + blk.set('min-width', '-'*int(minwidth)) + except: + blk.set('min-width', minwidth) blk.set('full_text', self.__content[widget]) if widget.get('pango', False): blk.set('markup', 'pango') diff --git a/core/widget.py b/core/widget.py index 0c12e99..2d1ad17 100644 --- a/core/widget.py +++ b/core/widget.py @@ -1,6 +1,8 @@ import core.input import core.decorators + import util.store +import util.format class Widget(util.store.Store, core.input.Object): def __init__(self, full_text='', name=None, module=None): @@ -9,6 +11,24 @@ class Widget(util.store.Store, core.input.Object): self.module = module self.name = name + def index(self): + if not self.module: return 0 + + idx = 0 + for w in self.module.widgets(): + if w.id == self.id: + return idx + idx = idx + 1 + return -1 # not found + + def theme(self, attribute): + attr = 'theme.{}'.format(attribute) + if self.module: + param = util.format.aslist(self.module.parameter(attr)) + if param and len(param) > self.index(): + return param[self.index()] + return self.get(attr) + def full_text(self, value=None): if value: self.__full_text = value