From b4eb295800916915b6188114b4df8fadd0165676 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Mon, 26 May 2014 19:11:19 +0200 Subject: PEP8 and python2 fixes --- modules/battery-level.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/modules/battery-level.py b/modules/battery-level.py index fb3b769..4d94311 100644 --- a/modules/battery-level.py +++ b/modules/battery-level.py @@ -1,35 +1,42 @@ # -*- coding: utf8 -*- -import subprocess -import time -import re + +from __future__ import division # python2 compatibility +from time import time + import math +import re +import subprocess """ Module for displaying information about battery. +Requires: + - the 'acpi' command line + @author shadowprince -@version 1.0 @license Eclipse Public License """ -CACHE_TIME = 30 # time to update battery -HIDE_WHEN_FULL = True # hide any information when battery is fully charged +CACHE_TIME = 30 # time to update battery +HIDE_WHEN_FULL = False # hide any information when battery is fully charged -MODE = "bar" # for primitive-one-char bar, or "text" for text percentage ouput +MODE = "bar" # for primitive-one-char bar, or "text" for text percentage ouput -BLOCKS = [ "_", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", ] # block for bar -TEXT_FORMAT = "Battery: {}" # text with "text" mode. percentage with % replaces {} +BLOCKS = ["_", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] # block for bar +TEXT_FORMAT = "Battery: {}" # text with "text" mode. percentage with % replaces {} -CHARGING_CHARACTER = "⚡" +CHARGING_CHARACTER = "⚡" # None means - get it from i3 config -COLOR_DEGRADED = None COLOR_BAD = None COLOR_CHARGING = "#FCE94F" +COLOR_DEGRADED = None +COLOR_GOOD = None + class Py3status: - def currentBattery(self, i3status_output_json, i3status_config): - response = {'name': 'current-battery-level'} + def battery_level(self, i3status_output_json, i3status_config): + response = {'name': 'battery-level'} acpi = subprocess.check_output(["acpi"]).decode('utf-8') proc = int(re.search(r"(\d+)%", acpi).group(1)) @@ -38,23 +45,24 @@ class Py3status: full = bool(re.match(r".*Unknown.*", acpi)) or bool(re.match(r".*Full.*", acpi)) if MODE == "bar": - character = BLOCKS[math.ceil(proc/100*(len(BLOCKS) - 1))] + character = BLOCKS[int(math.ceil(proc/100*(len(BLOCKS) - 1)))] else: character = TEXT_FORMAT.format(str(proc) + "%") - + if proc < 30: - response['color'] = COLOR_DEGRADED if COLOR_DEGRADED else i3status_config["color_degraded"] + response['color'] = COLOR_DEGRADED if COLOR_DEGRADED else i3status_config['color_degraded'] if proc < 10: - response['color'] = COLOR_BAD if COLOR_BAD else i3status_config["color_bad"] + response['color'] = COLOR_BAD if COLOR_BAD else i3status_config['color_bad'] if full: + response['color'] = COLOR_GOOD if COLOR_GOOD else i3status_config['color_good'] response['full_text'] = "" if HIDE_WHEN_FULL else BLOCKS[-1] elif charging: - response['full_text'] = CHARGING_CHARACTER response['color'] = COLOR_CHARGING + response['full_text'] = CHARGING_CHARACTER else: response['full_text'] = character - response['cached_until'] = time.time() + CACHE_TIME + response['cached_until'] = time() + CACHE_TIME return (0, response) -- cgit v1.3