[core/output] Refactor full/partial refresh

Creating the "raw", cached widget data out of the widget object was done
two places now.

see  #353
This commit is contained in:
Tobias Witek 2019-01-19 14:12:32 +01:00
parent 3d9279c444
commit 2b91ce5861

View file

@ -106,27 +106,8 @@ class I3BarOutput(object):
self._config = config self._config = config
def replace(self, event, module, new_widget): def replace(self, event, module, new_widget):
full_text = new_widget.full_text() data = self.widget_data(module, new_widget)
padding = self._theme.padding(new_widget) self._widgets = [w if not "instance" in w or w["instance"] != event["instance"] else data for w in self._widgets]
prefix = self._theme.prefix(new_widget, padding)
suffix = self._theme.suffix(new_widget, padding)
if prefix:
full_text = u"{}{}".format(prefix, full_text)
if suffix:
full_text = u"{}{}".format(full_text, suffix)
separator = self._theme.separator(new_widget)
widget_data = {
u"full_text": full_text,
"color": self._theme.fg(new_widget),
"background": self._theme.bg(new_widget),
"separator_block_width": self._theme.separator_block_width(new_widget),
"separator": True if separator is None else False,
"min_width": None,
"align": self._theme.align(new_widget),
"instance": new_widget.id,
"name": module.id,
}
self._widgets = [w if not "instance" in w or w["instance"] != event["instance"] else widget_data for w in self._widgets]
def started(self): def started(self):
return self._started return self._started
@ -140,19 +121,37 @@ class I3BarOutput(object):
"""Finish i3bar protocol""" """Finish i3bar protocol"""
sys.stdout.write("]\n") sys.stdout.write("]\n")
def draw(self, widget, module=None, engine=None): def widget_data(self, module, widget):
"""Draw a single widget"""
full_text = widget.full_text() full_text = widget.full_text()
if widget.get_module() and widget.get_module().hidden():
return
padding = self._theme.padding(widget) padding = self._theme.padding(widget)
prefix = self._theme.prefix(widget, padding) prefix = self._theme.prefix(widget, padding)
suffix = self._theme.suffix(widget, padding) suffix = self._theme.suffix(widget, padding)
if prefix: if prefix:
full_text = u"{}{}".format(prefix, full_text) full_text = u"{}{}".format(prefix, full_text)
if suffix: if suffix:
full_text = u"{}{}".format(full_text, suffix) full_text = u"{}{}".format(full_text, suffix)
separator = self._theme.separator(widget)
width = self._theme.minwidth(widget)
if width:
full_text = full_text.ljust(len(width) + len(prefix) + len(suffix))
return {
u"full_text": full_text,
"color": self._theme.fg(widget),
"background": self._theme.bg(widget),
"separator_block_width": self._theme.separator_block_width(widget),
"separator": True if separator is None else False,
"min_width": None,
"align": self._theme.align(widget),
"instance": widget.id,
"name": module.id,
}
def draw(self, widget, module=None, engine=None):
"""Draw a single widget"""
if widget.get_module() and widget.get_module().hidden():
return
separator = self._theme.separator(widget) separator = self._theme.separator(widget)
if separator: if separator:
@ -163,23 +162,8 @@ class I3BarOutput(object):
"background": self._theme.separator_bg(widget), "background": self._theme.separator_bg(widget),
"separator_block_width": self._theme.separator_block_width(widget), "separator_block_width": self._theme.separator_block_width(widget),
}) })
width = self._theme.minwidth(widget)
if width: self._widgets.append(self.widget_data(module, widget))
full_text = full_text.ljust(len(width) + len(prefix) + len(suffix))
self._widgets.append({
u"full_text": full_text,
"color": self._theme.fg(widget),
"background": self._theme.bg(widget),
"separator_block_width": self._theme.separator_block_width(widget),
"separator": True if separator is None else False,
"min_width": None,
# "min_width": width + "A"*(len(prefix) + len(suffix)) if width else None,
"align": self._theme.align(widget),
"instance": widget.id,
"name": module.id,
})
def begin(self): def begin(self):
"""Start one output iteration""" """Start one output iteration"""