21cbbe685d
add a scrolling module that can be used to scroll the whole bar to an arbitrary number of widgets. its parameter is "width", which determines the number of widgets to display. see #921
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
# pylint: disable=C0111,R0903
|
|
|
|
"""
|
|
"""
|
|
|
|
import core.module
|
|
import core.widget
|
|
import core.input
|
|
import core.event
|
|
|
|
import util.format
|
|
|
|
class Module(core.module.Module):
|
|
def __init__(self, config, theme):
|
|
super().__init__(config, theme, [])
|
|
self.__offset = 0
|
|
self.__widgetcount = 0
|
|
w = self.add_widget(full_text = "<")
|
|
core.input.register(w, button=core.input.LEFT_MOUSE, cmd=self.scroll_left)
|
|
w = self.add_widget(full_text = ">")
|
|
core.input.register(w, button=core.input.LEFT_MOUSE, cmd=self.scroll_right)
|
|
self.__width = util.format.asint(self.parameter("width"))
|
|
config.set("output.width", self.__width)
|
|
core.event.register("output.done", self.update_done)
|
|
|
|
|
|
def scroll_left(self, _):
|
|
if self.__offset > 0:
|
|
core.event.trigger("output.scroll-left")
|
|
|
|
def scroll_right(self, _):
|
|
if self.__offset + self.__width < self.__widgetcount:
|
|
core.event.trigger("output.scroll-right")
|
|
|
|
def update_done(self, offset, widgetcount):
|
|
self.__offset = offset
|
|
self.__widgetcount = widgetcount
|
|
|
|
def scroll(self):
|
|
return False
|
|
|
|
def state(self, widget):
|
|
if widget.id == self.widgets()[0].id:
|
|
if self.__offset == 0:
|
|
return ["warning"]
|
|
if self.__offset + self.__width >= self.__widgetcount:
|
|
return ["warning"]
|
|
return []
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|