From d9747b64e1e62abee12ef0bafd365cf380ff7fe9 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Sun, 23 Nov 2014 20:55:53 +0100 Subject: move modules folder so we can install it as a module of py3status --- py3status/modules/__init__.py | 0 py3status/modules/battery-level.py | 68 +++++++++++++ py3status/modules/clementine.py | 65 +++++++++++++ py3status/modules/dpms.py | 44 +++++++++ py3status/modules/empty_class.py | 41 ++++++++ py3status/modules/glpi.py | 52 ++++++++++ py3status/modules/i3bar_click_events.py | 127 +++++++++++++++++++++++++ py3status/modules/imap.py | 58 ++++++++++++ py3status/modules/keyboard-layout.py | 73 ++++++++++++++ py3status/modules/mpd_status.py | 117 +++++++++++++++++++++++ py3status/modules/net_rate.py | 163 ++++++++++++++++++++++++++++++++ py3status/modules/netdata.py | 132 ++++++++++++++++++++++++++ py3status/modules/ns_checker.py | 57 +++++++++++ py3status/modules/pingdom.py | 59 ++++++++++++ py3status/modules/pomodoro.py | 123 ++++++++++++++++++++++++ py3status/modules/scratchpad-counter.py | 50 ++++++++++ py3status/modules/sysdata.py | 148 +++++++++++++++++++++++++++++ py3status/modules/vnstat.py | 138 +++++++++++++++++++++++++++ py3status/modules/weather_yahoo.py | 106 +++++++++++++++++++++ py3status/modules/whoami.py | 26 +++++ py3status/modules/window-title.py | 58 ++++++++++++ 21 files changed, 1705 insertions(+) create mode 100644 py3status/modules/__init__.py create mode 100644 py3status/modules/battery-level.py create mode 100644 py3status/modules/clementine.py create mode 100644 py3status/modules/dpms.py create mode 100644 py3status/modules/empty_class.py create mode 100644 py3status/modules/glpi.py create mode 100644 py3status/modules/i3bar_click_events.py create mode 100644 py3status/modules/imap.py create mode 100644 py3status/modules/keyboard-layout.py create mode 100644 py3status/modules/mpd_status.py create mode 100644 py3status/modules/net_rate.py create mode 100644 py3status/modules/netdata.py create mode 100644 py3status/modules/ns_checker.py create mode 100644 py3status/modules/pingdom.py create mode 100644 py3status/modules/pomodoro.py create mode 100644 py3status/modules/scratchpad-counter.py create mode 100644 py3status/modules/sysdata.py create mode 100644 py3status/modules/vnstat.py create mode 100644 py3status/modules/weather_yahoo.py create mode 100644 py3status/modules/whoami.py create mode 100644 py3status/modules/window-title.py (limited to 'py3status') diff --git a/py3status/modules/__init__.py b/py3status/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py3status/modules/battery-level.py b/py3status/modules/battery-level.py new file mode 100644 index 0000000..6c30556 --- /dev/null +++ b/py3status/modules/battery-level.py @@ -0,0 +1,68 @@ +# -*- 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/clementine.py b/py3status/modules/clementine.py new file mode 100644 index 0000000..61917b7 --- /dev/null +++ b/py3status/modules/clementine.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +from time import time +from subprocess import check_output + + +class Py3status: + """ + clementine.py + + This module display the current "artist - title" playing in Clementine. + + Last modified: 2014-03-23 + Author: Francois LASSERRE + License: GNU GPL http://www.gnu.org/licenses/gpl.html + """ + def _getMetadatas(self): + """ + Get the current song metadatas (artist - title) + """ + track_id = check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack', shell=True) + metadatas = check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata {}'.format(track_id.decode()), shell=True) + lines = metadatas.decode('utf-8').split('\n') + lines = filter(None, lines) + + now_playing = '' + + if lines: + artist = '' + title = '' + internet_radio = False + + for item in lines: + if item.find('artist:') != -1: + artist = item[8:] + if item.find('title:') != -1: + title = item[7:] + + if title.find('.wav') != -1 or title.find('.mp3') != -1: + title = title[:-4] + if title.find('http') != -1: + title = '' + internet_radio = True + + if artist and title: + now_playing = '♫ {} - {}'.format(artist, title) + elif artist: + now_playing = '♫ {}'.format(artist) + elif title: + now_playing = '♫ {}'.format(title) + elif internet_radio: + now_playing = '♫ Internet Radio' + + return now_playing + + def clementine(self, i3status_output_json, i3status_config): + """ + Get the current "artist - title" and return it. + """ + response = {'full_text': '', 'name': 'clementine'} + + response['cached_until'] = time() + response['full_text'] = self._getMetadatas() + + return (0, response) diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py new file mode 100644 index 0000000..783c53c --- /dev/null +++ b/py3status/modules/dpms.py @@ -0,0 +1,44 @@ +from os import system + + +class Py3status: + """ + This module allows activation and deactivation + of DPMS (Display Power Management Signaling) + by clicking on 'DPMS' in the status bar. + + Written and contributed by @tasse: + Andre Doser + """ + def __init__(self): + """ + Detect current state on start. + """ + self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0 + + def dpms(self, i3status_output_json, i3status_config): + """ + Display a colorful state of DPMS. + """ + result = { + 'full_text': 'DPMS', + 'name': 'dpms' + } + if self.run: + result['color'] = i3status_config['color_good'] + else: + result['color'] = i3status_config['color_bad'] + return (0, result) + + def on_click(self, json, i3status_config, event): + """ + Enable/Disable DPMS on left click. + """ + if event['button'] == 1: + if self.run: + self.run = False + system("xset -dpms") + else: + self.run = True + system("xset +dpms") + system("killall -USR1 py3status") diff --git a/py3status/modules/empty_class.py b/py3status/modules/empty_class.py new file mode 100644 index 0000000..077269c --- /dev/null +++ b/py3status/modules/empty_class.py @@ -0,0 +1,41 @@ +class Py3status: + """ + Empty and basic py3status class. + + NOTE: py3status will NOT execute: + - methods starting with '_' + - methods decorated by @property and @staticmethod + + NOTE: reserved method names: + - 'kill' method for py3status exit notification + - 'on_click' method for click events from i3bar + """ + def kill(self, i3status_output_json, i3status_config): + """ + This method will be called upon py3status exit. + """ + pass + + def on_click(self, i3status_output_json, i3status_config, event): + """ + This method will be called when a click event occurs on this module's + output on the i3bar. + + Example 'event' json object: + {'y': 13, 'x': 1737, 'button': 1, 'name': 'empty', 'instance': 'first'} + """ + pass + + def empty(self, i3status_output_json, i3status_config): + """ + This method will return an empty text message + so it will NOT be displayed on your i3bar. + + If you want something displayed you should write something + in the 'full_text' key of your response. + + See the i3bar protocol spec for more information: + http://i3wm.org/docs/i3bar-protocol.html + """ + response = {'full_text': '', 'name': 'empty', 'instance': 'first'} + return (0, response) diff --git a/py3status/modules/glpi.py b/py3status/modules/glpi.py new file mode 100644 index 0000000..929749d --- /dev/null +++ b/py3status/modules/glpi.py @@ -0,0 +1,52 @@ +# You need MySQL-python from http://pypi.python.org/pypi/MySQL-python +import MySQLdb + + +class Py3status: + """ + This example class demonstrates how to display the current total number of + open tickets from GLPI in your i3bar. + + It features thresholds to colorize the output and forces a low timeout to + limit the impact of a server connectivity problem on your i3bar freshness. + + Note that we don't have to implement a cache layer as it is handled by + py3status automagically. + """ + def count_glpi_open_tickets(self, json, i3status_config): + response = {'full_text': '', 'name': 'glpi_tickets'} + + # user-defined variables + CRIT_THRESHOLD = 20 + WARN_THRESHOLD = 15 + MYSQL_DB = '' + MYSQL_HOST = '' + MYSQL_PASSWD = '' + MYSQL_USER = '' + POSITION = 0 + + mydb = MySQLdb.connect( + host=MYSQL_HOST, + user=MYSQL_USER, + passwd=MYSQL_PASSWD, + db=MYSQL_DB, + connect_timeout=5, + ) + mycr = mydb.cursor() + mycr.execute('''select count(*) + from glpi_tickets + where closedate is NULL and solvedate is NULL;''') + row = mycr.fetchone() + if row: + open_tickets = int(row[0]) + if i3status_config['colors']: + if open_tickets > CRIT_THRESHOLD: + response.update({'color': i3status_config['color_bad']}) + elif open_tickets > WARN_THRESHOLD: + response.update( + {'color': i3status_config['color_degraded']} + ) + response['full_text'] = '%s tickets' % open_tickets + mydb.close() + + return (POSITION, response) diff --git a/py3status/modules/i3bar_click_events.py b/py3status/modules/i3bar_click_events.py new file mode 100644 index 0000000..792965c --- /dev/null +++ b/py3status/modules/i3bar_click_events.py @@ -0,0 +1,127 @@ +from subprocess import Popen +from time import time + + +class Py3status: + """ + This module allows you to take actions based on click events made on + the i3status modules. For example, thanks to this module you could + launch the wicd GUI when clicking on the ethernet or wireless module + of your i3status output ! + + IMPORTANT: + This module file name is reserved and should NOT be changed if you + want py3status to handle your i3status modules click events ! + + The behavior described above will only work if this file is named + 'i3bar_click_events.py' ! + """ + def __init__(self): + """ + This is where you setup your actions based on your i3status config. + + Configuration: + -------------- + self.actions = { + "": { +