diff options
| -rwxr-xr-x | py3status/__init__.py | 13 | ||||
| -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 |
4 files changed, 25 insertions, 14 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py index f16a945..d98b83d 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -5,6 +5,7 @@ import os import select import sys +from collections import OrderedDict from contextlib import contextmanager from copy import deepcopy from datetime import datetime, timedelta @@ -411,13 +412,13 @@ class I3status(Thread): the user in his i3status.conf. """ ordered = [] - for module in self.config['order']: - if module in py3_modules: - for method in py3_modules[module].methods.values(): + for module_name in self.config['order']: + if module_name in py3_modules: + for method in py3_modules[module_name].methods.values(): ordered.append(method['last_output']) else: - if self.config.get(module, {}).get('response'): - ordered.append(self.config[module]['response']) + if self.config.get(module_name, {}).get('response'): + ordered.append(self.config[module_name]['response']) return ordered @staticmethod @@ -846,7 +847,7 @@ class Module(Thread): self.i3status_thread = i3_thread self.last_output = [] self.lock = lock - self.methods = {} + self.methods = OrderedDict() self.module_class = None self.module_inst = ''.join(module.split(' ')[1:]) self.module_name = module.split(' ')[0] 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: |
