File: switchers_service.py

package info (click to toggle)
kylin-display-switch 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 216 kB
  • sloc: python: 540; sh: 4; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,044 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
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import subprocess


class SwitchersService:

    def get_capslock_status(self):
        handle = subprocess.Popen("xset q", shell=True, stdout=subprocess.PIPE)
        handle.wait()
        res = handle.communicate()[0]
        res = res.decode()
        capslock = res[res.find("Caps Lock:") + 9:]
        capslock = capslock[capslock.find("o"):capslock.find("o") + 2]

        if capslock == "on":
            return True
        else:
            return False

    def get_numlock_status(self):
        handle = subprocess.Popen("xset q", shell=True, stdout=subprocess.PIPE)
        handle.wait()
        res = handle.communicate()[0]
        res = res.decode()
        numlock = res[res.find("Num Lock:") + 9:]
        numlock = numlock[numlock.find("o"):numlock.find("o") + 2]

        if numlock == "on":
            return True
        else:
            return False


def main():
    w = SwitchersService()
    print(w.get_capslock_status())


if __name__ == '__main__':
    main()