File: indicator.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 (65 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
# pylint: disable=C0111,R0903

"""Displays the indicator status, for numlock, scrolllock and capslock 

Requires the following executable:
    * xset

Parameters:
    * indicator.include: Comma-separated list of interface prefixes to include (defaults to 'numlock,capslock')
    * indicator.signalstype: If you want the signali type color to be 'critical' or 'warning' (defaults to 'warning')

contributed by `freed00m <https://github.com/freed00m>`_ - many thanks!
"""

import core.module

import util.cli
import util.format


class Module(core.module.Module):
    def __init__(self, config, theme):
        super().__init__(config, theme, [])

        self.__include = tuple(
            filter(
                len, util.format.aslist(self.parameter("include", "NumLock,CapsLock"))
            )
        )
        self.__signalType = (
            self.parameter("signaltype")
            if not self.parameter("signaltype") is None
            else "warning"
        )

    def update(self):
        status_line = ""
        for line in (
            util.cli.execute("xset q", ignore_errors=True).replace(" ", "").split("\n")
        ):
            if "capslock" in line.lower():
                status_line = line
                break
        for indicator in self.__include:
            widget = self.widget(indicator)
            if not widget:
                widget = self.add_widget(name=indicator, full_text=indicator)

            widget.set(
                "status",
                True
                if "{}:on".format(indicator.lower()) in status_line.lower()
                else False,
            )

    def state(self, widget):
        states = []
        if widget.get("status", False):
            states.append(self.__signalType)
        else:
            states.append("normal")
        return states


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4