[core/widget] make arbitrary modules scrollable

Use a boolean parameter "scrolling" that's applied generically to
modules to allow arbitrary modules to scroll.

see #606

TODO: Add to documentation
This commit is contained in:
tobi-wan-kenobi 2020-05-18 13:13:06 +02:00
parent e359c75603
commit 922575fcda

View file

@ -1,9 +1,13 @@
import logging
import core.input import core.input
import core.decorators import core.decorators
import util.store import util.store
import util.format import util.format
log = logging.getLogger(__name__)
class Widget(util.store.Store, core.input.Object): class Widget(util.store.Store, core.input.Object):
def __init__(self, full_text="", name=None): def __init__(self, full_text="", name=None):
@ -27,6 +31,13 @@ class Widget(util.store.Store, core.input.Object):
custom_ids = util.format.aslist(module.parameter("id")) custom_ids = util.format.aslist(module.parameter("id"))
if len(custom_ids) > self.index(): if len(custom_ids) > self.index():
self.id = custom_ids[self.index()] self.id = custom_ids[self.index()]
if util.format.asbool(module.parameter("scrolling", False)) == True:
if callable(self.__full_text):
self.__full_text = core.decorators.scrollable(
self.__full_text.__func__
).__get__(module)
else:
log.warning("unable to make scrollable: {}".format(module.name))
def index(self): def index(self):
if not self.module: if not self.module: