From 3beaf88e9764e26725ab2cd2dfbe5c08ec61340e Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Thu, 22 May 2014 08:08:40 +0300 Subject: added scratchpad-counter --- modules/scratchpad-counter.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/scratchpad-counter.py (limited to 'modules/scratchpad-counter.py') diff --git a/modules/scratchpad-counter.py b/modules/scratchpad-counter.py new file mode 100644 index 0000000..5fc3c71 --- /dev/null +++ b/modules/scratchpad-counter.py @@ -0,0 +1,41 @@ +import i3 +import time +import random +from pprint import pprint + +CACHED_TIME = 1 +POSITION = 1 +HIDE_WHEN_NONE = True +STRFORMAT = "{} ⌫" + +def find_scratch(tree): + if tree["name"] == "__i3_scratch": + return tree + else: + for x in tree["nodes"]: + result = find_scratch(x) + if result: + return result + + return None + +class Py3status: + def __init__(self, *args, **kwargs): + self.count = -1 + super(Py3status).__init__(*args, **kwargs) + + def currentTitle(self, json, i3status_config): + count = len(find_scratch(i3.get_tree()).get("floating_nodes", [])) + + if self.count != count: + transformed = True + self.count = count + else: + transformed = False + + return (POSITION, { + 'transformed': transformed, + 'full_text': '' if HIDE_WHEN_NONE and count == 0 else STRFORMAT.format(count), + 'name': 'scratchpad-count', + 'cached_until': time.time() + CACHED_TIME, + }) -- cgit v1.3 From 73f27f48731f213396bc1e206a26f176986c8fdc Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Thu, 22 May 2014 16:38:15 +0300 Subject: scratchpad counter and current title fixes --- modules/current-title.py | 14 ++++++++------ modules/scratchpad-counter.py | 2 +- modules/x/current-title.py | 44 ------------------------------------------- 3 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 modules/x/current-title.py (limited to 'modules/scratchpad-counter.py') diff --git a/modules/current-title.py b/modules/current-title.py index 1f0822d..d8cf383 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -15,6 +15,7 @@ CONFIG: 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. """ +POSITION = 0 MAX_WIDTH = 120 CACHED_TIME = 0.5 @@ -36,7 +37,7 @@ class Py3status: self.text = "" super(Py3status).__init__(*args, **kwargs) - def currentTitle(self, json, i3status_config): + def currentTitle(self, i3_status_output_json, i3status_config): window = find_focused(i3.get_tree()) transformed = False @@ -44,8 +45,9 @@ class Py3status: self.text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] transformed = True - return (0, {'full_text': self.text, - 'transformed': transformed, - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME, - }) + return (POSITION, { + 'full_text': self.text, + 'transformed': transformed, + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME, + }) diff --git a/modules/scratchpad-counter.py b/modules/scratchpad-counter.py index 5fc3c71..f2c7dbc 100644 --- a/modules/scratchpad-counter.py +++ b/modules/scratchpad-counter.py @@ -24,7 +24,7 @@ class Py3status: self.count = -1 super(Py3status).__init__(*args, **kwargs) - def currentTitle(self, json, i3status_config): + def scratchpadCounter(self, i3status_output_json, i3status_config): count = len(find_scratch(i3.get_tree()).get("floating_nodes", [])) if self.count != count: diff --git a/modules/x/current-title.py b/modules/x/current-title.py deleted file mode 100644 index 16248d1..0000000 --- a/modules/x/current-title.py +++ /dev/null @@ -1,44 +0,0 @@ -import i3 -import time - -""" -Shows current window title. - -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. -""" - -MAX_WIDTH = 120 -CACHED_TIME = 0.5 - -def find_focused(tree): - if type(tree) == list: - for el in tree: - res = find_focused(el) - if res: - return res - - elif type(tree) == dict: - if tree["focused"]: - return tree - else: - return find_focused(tree["nodes"] + tree["floating_nodes"]) - -class Py3status: - def currentTitle(self, json, i3status_config): - window = find_focused(i3.get_tree()) - - if window and "name" in window: - text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] - - return (0, {'full_text': text, - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME, - }) -- cgit v1.3 From ab38f5686d6c0c2fa658743e4e0d18ae0f7af76e Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Thu, 22 May 2014 17:03:09 +0300 Subject: added battery level, current keyboard layout --- modules/battery-level.py | 59 ++++++++++++++++++++++++++++++++++++++ modules/current-keyboard-layout.py | 33 +++++++++++++++++++++ modules/current-title.py | 12 ++++---- modules/scratchpad-counter.py | 12 ++++++-- 4 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 modules/battery-level.py create mode 100644 modules/current-keyboard-layout.py (limited to 'modules/scratchpad-counter.py') 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": -- cgit v1.3 From 9d1b932062fc4d9a236098c33ee8d2e447df3d41 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Tue, 27 May 2014 12:30:22 +0200 Subject: PEP8 and cleanup of scratchpad-counter module --- modules/scratchpad-counter.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'modules/scratchpad-counter.py') diff --git a/modules/scratchpad-counter.py b/modules/scratchpad-counter.py index b1cdd73..390745f 100644 --- a/modules/scratchpad-counter.py +++ b/modules/scratchpad-counter.py @@ -1,20 +1,20 @@ +# -*- coding: utf-8 -*- + import i3 -import time -import random -from pprint import pprint +from time import time """ 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 # hide indicator when there is no windows -STRFORMAT = "{} ⌫" # format of indicator. {} replaces with count of windows +CACHE_TIMEOUT = 5 +HIDE_WHEN_NONE = False # hide indicator when there is no windows +POSITION = 0 +STRFORMAT = "{} ⌫" # format of indicator. {} replaces with count of windows + def find_scratch(tree): if tree["name"] == "__i3_scratch": @@ -24,15 +24,14 @@ def find_scratch(tree): result = find_scratch(x) if result: return result - return None + class Py3status: - def __init__(self, *args, **kwargs): + def __init__(self): self.count = -1 - super(Py3status).__init__(*args, **kwargs) - def scratchpadCounter(self, i3status_output_json, i3status_config): + def scratchpad_counter(self, i3status_output_json, i3status_config): count = len(find_scratch(i3.get_tree()).get("floating_nodes", [])) if self.count != count: @@ -41,9 +40,11 @@ class Py3status: else: transformed = False - return (POSITION, { - 'transformed': transformed, - 'full_text': '' if HIDE_WHEN_NONE and count == 0 else STRFORMAT.format(count), - 'name': 'scratchpad-count', - 'cached_until': time.time() + CACHED_TIME, - }) + response = { + 'cached_until': time() + CACHE_TIMEOUT, + 'full_text': '' if HIDE_WHEN_NONE and count == 0 else STRFORMAT.format(count), + 'name': 'scratchpad-counter', + 'transformed': transformed + } + + return (POSITION, response) -- cgit v1.3