summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2014-12-21 20:14:19 +0100
committerUltrabug <ultrabug@gentoo.org>2014-12-21 20:14:19 +0100
commitd07f360da83260c811875a79ae5e5441612bee80 (patch)
tree17bb7de33730e57b6564195e6ddbe25fb01ffc23
parentadbf860f6027236d94258e2f86b2596ebd759a74 (diff)
module battery_level name normalization and QA and config
-rw-r--r--py3status/modules/battery-level.py68
-rw-r--r--py3status/modules/battery_level.py88
2 files changed, 88 insertions, 68 deletions
diff --git a/py3status/modules/battery-level.py b/py3status/modules/battery-level.py
deleted file mode 100644
index 6c30556..0000000
--- a/py3status/modules/battery-level.py
+++ /dev/null
@@ -1,68 +0,0 @@
-# -*- coding: utf8 -*-
-
-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
-@license Eclipse Public License
-"""
-
-CACHE_TIMEOUT = 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
-
-BLOCKS = ["_", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] # block for bar
-TEXT_FORMAT = "Battery: {}" # text with "text" mode. percentage with % replaces {}
-
-CHARGING_CHARACTER = "⚡"
-
-# None means - get it from i3 config
-COLOR_BAD = None
-COLOR_CHARGING = "#FCE94F"
-COLOR_DEGRADED = None
-COLOR_GOOD = None
-
-
-class Py3status:
- 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))
-
- charging = bool(re.match(r".*Charging.*", acpi))
- full = bool(re.match(r".*Unknown.*", acpi)) or bool(re.match(r".*Full.*", acpi))
-
- if MODE == "bar":
- 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']
- if proc < 10:
- 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['color'] = COLOR_CHARGING
- response['full_text'] = CHARGING_CHARACTER
- else:
- response['full_text'] = character
-
- response['cached_until'] = time() + CACHE_TIMEOUT
-
- return (0, response)
diff --git a/py3status/modules/battery_level.py b/py3status/modules/battery_level.py
new file mode 100644
index 0000000..938a7f1
--- /dev/null
+++ b/py3status/modules/battery_level.py
@@ -0,0 +1,88 @@
+# -*- coding: utf8 -*-
+"""
+Module for displaying information about battery.
+
+Requires:
+ - the 'acpi' command line
+
+@author shadowprince
+@license Eclipse Public License
+"""
+
+from __future__ import division # python2 compatibility
+from time import time
+
+import math
+import re
+import subprocess
+
+BLOCKS = ["_", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]
+CHARGING_CHARACTER = "⚡"
+
+
+class Py3status:
+ """
+ Configuration parameters:
+ - color_* : None means - get it from i3status config
+ - format : text with "text" mode. percentage with % replaces {}
+ - hide_when_full : hide any information when battery is fully charged
+ - mode : for primitive-one-char bar, or "text" for text percentage ouput
+ """
+
+ # available configuration parameters
+ cache_timeout = 30
+ color_bad = None
+ color_charging = "#FCE94F"
+ color_degraded = None
+ color_good = None
+ format = "Battery: {}"
+ hide_when_full = False
+ mode = "bar"
+
+ def battery_level(self, i3s_output_list, i3s_config):
+ response = {}
+
+ acpi = subprocess.check_output(["acpi"]).decode('utf-8')
+ proc = int(re.search(r"(\d+)%", acpi).group(1))
+
+ charging = bool(re.match(r".*Charging.*", acpi))
+ full = bool(
+ re.match(r".*Unknown.*", acpi)
+ ) or bool(
+ re.match(r".*Full.*", acpi)
+ )
+
+ if self.mode == "bar":
+ character = BLOCKS[int(math.ceil(proc/100*(len(BLOCKS) - 1)))]
+ else:
+ character = self.format.format(str(proc) + "%")
+
+ if proc < 30:
+ response['color'] = (
+ self.color_degraded
+ if self.color_degraded
+ else i3s_config['color_degraded']
+ )
+ if proc < 10:
+ response['color'] = (
+ self.color_bad
+ if self.color_bad
+ else i3s_config['color_bad']
+ )
+
+ if full:
+ response['color'] = (
+ self.color_good
+ if self.color_good
+ else i3s_config['color_good']
+ )
+ response['full_text'] = "" if self.hide_when_full else BLOCKS[-1]
+ elif charging:
+ response['color'] = self.color_charging
+ response['full_text'] = CHARGING_CHARACTER
+ else:
+ response['full_text'] = character
+
+ response['cached_until'] = time() + self.cache_timeout
+
+ return response