Merge branch '921-scrolling-status-bar'
This commit is contained in:
commit
acb387a685
4 changed files with 92 additions and 1 deletions
53
bumblebee_status/modules/core/scroll.py
Normal file
53
bumblebee_status/modules/core/scroll.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays two widgets that can be used to scroll the whole status bar
|
||||
|
||||
Parameters:
|
||||
* scroll.width: Width (in number of widgets) to display
|
||||
"""
|
||||
|
||||
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"]
|
||||
elif self.__offset + self.__width >= self.__widgetcount:
|
||||
return ["warning"]
|
||||
return []
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue