diff options
Diffstat (limited to 'py3status/modules')
| -rw-r--r-- | py3status/modules/battery_level.py | 15 | ||||
| -rw-r--r-- | py3status/modules/dpms.py | 4 | ||||
| -rw-r--r-- | py3status/modules/keyboard_layout.py | 7 |
3 files changed, 18 insertions, 8 deletions
diff --git a/py3status/modules/battery_level.py b/py3status/modules/battery_level.py index 5ca9ea8..fd7c22d 100644 --- a/py3status/modules/battery_level.py +++ b/py3status/modules/battery_level.py @@ -47,13 +47,13 @@ class Py3status: # Example acpi raw output: "Battery 0: Discharging, 43%, 00:59:20 remaining" acpi_raw = subprocess.check_output(["acpi"], stderr=subprocess.STDOUT) - acpi_clean = acpi_raw.translate(None, ',') + acpi_unicode = acpi_raw.decode("UTF-8") # Example list: ['Battery', '0:', 'Discharging', '43%', '00:59:20', 'remaining'] - acpi_list = acpi_clean.split(' ') + acpi_list = acpi_unicode.split(' ') - charging = True if acpi_list[2] == "Charging" else False - percent_charged = int(acpi_list[3].translate(None, '%')) + charging = True if acpi_list[2][:8] == "Charging" else False + percent_charged = int(acpi_list[3][:-2]) self.time_remaining = ' '.join(acpi_list[4:]) battery_full = False @@ -112,3 +112,10 @@ class Py3status: stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w') ) + +if __name__ == "__main__": + from time import sleep + x = Py3status() + while True: + print(x.battery_level([], {})) + sleep(1) diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py index ba7437e..bcef53c 100644 --- a/py3status/modules/dpms.py +++ b/py3status/modules/dpms.py @@ -38,8 +38,8 @@ class Py3status: if event['button'] == 1: if self.run: self.run = False - system("xset -dpms") + system("xset -dpms;xset s off") else: self.run = True - system("xset +dpms") + system("xset +dpms;xset s on") system("killall -USR1 py3status") diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py index ffc3907..b62268e 100644 --- a/py3status/modules/keyboard_layout.py +++ b/py3status/modules/keyboard_layout.py @@ -13,6 +13,8 @@ Requires: from subprocess import check_output from time import time +import shlex +import re # colors of layouts, check your command's output to match keys LANG_COLORS = { @@ -22,6 +24,7 @@ LANG_COLORS = { 'us': '#729FCF', # light blue } +LAYOUT_RE = re.compile(r".*layout:\s*(\w+).*", flags=re.DOTALL) def xbklayout(): """ @@ -39,9 +42,9 @@ def setxkbmap(): Please read issue 33 for more information : https://github.com/ultrabug/py3status/pull/33 """ - q = check_output(['setxkbmap', '-query']).decode('utf-8') - return q.replace(' ', '').split(':')[-1] + out = check_output(shlex.split("setxkbmap -query")).decode("utf-8") + return re.match(LAYOUT_RE, out).group(1) class Py3status: |
