2020-02-23 14:47:20 +01:00
|
|
|
import util.format
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-13 09:27:03 +02:00
|
|
|
def never(init):
|
|
|
|
def call_init(obj, *args, **kwargs):
|
|
|
|
init(obj, *args, **kwargs)
|
2020-05-03 11:15:52 +02:00
|
|
|
if obj.parameter("interval") is None:
|
|
|
|
obj.set("interval", "never")
|
|
|
|
|
2020-04-13 09:27:03 +02:00
|
|
|
return call_init
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-02 16:30:31 +02:00
|
|
|
def every(hours=0, minutes=0, seconds=0):
|
2020-03-29 14:36:44 +02:00
|
|
|
def decorator_init(init):
|
|
|
|
def call_init(obj, *args, **kwargs):
|
|
|
|
init(obj, *args, **kwargs)
|
2020-05-03 11:15:52 +02:00
|
|
|
if obj.parameter("interval") is None:
|
|
|
|
obj.set("interval", hours * 3600 + minutes * 60 + seconds)
|
|
|
|
|
2020-03-29 14:36:44 +02:00
|
|
|
return call_init
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-29 14:36:44 +02:00
|
|
|
return decorator_init
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-23 14:47:20 +01:00
|
|
|
def scrollable(func):
|
|
|
|
def wrapper(module, widget):
|
|
|
|
text = func(module, widget)
|
|
|
|
if not text:
|
|
|
|
return text
|
2020-05-04 20:11:10 +02:00
|
|
|
|
|
|
|
if text != widget.get("__content__", text):
|
|
|
|
widget.set("scrolling.start", 0)
|
|
|
|
widget.set("scrolling.direction", "right")
|
|
|
|
widget.set("__content__", text)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
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)
|
2020-02-23 14:47:20 +01:00
|
|
|
if width < 0 or len(text) <= width:
|
|
|
|
return text
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
start = widget.get("scrolling.start", 0)
|
|
|
|
bounce = util.format.asbool(module.parameter("scrolling.bounce", True))
|
|
|
|
scroll_speed = util.format.asint(module.parameter("scrolling.speed", 1))
|
|
|
|
direction = widget.get("scrolling.direction", "right")
|
2020-02-29 14:05:02 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
if direction == "left":
|
2020-02-27 21:39:04 +01:00
|
|
|
scroll_speed = -scroll_speed
|
2020-05-03 11:15:52 +02:00
|
|
|
if start + scroll_speed <= 0: # bounce back
|
|
|
|
widget.set("scrolling.direction", "right")
|
2020-02-29 14:05:02 +01:00
|
|
|
|
|
|
|
next_start = start + scroll_speed
|
|
|
|
if next_start + width > len(text):
|
|
|
|
if not bounce:
|
|
|
|
next_start = 0
|
|
|
|
else:
|
|
|
|
next_start = start - scroll_speed
|
2020-05-03 11:15:52 +02:00
|
|
|
widget.set("scrolling.direction", "left")
|
2020-02-29 14:05:02 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
widget.set("scrolling.start", next_start)
|
|
|
|
|
|
|
|
return text[start : start + width]
|
2020-02-23 14:47:20 +01:00
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-23 14:47:20 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|