bumblebee-status/core/decorators.py

37 lines
1.3 KiB
Python
Raw Normal View History

import util.format
def scrollable(func):
def wrapper(module, widget):
text = func(module, widget)
if not text:
return text
width = widget.get('theme.width', util.format.asint(module.parameter('width', 30)))
if util.format.asbool(module.parameter('scrolling.makewide', True)):
widget.set('theme.minwidth', 'A'*width)
if width < 0 or len(text) <= width:
return text
2020-02-23 14:52:58 +01:00
bounce = util.format.asbool(module.parameter('scrolling.bounce', True))
scroll_speed = util.format.asint(module.parameter('scrolling.speed', 1))
start = widget.get('scrolling.start', -1)
direction = widget.get('scrolling.direction', 'right')
start += scroll_speed if direction == 'right' else -(scroll_speed)
2020-02-24 14:20:54 +01:00
if width + start > len(text) + (scroll_speed - 1):
if bounce:
widget.set('scrolling.direction', 'left')
else:
start = 0
elif start <= 0:
if bounce:
widget.set('scrolling.direction', 'right')
else:
start = len(text)
widget.set('scrolling.start', start)
text = text[start:width+start]
return text
return wrapper
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4