[core] Add a "scrollable" modifier for widget texts callbacks
If a module defines a callback for a widget's text, an optional decorator "@bumblebee.output.scrollable" can be used to make the text scrollable. In those cases, the desired width is set to (in decreasing order of priority): 1. whatever the widget defines as "theme.width" 2. whatever the theme defines as "width" for the module 3. whatever the commandline parameter "width" for the module is set to 4. 30 (determined by unfair dice roll) see #27
This commit is contained in:
parent
92be7d3020
commit
928940d848
2 changed files with 24 additions and 2 deletions
|
@ -8,6 +8,27 @@ import uuid
|
||||||
|
|
||||||
import bumblebee.store
|
import bumblebee.store
|
||||||
|
|
||||||
|
def scrollable(func):
|
||||||
|
def wrapper(module, widget):
|
||||||
|
text = func(module, widget)
|
||||||
|
width = widget.get("theme.width", module.parameter("width", 30))
|
||||||
|
widget.set("theme.minwidth", "A"*width)
|
||||||
|
if len(text) <= width:
|
||||||
|
return text
|
||||||
|
# we need to shorten
|
||||||
|
start = widget.get("scrolling.start", -1)
|
||||||
|
direction = widget.get("scrolling.direction", "right")
|
||||||
|
start += 1 if direction == "right" else -1
|
||||||
|
widget.set("scrolling.start", start)
|
||||||
|
if width + start >= len(text):
|
||||||
|
widget.set("scrolling.direction", "left")
|
||||||
|
if start <= 0:
|
||||||
|
widget.set("scrolling.direction", "right")
|
||||||
|
text = text[start:width+start]
|
||||||
|
|
||||||
|
return text
|
||||||
|
return wrapper
|
||||||
|
|
||||||
class Widget(bumblebee.store.Store):
|
class Widget(bumblebee.store.Store):
|
||||||
"""Represents a single visible block in the status bar"""
|
"""Represents a single visible block in the status bar"""
|
||||||
def __init__(self, full_text="", name=""):
|
def __init__(self, full_text="", name=""):
|
||||||
|
@ -83,13 +104,14 @@ 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)
|
||||||
self._widgets.append({
|
self._widgets.append({
|
||||||
u"full_text": full_text,
|
u"full_text": full_text,
|
||||||
"color": self._theme.fg(widget),
|
"color": self._theme.fg(widget),
|
||||||
"background": self._theme.bg(widget),
|
"background": self._theme.bg(widget),
|
||||||
"separator_block_width": self._theme.separator_block_width(widget),
|
"separator_block_width": self._theme.separator_block_width(widget),
|
||||||
"separator": True if separator is None else False,
|
"separator": True if separator is None else False,
|
||||||
"min_width": self._theme.minwidth(widget),
|
"min_width": width + "A"*(len(prefix) + len(suffix)) if width else None,
|
||||||
"align": self._theme.align(widget),
|
"align": self._theme.align(widget),
|
||||||
"instance": widget.id,
|
"instance": widget.id,
|
||||||
"name": module.id,
|
"name": module.id,
|
||||||
|
|
|
@ -139,7 +139,7 @@ class Theme(object):
|
||||||
state_themes.append(self._get(widget, state, {}))
|
state_themes.append(self._get(widget, state, {}))
|
||||||
|
|
||||||
value = self._defaults.get(name, default)
|
value = self._defaults.get(name, default)
|
||||||
value = widget.get("theme-{}".format(name), value)
|
value = widget.get("theme.{}".format(name), value)
|
||||||
value = self._cycle.get(name, value)
|
value = self._cycle.get(name, value)
|
||||||
value = module_theme.get(name, value)
|
value = module_theme.get(name, value)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue