From d9f15faaf6a61380a51c99349932718a181513f4 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Sat, 3 May 2014 19:36:39 +0200 Subject: rename examples folder to the modules and prepare for installation --- modules/__init__.py | 0 modules/dpms.py | 44 ++++++++++++++ modules/empty_class.py | 41 +++++++++++++ modules/glpi.py | 52 ++++++++++++++++ modules/i3bar_click_events.py | 127 +++++++++++++++++++++++++++++++++++++++ modules/netdata.py | 132 ++++++++++++++++++++++++++++++++++++++++ modules/ns_checker.py | 57 ++++++++++++++++++ modules/pingdom.py | 59 ++++++++++++++++++ modules/pomodoro.py | 123 +++++++++++++++++++++++++++++++++++++ modules/sysdata.py | 137 ++++++++++++++++++++++++++++++++++++++++++ modules/weather_yahoo.py | 106 ++++++++++++++++++++++++++++++++ modules/whoami.py | 26 ++++++++ 12 files changed, 904 insertions(+) create mode 100644 modules/__init__.py create mode 100644 modules/dpms.py create mode 100644 modules/empty_class.py create mode 100644 modules/glpi.py create mode 100644 modules/i3bar_click_events.py create mode 100644 modules/netdata.py create mode 100644 modules/ns_checker.py create mode 100644 modules/pingdom.py create mode 100644 modules/pomodoro.py create mode 100644 modules/sysdata.py create mode 100644 modules/weather_yahoo.py create mode 100644 modules/whoami.py (limited to 'modules') diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/dpms.py b/modules/dpms.py new file mode 100644 index 0000000..783c53c --- /dev/null +++ b/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/modules/empty_class.py b/modules/empty_class.py new file mode 100644 index 0000000..077269c --- /dev/null +++ b/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/modules/glpi.py b/modules/glpi.py new file mode 100644 index 0000000..929749d --- /dev/null +++ b/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/modules/i3bar_click_events.py b/modules/i3bar_click_events.py new file mode 100644 index 0000000..792965c --- /dev/null +++ b/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 = { + "": { +