summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorVasiliy Horbachenko <shadowprince47@gmail.com>2014-05-22 17:03:09 +0300
committerVasiliy Horbachenko <shadowprince47@gmail.com>2014-05-22 17:03:09 +0300
commitab38f5686d6c0c2fa658743e4e0d18ae0f7af76e (patch)
tree19eaffdd12e72b819c46a9fccd0527efce5cd7d6 /modules
parent73f27f48731f213396bc1e206a26f176986c8fdc (diff)
added battery level, current keyboard layout
Diffstat (limited to 'modules')
-rw-r--r--modules/battery-level.py59
-rw-r--r--modules/current-keyboard-layout.py33
-rw-r--r--modules/current-title.py12
-rw-r--r--modules/scratchpad-counter.py12
4 files changed, 108 insertions, 8 deletions
diff --git a/modules/battery-level.py b/modules/battery-level.py
new file mode 100644
index 0000000..ed6d484
--- /dev/null
+++ b/modules/battery-level.py
@@ -0,0 +1,59 @@
+import subprocess
+import time
+import re
+import math
+
+"""
+Module for displaying information about battery.
+
+@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
+
+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_DEGRADED = None
+COLOR_BAD = None
+COLOR_CHARGING = "#FCE94F"
+
+class Py3status:
+ def currentBattery(self, i3status_output_json, i3status_config):
+ response = {'name': 'current-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[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['full_text'] = "" if HIDE_WHEN_FULL else BLOCKS[-1]
+ elif charging:
+ response['full_text'] = CHARGING_CHAR
+ response['color'] = COLOR_CHARGING
+ else:
+ response['full_text'] = character
+
+ response['cached_until'] = time.time() + CACHE_TIME
+
+ return (0, response)
diff --git a/modules/current-keyboard-layout.py b/modules/current-keyboard-layout.py
new file mode 100644
index 0000000..046a2aa
--- /dev/null
+++ b/modules/current-keyboard-layout.py
@@ -0,0 +1,33 @@
+import subprocess
+import time
+
+"""
+Module for showing current keyboard layout.
+DEPENDS ON xkblayout-state!
+
+@author shadowprince
+@version 1.0
+@license Eclipse Public License
+"""
+
+CACHE_TIME = 0.2 # maximum time to update indicator
+
+# colors of layouts
+# key must be compatible with xkblayout-state print %s!
+LANG_COLORS = {
+ "ru": "#F75252",
+ "us": "#729FCF",
+ "ua": "#FCE94F",
+ }
+
+class Py3status:
+ def currentLayout(self, i3status_output_json, i3status_config):
+ response = {'full_text': '', 'name': 'current-layout', 'cached_until': time.time()+CACHE_TIME}
+ lang = subprocess.check_output(["xkblayout-state", "print", "%s"]).decode('utf-8')
+
+ return (0, {
+ "full_text": lang,
+ "name": "current-layout",
+ "cached_until": time.time() + CACHE_TIME,
+ "color": LANG_COLORS.get(lang, "#ffffff"),
+ })
diff --git a/modules/current-title.py b/modules/current-title.py
index d8cf383..e2f5aef 100644
--- a/modules/current-title.py
+++ b/modules/current-title.py
@@ -8,16 +8,16 @@ DEPENDENCIES:
Depends on i3-py!
pip install i3-py
-CONFIG:
- MAX_WIDTH - max title width
- CACHED_TIME - in seconds
-
If payload from server contains wierd utf-8 (for example one window have something bad in title) - plugin will give empty output UNTIL this window will be closed. I can't fix or workaround that in PLUGIN, problem is in i3-py library.
+
+@author shadowprince
+@version 1.0
+@license Eclipse Public License
"""
POSITION = 0
-MAX_WIDTH = 120
-CACHED_TIME = 0.5
+MAX_WIDTH = 120 # if width of title is greater, shrink it and add ...
+CACHED_TIME = 0.5 # maximum time to update indicator
def find_focused(tree):
if type(tree) == list:
diff --git a/modules/scratchpad-counter.py b/modules/scratchpad-counter.py
index f2c7dbc..b1cdd73 100644
--- a/modules/scratchpad-counter.py
+++ b/modules/scratchpad-counter.py
@@ -3,10 +3,18 @@ import time
import random
from pprint import pprint
+"""
+Module showing amount of windows at the scratchpad.
+
+@author shadowprince
+@version 1.0
+@license Eclipse Public License
+"""
+
CACHED_TIME = 1
POSITION = 1
-HIDE_WHEN_NONE = True
-STRFORMAT = "{} ⌫"
+HIDE_WHEN_NONE = True # hide indicator when there is no windows
+STRFORMAT = "{} ⌫" # format of indicator. {} replaces with count of windows
def find_scratch(tree):
if tree["name"] == "__i3_scratch":