File: scroll.py

package info (click to toggle)
bumblebee-status 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,844 kB
  • sloc: python: 13,430; sh: 68; makefile: 29
file content (53 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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