From 16324fdad587750dccdac52cf64c5bf15b5d227f Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Mon, 19 May 2014 19:20:40 +0300 Subject: module for displaying current window\'s title --- modules/current-title.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ modules/i3-current-title.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 modules/current-title.py create mode 100644 modules/i3-current-title.py (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py new file mode 100644 index 0000000..c9cdde9 --- /dev/null +++ b/modules/current-title.py @@ -0,0 +1,47 @@ +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): + response = { + 'full_text': 'error', + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME + } + + window = find_focused(i3.get_tree()) + + if window and "name" in window: + response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-MAX_WIDTH:] or window["name"] + + return (0, response) diff --git a/modules/i3-current-title.py b/modules/i3-current-title.py new file mode 100644 index 0000000..6fc05d0 --- /dev/null +++ b/modules/i3-current-title.py @@ -0,0 +1,48 @@ +import i3 +import time +import random + +""" +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): + response = { + 'full_text': 'error', + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME + } + + window = find_focused(i3.get_tree()) + + if window and "name" in window: + response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-MAX_WIDTH:] or window["name"] + + return (0, response) -- cgit v1.3 From a6cd4b91c51e4f9dfb7f09b49a0634f27c2dede8 Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Mon, 19 May 2014 19:20:57 +0300 Subject: module for displaying current window\'s title --- modules/i3-current-title.py | 48 --------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 modules/i3-current-title.py (limited to 'modules') diff --git a/modules/i3-current-title.py b/modules/i3-current-title.py deleted file mode 100644 index 6fc05d0..0000000 --- a/modules/i3-current-title.py +++ /dev/null @@ -1,48 +0,0 @@ -import i3 -import time -import random - -""" -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): - response = { - 'full_text': 'error', - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME - } - - window = find_focused(i3.get_tree()) - - if window and "name" in window: - response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-MAX_WIDTH:] or window["name"] - - return (0, response) -- cgit v1.3 From 3c4b686cabc4c48325b09f158b65f5adf61bb3a6 Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Mon, 19 May 2014 19:31:10 +0300 Subject: module for displaying current window\'s title --- modules/current-title.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py index c9cdde9..f995752 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -42,6 +42,6 @@ class Py3status: window = find_focused(i3.get_tree()) if window and "name" in window: - response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-MAX_WIDTH:] or window["name"] + response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] return (0, response) -- cgit v1.3 From 1ff108ea4931ccf31da7d724298c52de9a839913 Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Mon, 19 May 2014 19:34:51 +0300 Subject: module for displaying current window\'s title --- modules/current-title.py | 13 +++++-------- modules/x/current-title.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 modules/x/current-title.py (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py index f995752..16248d1 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -33,15 +33,12 @@ def find_focused(tree): class Py3status: def currentTitle(self, json, i3status_config): - response = { - 'full_text': 'error', - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME - } - window = find_focused(i3.get_tree()) if window and "name" in window: - response["full_text"] = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] + text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] - return (0, response) + return (0, {'full_text': text, + 'name': 'current-title', + 'cached_until': time.time() + CACHED_TIME, + }) diff --git a/modules/x/current-title.py b/modules/x/current-title.py new file mode 100644 index 0000000..16248d1 --- /dev/null +++ b/modules/x/current-title.py @@ -0,0 +1,44 @@ +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 5608ad5258a682985fd97a11454d60d2274aa88b Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Mon, 19 May 2014 19:35:58 +0300 Subject: module for displaying current windows title --- modules/current-title.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py index 16248d1..ad2b97a 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -2,7 +2,7 @@ import i3 import time """ -Shows current window title. +Py3status plugin - shows current window title. DEPENDENCIES: Depends on i3-py! -- cgit v1.3 From 94c99351d72b91c3f6063fac3c98001ed893b3cd Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Tue, 20 May 2014 11:09:34 +0300 Subject: current-title: updated --- modules/current-title.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py index ad2b97a..1f0822d 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -32,13 +32,20 @@ def find_focused(tree): return find_focused(tree["nodes"] + tree["floating_nodes"]) class Py3status: + def __init__(self, *args, **kwargs): + self.text = "" + super(Py3status).__init__(*args, **kwargs) + 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"] + transformed = False + if window and "name" in window and window["name"] != self.text: + self.text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] + transformed = True - return (0, {'full_text': text, + return (0, {'full_text': self.text, + 'transformed': transformed, 'name': 'current-title', 'cached_until': time.time() + CACHED_TIME, }) -- cgit v1.3 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') 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') 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') 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 cff1906f8d6eab1a01fba07326d3ab5175e52975 Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Thu, 22 May 2014 17:18:24 +0300 Subject: small fix --- modules/battery-level.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/battery-level.py b/modules/battery-level.py index ed6d484..37a25d6 100644 --- a/modules/battery-level.py +++ b/modules/battery-level.py @@ -5,10 +5,6 @@ import math """ Module for displaying information about battery. - -@author shadowprince -@version 1.0 -@license Eclipse Public License """ CACHE_TIME = 30 # time to update battery @@ -49,7 +45,7 @@ class Py3status: if full: response['full_text'] = "" if HIDE_WHEN_FULL else BLOCKS[-1] elif charging: - response['full_text'] = CHARGING_CHAR + response['full_text'] = CHARGING_CHARACTER response['color'] = COLOR_CHARGING else: response['full_text'] = character -- cgit v1.3 From 61db2ac48f633db4d1b7c3ee82fa8baf06f3e82b Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Fri, 23 May 2014 22:44:43 +0300 Subject: coding header for battery level --- modules/battery-level.py | 1 + 1 file changed, 1 insertion(+) (limited to 'modules') diff --git a/modules/battery-level.py b/modules/battery-level.py index 37a25d6..02b7e43 100644 --- a/modules/battery-level.py +++ b/modules/battery-level.py @@ -1,3 +1,4 @@ +# -*- coding: utf8 -*- import subprocess import time import re -- cgit v1.3 From fbac7ee6d51f82756e3cd17a31f7d212f5f6dd3c Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Sat, 24 May 2014 00:07:52 +0300 Subject: mpd module --- modules/battery-level.py | 4 ++ modules/current-title.py | 5 +-- modules/mpd.py | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 modules/mpd.py (limited to 'modules') diff --git a/modules/battery-level.py b/modules/battery-level.py index 02b7e43..fb3b769 100644 --- a/modules/battery-level.py +++ b/modules/battery-level.py @@ -6,6 +6,10 @@ import math """ Module for displaying information about battery. + +@author shadowprince +@version 1.0 +@license Eclipse Public License """ CACHE_TIME = 30 # time to update battery diff --git a/modules/current-title.py b/modules/current-title.py index e2f5aef..530908f 100644 --- a/modules/current-title.py +++ b/modules/current-title.py @@ -4,9 +4,8 @@ import time """ Py3status plugin - shows current window title. -DEPENDENCIES: - Depends on i3-py! - pip install i3-py +DEPENDENCIES: Depends on i3-py: + # pip install i3-py 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. diff --git a/modules/mpd.py b/modules/mpd.py new file mode 100644 index 0000000..e94872c --- /dev/null +++ b/modules/mpd.py @@ -0,0 +1,112 @@ +from mpd import (MPDClient, CommandError) +from socket import error as SocketError +import time +import re + +""" +Mpd - module to show information from mpd to your's bar! Settings listed above. +DEPENDENCIES: python-mpd2 (NOT python2-mpd2): + # pip install python-mpd2 + +@author shadowprince +@version 1.0 +@license Eclipse Public License +""" + +# mpd settings +HOST = "localhost" +PORT = "6600" +PASSWORD = None + +# time to update +CACHED_TIME = 1 + +# position +POSITION = 1 + +# if text length will be greater - it'll shrink it +MAX_WIDTH = 120 + +# hide any indicator, if +HIDE_WHEN_PAUSED = False +HIDE_WHEN_STOPPED = True + +# state characters (or strings). Actual of them replaces {state} placeholder in STRFORMAT +STATE_CHARACTERS = { + "pause": "[pause]", + "play": "[play]", + "stop": "[stop]", +} + +""" format of result string +can contain: + {state} - current state from STATE_CHARACTERS + Track information: + {track}, {artist}, {title}, {time}, {album}, {pos} + In additional, information about next track also comes in, in analogue with current, but with next_ prefix, + like {next_title} +""" +STRFORMAT = "{state} №{pos}. {artist} - {title} [{time}] | {next_title}" + +class Py3status: + def __init__(self, *args, **kwargs): + self.text = "" + super(Py3status).__init__(*args, **kwargs) + + def currentTrack(self, i3status_output_json, i3status_config): + try: + c = MPDClient() + c.connect(host=HOST, port=PORT) + if PASSWORD: + c.password(PASSWORD) + + status = c.status() + song = int(status.get("song", 0)) + next_song = int(status.get("nextsong", 0)) + + if (status["state"] == "pause" and HIDE_WHEN_PAUSED) or (status["state"] == "stop" and HIDE_WHEN_STOPPED): + text = "" + else: + try: + song = c.playlistinfo()[song] + song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60) + except IndexError: + song = {} + + try: + next_song = c.playlistinfo()[next_song] + except IndexError: + next_song = {} + + format_args = song + format_args["state"] = STATE_CHARACTERS.get(status.get("state", None)) + for k, v in next_song.items(): + format_args["next_{}".format(k)] = v + + text = STRFORMAT + for k, v in format_args.items(): + text = text.replace("{" + k + "}", v) + + for sub in re.findall(r"{\S+?}", text): + text = text.replace(sub, "") + except SocketError: + text = "Failed to connect to mpd!" + except CommandError: + text = "Failed to authenticate to mpd!" + c.disconnect() + + if len(text) > MAX_WIDTH: + text = text[-MAX_WIDTH-3:] + "..." + + if self.text != text: + transformed = True + self.text = text + else: + transformed = False + + return (POSITION, { + 'transformed': transformed, + 'full_text': self.text, + 'name': 'scratchpad-count', + 'cached_until': time.time() + CACHED_TIME, + }) -- cgit v1.3 From dfc2dc3d2a2ed5c13223beae97976004122fdd83 Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Sun, 25 May 2014 12:58:51 +0300 Subject: rename mpd module to mpd_status to avoid conflict --- modules/mpd.py | 112 -------------------------------------------------- modules/mpd_status.py | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 112 deletions(-) delete mode 100644 modules/mpd.py create mode 100644 modules/mpd_status.py (limited to 'modules') diff --git a/modules/mpd.py b/modules/mpd.py deleted file mode 100644 index e94872c..0000000 --- a/modules/mpd.py +++ /dev/null @@ -1,112 +0,0 @@ -from mpd import (MPDClient, CommandError) -from socket import error as SocketError -import time -import re - -""" -Mpd - module to show information from mpd to your's bar! Settings listed above. -DEPENDENCIES: python-mpd2 (NOT python2-mpd2): - # pip install python-mpd2 - -@author shadowprince -@version 1.0 -@license Eclipse Public License -""" - -# mpd settings -HOST = "localhost" -PORT = "6600" -PASSWORD = None - -# time to update -CACHED_TIME = 1 - -# position -POSITION = 1 - -# if text length will be greater - it'll shrink it -MAX_WIDTH = 120 - -# hide any indicator, if -HIDE_WHEN_PAUSED = False -HIDE_WHEN_STOPPED = True - -# state characters (or strings). Actual of them replaces {state} placeholder in STRFORMAT -STATE_CHARACTERS = { - "pause": "[pause]", - "play": "[play]", - "stop": "[stop]", -} - -""" format of result string -can contain: - {state} - current state from STATE_CHARACTERS - Track information: - {track}, {artist}, {title}, {time}, {album}, {pos} - In additional, information about next track also comes in, in analogue with current, but with next_ prefix, - like {next_title} -""" -STRFORMAT = "{state} №{pos}. {artist} - {title} [{time}] | {next_title}" - -class Py3status: - def __init__(self, *args, **kwargs): - self.text = "" - super(Py3status).__init__(*args, **kwargs) - - def currentTrack(self, i3status_output_json, i3status_config): - try: - c = MPDClient() - c.connect(host=HOST, port=PORT) - if PASSWORD: - c.password(PASSWORD) - - status = c.status() - song = int(status.get("song", 0)) - next_song = int(status.get("nextsong", 0)) - - if (status["state"] == "pause" and HIDE_WHEN_PAUSED) or (status["state"] == "stop" and HIDE_WHEN_STOPPED): - text = "" - else: - try: - song = c.playlistinfo()[song] - song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60) - except IndexError: - song = {} - - try: - next_song = c.playlistinfo()[next_song] - except IndexError: - next_song = {} - - format_args = song - format_args["state"] = STATE_CHARACTERS.get(status.get("state", None)) - for k, v in next_song.items(): - format_args["next_{}".format(k)] = v - - text = STRFORMAT - for k, v in format_args.items(): - text = text.replace("{" + k + "}", v) - - for sub in re.findall(r"{\S+?}", text): - text = text.replace(sub, "") - except SocketError: - text = "Failed to connect to mpd!" - except CommandError: - text = "Failed to authenticate to mpd!" - c.disconnect() - - if len(text) > MAX_WIDTH: - text = text[-MAX_WIDTH-3:] + "..." - - if self.text != text: - transformed = True - self.text = text - else: - transformed = False - - return (POSITION, { - 'transformed': transformed, - 'full_text': self.text, - 'name': 'scratchpad-count', - 'cached_until': time.time() + CACHED_TIME, - }) diff --git a/modules/mpd_status.py b/modules/mpd_status.py new file mode 100644 index 0000000..e94872c --- /dev/null +++ b/modules/mpd_status.py @@ -0,0 +1,112 @@ +from mpd import (MPDClient, CommandError) +from socket import error as SocketError +import time +import re + +""" +Mpd - module to show information from mpd to your's bar! Settings listed above. +DEPENDENCIES: python-mpd2 (NOT python2-mpd2): + # pip install python-mpd2 + +@author shadowprince +@version 1.0 +@license Eclipse Public License +""" + +# mpd settings +HOST = "localhost" +PORT = "6600" +PASSWORD = None + +# time to update +CACHED_TIME = 1 + +# position +POSITION = 1 + +# if text length will be greater - it'll shrink it +MAX_WIDTH = 120 + +# hide any indicator, if +HIDE_WHEN_PAUSED = False +HIDE_WHEN_STOPPED = True + +# state characters (or strings). Actual of them replaces {state} placeholder in STRFORMAT +STATE_CHARACTERS = { + "pause": "[pause]", + "play": "[play]", + "stop": "[stop]", +} + +""" format of result string +can contain: + {state} - current state from STATE_CHARACTERS + Track information: + {track}, {artist}, {title}, {time}, {album}, {pos} + In additional, information about next track also comes in, in analogue with current, but with next_ prefix, + like {next_title} +""" +STRFORMAT = "{state} №{pos}. {artist} - {title} [{time}] | {next_title}" + +class Py3status: + def __init__(self, *args, **kwargs): + self.text = "" + super(Py3status).__init__(*args, **kwargs) + + def currentTrack(self, i3status_output_json, i3status_config): + try: + c = MPDClient() + c.connect(host=HOST, port=PORT) + if PASSWORD: + c.password(PASSWORD) + + status = c.status() + song = int(status.get("song", 0)) + next_song = int(status.get("nextsong", 0)) + + if (status["state"] == "pause" and HIDE_WHEN_PAUSED) or (status["state"] == "stop" and HIDE_WHEN_STOPPED): + text = "" + else: + try: + song = c.playlistinfo()[song] + song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60) + except IndexError: + song = {} + + try: + next_song = c.playlistinfo()[next_song] + except IndexError: + next_song = {} + + format_args = song + format_args["state"] = STATE_CHARACTERS.get(status.get("state", None)) + for k, v in next_song.items(): + format_args["next_{}".format(k)] = v + + text = STRFORMAT + for k, v in format_args.items(): + text = text.replace("{" + k + "}", v) + + for sub in re.findall(r"{\S+?}", text): + text = text.replace(sub, "") + except SocketError: + text = "Failed to connect to mpd!" + except CommandError: + text = "Failed to authenticate to mpd!" + c.disconnect() + + if len(text) > MAX_WIDTH: + text = text[-MAX_WIDTH-3:] + "..." + + if self.text != text: + transformed = True + self.text = text + else: + transformed = False + + return (POSITION, { + 'transformed': transformed, + 'full_text': self.text, + 'name': 'scratchpad-count', + 'cached_until': time.time() + CACHED_TIME, + }) -- cgit v1.3 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(-) (limited to 'modules') 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 From f4a2a2cb22770f298c13904f05049f0c17c8c3c0 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Mon, 26 May 2014 19:12:26 +0200 Subject: rename current-keyboard-layout to keyboard-layout, PEP8 cleanup, implement check using setxkbmap for maximal compatibility, add french coloring --- modules/current-keyboard-layout.py | 33 ------------------ modules/keyboard-layout.py | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 33 deletions(-) delete mode 100644 modules/current-keyboard-layout.py create mode 100644 modules/keyboard-layout.py (limited to 'modules') diff --git a/modules/current-keyboard-layout.py b/modules/current-keyboard-layout.py deleted file mode 100644 index 046a2aa..0000000 --- a/modules/current-keyboard-layout.py +++ /dev/null @@ -1,33 +0,0 @@ -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/keyboard-layout.py b/modules/keyboard-layout.py new file mode 100644 index 0000000..be1f72d --- /dev/null +++ b/modules/keyboard-layout.py @@ -0,0 +1,70 @@ +from subprocess import check_output +from time import time + +""" +Module for showing current keyboard layout. + +Requires: + - xkblayout-state + or + - setxkbmap + +@author shadowprince +@license Eclipse Public License +""" + +CACHE_TIME = 10 # refresh time to update indicator + +# colors of layouts, check your command's output to match keys +LANG_COLORS = { + 'fr': '#668FBA', # blue + 'ru': '#F75252', # red + 'ua': '#FCE94F', # yellow + 'us': '#729FCF', # light blue +} + + +def xbklayout(): + """ + check using xkblayout-state (preferred method) + """ + return check_output( + ["xkblayout-state", "print", "%s"] + ).decode('utf-8') + + +def setxkbmap(): + """ + check using setxkbmap >= 1.3.0 + """ + q = check_output(['setxkbmap', '-query']).decode('utf-8') + return q.replace(' ', '').split(':')[-1] + + +class Py3status: + def __init__(self): + """ + find the best implementation to get the keyboard's layout + """ + try: + xbklayout() + except: + self.command = setxkbmap + else: + self.command = xbklayout + + def keyboard_layout(self, i3status_output_json, i3status_config): + response = { + 'full_text': '', + 'name': 'keyboard-layout', + 'cached_until': time() + CACHE_TIME + } + + lang = self.command().strip() + lang_color = LANG_COLORS.get(lang) + + response['full_text'] = lang or '??' + if lang_color: + response['color'] = lang_color + + return (0, response) -- cgit v1.3 From 509506c4a89cab9863a25bb3e74bc10e64c0be53 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Mon, 26 May 2014 19:18:07 +0200 Subject: switch french color to solarized blue on keyboard-layout module --- modules/keyboard-layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/keyboard-layout.py b/modules/keyboard-layout.py index be1f72d..6fd4019 100644 --- a/modules/keyboard-layout.py +++ b/modules/keyboard-layout.py @@ -17,7 +17,7 @@ CACHE_TIME = 10 # refresh time to update indicator # colors of layouts, check your command's output to match keys LANG_COLORS = { - 'fr': '#668FBA', # blue + 'fr': '#268BD2', # solarized blue 'ru': '#F75252', # red 'ua': '#FCE94F', # yellow 'us': '#729FCF', # light blue -- cgit v1.3 From a818e91ed70bb50eb2e05fd162d6d62cc150c546 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Tue, 27 May 2014 12:29:07 +0200 Subject: PEP8 and rename the current-title to window-title, normalization --- modules/current-title.py | 52 ------------------------------------------- modules/window-title.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 52 deletions(-) delete mode 100644 modules/current-title.py create mode 100644 modules/window-title.py (limited to 'modules') diff --git a/modules/current-title.py b/modules/current-title.py deleted file mode 100644 index 530908f..0000000 --- a/modules/current-title.py +++ /dev/null @@ -1,52 +0,0 @@ -import i3 -import time - -""" -Py3status plugin - shows current window title. - -DEPENDENCIES: Depends on i3-py: - # pip install i3-py - -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 # 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: - 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 __init__(self, *args, **kwargs): - self.text = "" - super(Py3status).__init__(*args, **kwargs) - - def currentTitle(self, i3_status_output_json, i3status_config): - window = find_focused(i3.get_tree()) - - transformed = False - if window and "name" in window and window["name"] != self.text: - self.text = len(window["name"]) > MAX_WIDTH and "..." + window["name"][-(MAX_WIDTH-3):] or window["name"] - transformed = True - - return (POSITION, { - 'full_text': self.text, - 'transformed': transformed, - 'name': 'current-title', - 'cached_until': time.time() + CACHED_TIME, - }) diff --git a/modules/window-title.py b/modules/window-title.py new file mode 100644 index 0000000..4f6f062 --- /dev/null +++ b/modules/window-title.py @@ -0,0 +1,58 @@ +import i3 +from time import time + +""" +Py3status plugin - shows current window title. + +Requires: + - i3-py (https://github.com/ziberna/i3-py) + # pip install i3-py + +If payload from server contains wierd utf-8 +(for example one window have something bad in title) - the plugin will +give empty output UNTIL this window is closed. +I can't fix or workaround that in PLUGIN, problem is in i3-py library. + +@author shadowprince +@license Eclipse Public License +""" + +CACHE_TIMEOUT = 0.5 # maximum time to update indicator +MAX_WIDTH = 120 # if width of title is greater, shrink it and add '...' +POSITION = 0 + + +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 __init__(self): + self.text = '' + + def window_title(self, i3_status_output_json, i3status_config): + window = find_focused(i3.get_tree()) + + transformed = False + if window and 'name' in window and window['name'] != self.text: + self.text = len(window['name']) > MAX_WIDTH and "..." + window['name'][-(MAX_WIDTH-3):] or window['name'] + transformed = True + + response = { + 'cached_until': time() + CACHE_TIMEOUT, + 'full_text': self.text, + 'name': 'window-title', + 'transformed': transformed + } + + return (POSITION, response) -- cgit v1.3 From 7e88e29f9dc1bae8b7eef767fd6358143a185ae2 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Tue, 27 May 2014 12:29:49 +0200 Subject: PEP8 and normalization of mpd_status module --- modules/mpd_status.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/mpd_status.py b/modules/mpd_status.py index e94872c..28e99dc 100644 --- a/modules/mpd_status.py +++ b/modules/mpd_status.py @@ -1,15 +1,18 @@ +# -*- coding: utf-8 -*- + +import re + from mpd import (MPDClient, CommandError) from socket import error as SocketError -import time -import re +from time import time """ Mpd - module to show information from mpd to your's bar! Settings listed above. -DEPENDENCIES: python-mpd2 (NOT python2-mpd2): +Reequires + - python-mpd2 (NOT python2-mpd2) # pip install python-mpd2 @author shadowprince -@version 1.0 @license Eclipse Public License """ @@ -19,10 +22,10 @@ PORT = "6600" PASSWORD = None # time to update -CACHED_TIME = 1 +CACHE_TIMEOUT = 1 # position -POSITION = 1 +POSITION = 0 # if text length will be greater - it'll shrink it MAX_WIDTH = 120 @@ -39,7 +42,7 @@ STATE_CHARACTERS = { } """ format of result string -can contain: +can contain: {state} - current state from STATE_CHARACTERS Track information: {track}, {artist}, {title}, {time}, {album}, {pos} @@ -48,13 +51,13 @@ can contain: """ STRFORMAT = "{state} №{pos}. {artist} - {title} [{time}] | {next_title}" + class Py3status: - def __init__(self, *args, **kwargs): - self.text = "" - super(Py3status).__init__(*args, **kwargs) + def __init__(self): + self.text = '' def currentTrack(self, i3status_output_json, i3status_config): - try: + try: c = MPDClient() c.connect(host=HOST, port=PORT) if PASSWORD: @@ -104,9 +107,11 @@ class Py3status: else: transformed = False - return (POSITION, { - 'transformed': transformed, - 'full_text': self.text, - 'name': 'scratchpad-count', - 'cached_until': time.time() + CACHED_TIME, - }) + response = { + 'cached_until': time() + CACHE_TIMEOUT, + 'full_text': self.text, + 'name': 'scratchpad-count', + 'transformed': transformed + } + + return (POSITION, response) -- 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') 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 From 277b0008c2d779a98605737bc91ca75e6b364728 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Tue, 27 May 2014 12:31:44 +0200 Subject: normalize the CACHE_TIMEOUT variable name --- modules/battery-level.py | 4 ++-- modules/keyboard-layout.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/battery-level.py b/modules/battery-level.py index 4d94311..6c30556 100644 --- a/modules/battery-level.py +++ b/modules/battery-level.py @@ -17,7 +17,7 @@ Requires: @license Eclipse Public License """ -CACHE_TIME = 30 # time to update battery +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 @@ -63,6 +63,6 @@ class Py3status: else: response['full_text'] = character - response['cached_until'] = time() + CACHE_TIME + response['cached_until'] = time() + CACHE_TIMEOUT return (0, response) diff --git a/modules/keyboard-layout.py b/modules/keyboard-layout.py index 6fd4019..97ef716 100644 --- a/modules/keyboard-layout.py +++ b/modules/keyboard-layout.py @@ -13,7 +13,7 @@ Requires: @license Eclipse Public License """ -CACHE_TIME = 10 # refresh time to update indicator +CACHE_TIMEOUT = 10 # refresh time to update indicator # colors of layouts, check your command's output to match keys LANG_COLORS = { @@ -57,7 +57,7 @@ class Py3status: response = { 'full_text': '', 'name': 'keyboard-layout', - 'cached_until': time() + CACHE_TIME + 'cached_until': time() + CACHE_TIMEOUT } lang = self.command().strip() -- cgit v1.3 From e42f84cb9954942b3b604a05fb1933b54ecef5f4 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Fri, 30 May 2014 11:44:36 +0200 Subject: add an information note in the keyboard module --- modules/keyboard-layout.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules') diff --git a/modules/keyboard-layout.py b/modules/keyboard-layout.py index 97ef716..1ed3cee 100644 --- a/modules/keyboard-layout.py +++ b/modules/keyboard-layout.py @@ -36,6 +36,9 @@ def xbklayout(): def setxkbmap(): """ check using setxkbmap >= 1.3.0 + + 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] -- cgit v1.3