diff options
28 files changed, 287 insertions, 83 deletions
@@ -1,24 +1,28 @@ -Copyright (c) 2013 Ultrabug, http://www.ultrabug.fr +Copyright (c) 2013-2015 Ultrabug and contributors All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + * Neither the name of Ultrabug nor the + names of contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. @@ -14,7 +14,7 @@ Using py3status, you can take control of your i3bar easily by: - handling click events on your i3bar and play with them in no time - seeing your clock tick every second whatever your i3status interval -No extra configuration file needed, just install & enjoy ! +**No extra configuration file needed**, just install & enjoy ! Documentation ============= @@ -40,16 +40,29 @@ Get help or share your ideas on IRC: Usage ===== -In your i3 config file, simply switch from `i3status` to `py3status` in your `status_command`: +In your i3 config file, simply switch from *i3status* to *py3status* in your *status_command*: :: + status_command py3status Usually you have your own i3status configuration, just point to it: :: + status_command py3status -c ~/.i3/i3status.conf Available modules ================= +You can get a list and short description of all the available modules by using the CLI: +:: + + $ py3status modules list + + +To get more details about all the available modules, use: +:: + + $ py3status modules details + All the modules shipped with py3status are present in the sources in the `py3status/modules <https://github.com/ultrabug/py3status/tree/master/py3status/modules>`_ folder. Most of them are **configurable directly from your current i3status.conf**, check them out to see all the configurable variables. @@ -60,30 +73,37 @@ Pypi ---- Using pip: :: + $ pip install py3status +NB: **Debian users** should use **pypi-install** from the *python-stdeb* package instead of pip. + Gentoo Linux ------------ Using emerge: :: + $ sudo emerge -a py3status Arch Linux ---------- Thanks to @waaaaargh, py3status is present in the Arch User Repository using this URL: :: + https://aur.archlinux.org/packages/py3status-git/ Fedora ------ Using yum: :: + $ yum install py3status Options ======= You can see the help of py3status by issuing `py3status -h`: :: + -h, --help show this help message and exit -c I3STATUS_CONF, --config I3STATUS_CONF path to i3status config file @@ -104,4 +124,5 @@ Control Just like i3status, you can force an update of your i3bar by sending a SIGUSR1 signal to py3status. Note that this will also send a SIGUSR1 signal to i3status. :: + killall -USR1 py3status diff --git a/py3status/modules/empty_class.py b/doc/example_module.py index 9a58189..7db53fd 100644 --- a/py3status/modules/empty_class.py +++ b/doc/example_module.py @@ -85,11 +85,11 @@ class Py3status: output on the i3bar. Example 'event' json object: - {'y': 13, 'x': 1737, 'button': 1, 'name': 'empty', 'instance': 'first'} + {'y': 13, 'x': 17, 'button': 1, 'name': 'example', 'instance': 'first'} """ pass - def empty(self, i3s_output_list, i3s_config): + def example_method(self, i3s_output_list, i3s_config): """ This method will return an empty text message so it will NOT be displayed on your i3bar. @@ -114,8 +114,9 @@ if __name__ == "__main__": from time import sleep x = Py3status() config = { - 'color_good': '#00FF00', 'color_bad': '#FF0000', + 'color_degraded': '#FFFF00', + 'color_good': '#00FF00' } while True: print(x.empty([], config)) diff --git a/py3status/__init__.py b/py3status/__init__.py index 25f608a..9d877c8 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -1068,8 +1068,7 @@ class Module(Thread): if self.config['debug']: syslog( LOG_INFO, - 'method {} returned {} '.format(meth, result) + - 'for position {}'.format(position) + 'method {} returned {} '.format(meth, result) ) except Exception: err = sys.exc_info()[1] @@ -1639,8 +1638,6 @@ class Py3statusWrapper(): print_stderr('Available modules:') for mod_name, mod_path in sorted(user_modules.items()): - if mod_name == 'empty_class': - continue self.print_module_description(details, mod_name, mod_path) elif cmd[:2] in (['modules', 'enable'], ['modules', 'disable']): # TODO: to be implemented diff --git a/py3status/modules/battery_level.py b/py3status/modules/battery_level.py index f3cbb37..ae8fe33 100644 --- a/py3status/modules/battery_level.py +++ b/py3status/modules/battery_level.py @@ -1,11 +1,11 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- """ -Module for displaying information about battery. +Display the battery level. Requires: - the 'acpi' command line -@author shadowprince and AdamBSteele +@author shadowprince, AdamBSteele @license Eclipse Public License """ diff --git a/py3status/modules/bitcoin_price.py b/py3status/modules/bitcoin_price.py index 656797c..477394f 100644 --- a/py3status/modules/bitcoin_price.py +++ b/py3status/modules/bitcoin_price.py @@ -1,10 +1,8 @@ # -*- coding: utf-8 -*- """ -Module for displaying bitcoin prices using -the API by www.bitcoincharts.com. +Display bitcoin prices using bitcoincharts.com. -Written and contributed by @tasse: - Andre Doser <doser.andre AT gmail.com> +@author Andre Doser <doser.andre AT gmail.com> """ import json diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py index cd09945..3818325 100644 --- a/py3status/modules/bluetooth.py +++ b/py3status/modules/bluetooth.py @@ -1,6 +1,6 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- """ -This module displays bluetooth status. +Display bluetooth status. Requires: - hcitool diff --git a/py3status/modules/clementine.py b/py3status/modules/clementine.py index faadf1e..2c5c66f 100644 --- a/py3status/modules/clementine.py +++ b/py3status/modules/clementine.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- """ -This module displays the current "artist - title" playing in Clementine. +Display the current "artist - title" playing in Clementine. -Last modified: 2014-03-23 -Author: Francois LASSERRE <choiz@me.com> -License: GNU GPL http://www.gnu.org/licenses/gpl.html +@author Francois LASSERRE <choiz@me.com> +@license GNU GPL http://www.gnu.org/licenses/gpl.html """ from time import time diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py index bcef53c..0753df4 100644 --- a/py3status/modules/dpms.py +++ b/py3status/modules/dpms.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- """ +Activate or deactivate DPMS and screen blanking. + 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 <dosera AT tf.uni-freiburg.de> +@author Andre Doser <dosera AT tf.uni-freiburg.de> """ from os import system diff --git a/py3status/modules/glpi.py b/py3status/modules/glpi.py index db648e0..708ed4f 100644 --- a/py3status/modules/glpi.py +++ b/py3status/modules/glpi.py @@ -1,13 +1,9 @@ # -*- coding: utf-8 -*- """ -This example class demonstrates how to display the current total number of -open tickets from GLPI in your i3bar. +Display the total number of open tickets from GLPI. 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. """ # You need MySQL-python from http://pypi.python.org/pypi/MySQL-python diff --git a/py3status/modules/imap.py b/py3status/modules/imap.py index ff53f02..47661f1 100644 --- a/py3status/modules/imap.py +++ b/py3status/modules/imap.py @@ -1,8 +1,6 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- """ -Module displaying the number of unread messages -on an IMAP inbox (configurable, may also be a -comma-separated list of IMAP folders). +Display the unread messages count from your IMAP account. @author obb """ diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py index f7a570c..d8eb7cc 100644 --- a/py3status/modules/keyboard_layout.py +++ b/py3status/modules/keyboard_layout.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Module for showing current keyboard layout. +Display the current keyboard layout. Requires: - xkblayout-state diff --git a/py3status/modules/mpd_status.py b/py3status/modules/mpd_status.py index 10f3c99..a30830e 100644 --- a/py3status/modules/mpd_status.py +++ b/py3status/modules/mpd_status.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- """ -Mpd - module to show information from mpd in your i3bar. -Reequires +Display information from mpd. + +Requires: - python-mpd2 (NOT python2-mpd2) # pip install python-mpd2 diff --git a/py3status/modules/net_rate.py b/py3status/modules/net_rate.py index 876f6cb..961578b 100644 --- a/py3status/modules/net_rate.py +++ b/py3status/modules/net_rate.py @@ -1,6 +1,6 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- """ -Module for displaying current network transfer rate. +Display the current network transfer rate. @author shadowprince @license Eclipse Public License diff --git a/py3status/modules/netdata.py b/py3status/modules/netdata.py index fe9406f..c43ad06 100644 --- a/py3status/modules/netdata.py +++ b/py3status/modules/netdata.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -Display network information (Linux systems) in i3bar. +Display network speed and bandwidth usage. -Copyright (C) <2013> <Shahin Azad [ishahinism at Gmail]> +@author Shahin Azad <ishahinism at Gmail> """ import subprocess diff --git a/py3status/modules/ns_checker.py b/py3status/modules/ns_checker.py index 5fa6384..d21bbb0 100644 --- a/py3status/modules/ns_checker.py +++ b/py3status/modules/ns_checker.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- """ +Display DNS resolution success on a configured domain. + This module launch a simple query on each nameservers for the specified domain. Nameservers are dynamically retrieved. The FQDN is the only one mandatory parameter. It's also possible to add additional nameservers by appending them in nameservers list. The default resolver can be overwritten with my_resolver.nameservers parameter. -Written and contributed by @nawadanp +@author nawadanp """ import dns.resolver diff --git a/py3status/modules/online_status.py b/py3status/modules/online_status.py index 8cc6eeb..8176d21 100644 --- a/py3status/modules/online_status.py +++ b/py3status/modules/online_status.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Module displaying if a connection to the internet is established. +Display if a connection to the internet is established. @author obb """ diff --git a/py3status/modules/pingdom.py b/py3status/modules/pingdom.py index c4ec473..f47da68 100644 --- a/py3status/modules/pingdom.py +++ b/py3status/modules/pingdom.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- """ -Dynamically display the latest response time of the configured checks using -the Pingdom API. +Display the latest response time of the configured Pingdom checks. + We also verify the status of the checks and colorize if needed. Pingdom API doc : https://www.pingdom.com/services/api-documentation-rest/ -#NOTE: This module needs the 'requests' python module from pypi - https://pypi.python.org/pypi/requests +Requires: + - requests python module from pypi + https://pypi.python.org/pypi/requests """ import requests diff --git a/py3status/modules/player_control.py b/py3status/modules/player_control.py new file mode 100644 index 0000000..1651327 --- /dev/null +++ b/py3status/modules/player_control.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- +""" +Control music/video players. + +Provides an icon to control simple functions of audio/video players: + - start (left click) + - stop (left click) + - pause (middle click) + +@author Federico Ceratto <federico.ceratto@gmail.com>, rixx +@license BSD +""" +# Any contributor to this module should add his/her name to the @author +# line, comma separated. + +from syslog import syslog, LOG_INFO +from time import time, sleep +import dbus +import os +import subprocess + + +def log(msg): + syslog(LOG_INFO, "player_control: %s" % msg[:100]) + + +class Py3status: + """ + Configuration parameters: + - debug: enable verbose logging (bool) (default: False) + - supported_players: supported players (str) (comma separated list) + - volume_tick: percentage volume change on mouse wheel (int) (positive number or None to disable it) + + """ + + debug = False + pause_icon = u'❚❚' + play_icon = u'▶' + stop_icon = u'◼' + supported_players = 'audacious,vlc' + volume_tick = 1 + + def __init__(self): + self.status = 'stop' + self.icon = self.play_icon + + def on_click(self, i3s_output_list, i3s_config, event): + """ + """ + buttons = (None, 'left', 'middle', 'right', 'up', 'down') + try: + button = buttons[event['button']] + except IndexError: + return + + if button in ('up', 'down'): + if self.volume_tick is None: + return + + self._change_volume(button == 'up') + return + + if self.status == 'play': + if button == 'left': + self._stop() + + elif button == 'middle': + self._pause() + + elif self.status == 'stop': + if button == 'left': + self._play() + + elif self.status == 'pause': + if button in ('left', 'right'): + self._play() + + def _run(self, *args): + if self.debug: + log('running %s' % repr(*args)) + + subprocess.check_output(*args, stderr=subprocess.STDOUT) + + def _play(self): + self.status = 'play' + self.icon = self.stop_icon + player_name = self._detect_running_player() + if player_name == 'audacious': + self._run(['/usr/bin/audacious', '-p']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Play() + + def _stop(self): + self.status = 'stop' + self.icon = self.play_icon + player_name = self._detect_running_player() + if player_name == 'audacious': + self._run(['/usr/bin/audacious', '-s']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Stop() + + def _pause(self): + self.status = 'pause' + self.icon = self.pause_icon + player_name = self._detect_running_player() + if player_name == 'audacious': + self._run(['/usr/bin/audacious', '-u']) + elif player_name == 'vlc': + player = self._get_vlc() + if player: + player.Pause() + + def _change_volume(self, increase): + """Change volume using amixer + """ + sign = '+' if increase else '-' + delta = "%d%%%s" % (self.volume_tick, sign) + self._run(('/usr/bin/amixer', '-q', 'sset', 'Master', delta)) + + def _detect_running_player(self): + """Detect running player process, if any + """ + supported_players = self.supported_players.split(',') + running_players = [] + for pid in os.listdir('/proc'): + if not pid.isdigit(): + continue + + fn = os.path.join('/proc', pid, 'comm') + try: + with open(fn, 'rb') as f: + player_name = f.read().decode().rstrip() + + except: + continue + + if player_name in supported_players: + running_players.append(player_name) + + # Pick which player to use based on the order in self.supported_players + for player_name in supported_players: + if player_name in running_players: + if self.debug: + log('found player: %s' % player_name) + + return player_name + + return None + + def _get_vlc(self): + mpris = 'org.mpris.MediaPlayer2' + mpris_slash = '/' + mpris.replace('.', '/') + bus = dbus.SessionBus() + proxy = bus.get_object(mpris+'.vlc', mpris_slash) + return dbus.Interface(proxy, dbus_interface=mpris+'.Player') + + def player_control(self, i3s_output_list, i3s_config): + return dict( + full_text=self.icon, + cached_until=time(), + ) + + +if __name__ == "__main__": + x = Py3status() + config = { + 'color_good': '#00FF00', + 'color_bad': '#FF0000', + } + while True: + print(x.player_control([], config)) + sleep(1) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index ecb3f57..38f8020 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """ -Pomodoro countdown on i3bar originally written by @Fandekasp (Adrien Lemaire) +Display and control a Pomodoro countdown. + +@author Fandekasp (Adrien Lemaire), rixx, FedericoCeratto """ from subprocess import call @@ -151,17 +153,21 @@ class Py3status: if self.timer < 0: self.alert = True self.run = False + if self.status == 'start': + self.__play_sound(self.sound_pomodoro_end) + + elif self.status == 'break': + self.__play_sound(self.sound_break_end) + self.__i3_nagbar() if self.status == 'start': self.__setup('break') self.status = 'break' - self.__play_sound(self.sound_pomodoro_end) elif self.status == 'break': self.__setup('start') self.status = 'start' - self.__play_sound(self.sound_break_end) def __i3_nagbar(self, level='warning'): """ @@ -212,7 +218,7 @@ class Py3status: try: mixer.music.load(sound_fname) - except Exception as e: + except Exception: return mixer.music.play() diff --git a/py3status/modules/scratchpad_counter.py b/py3status/modules/scratchpad_counter.py index 4bfad23..3619cda 100644 --- a/py3status/modules/scratchpad_counter.py +++ b/py3status/modules/scratchpad_counter.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Module showing amount of windows at the scratchpad. +Display the amount of windows in your i3 scratchpad. @author shadowprince @license Eclipse Public License diff --git a/py3status/modules/spaceapi.py b/py3status/modules/spaceapi.py index 719ee3e..c4eac58 100644 --- a/py3status/modules/spaceapi.py +++ b/py3status/modules/spaceapi.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- """ -This module shows if your favorite hackerspace is open or not +Display if your favorite hackerspace is open or not. -Last modified: 2015-02-01 -Author: @timmszigat -License: WTFPL http://www.wtfpl.net/txt/copying/ +@author timmszigat +@license WTFPL <http://www.wtfpl.net/txt/copying/> """ import codecs diff --git a/py3status/modules/sysdata.py b/py3status/modules/sysdata.py index 0badbe0..34bf97a 100644 --- a/py3status/modules/sysdata.py +++ b/py3status/modules/sysdata.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- """ -Sysdata is a module used to display system information (RAM usage) -in i3bar (Linux systems). +Display system RAM and CPU utilization. NOTE: If you want py3status to show you your CPU temperature, change value of CPUTEMP into True in Py3status class - CPUInfo function and REMEMBER that you must install lm_sensors if you want CPU temp! -Copyright (C) <2013> <Shahin Azad [ishahinism at Gmail]> +@author Shahin Azad <ishahinism at Gmail> """ import subprocess diff --git a/py3status/modules/vnstat.py b/py3status/modules/vnstat.py index ad33b71..5955581 100644 --- a/py3status/modules/vnstat.py +++ b/py3status/modules/vnstat.py @@ -1,7 +1,9 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- """ -Module for displaying vnstat's statistics. -REQUIRE external program called "vnstat" installed and configured to work. +Display vnstat statistics. + +Requires: + - external program called "vnstat" installed and configured to work. @author shadowprince @license Eclipse Public License diff --git a/py3status/modules/weather_yahoo.py b/py3status/modules/weather_yahoo.py index df202d0..0e5d880 100644 --- a/py3status/modules/weather_yahoo.py +++ b/py3status/modules/weather_yahoo.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """ -Display current day + 3 days weather forecast as icons on your i3bar +Display Yahoo! Weather forecast as icons. + Based on Yahoo! Weather. forecast, thanks guys ! http://developer.yahoo.com/weather/ diff --git a/py3status/modules/whoami.py b/py3status/modules/whoami.py index 884cbf5..aea11fb 100644 --- a/py3status/modules/whoami.py +++ b/py3status/modules/whoami.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Simply output the currently logged in user in i3bar. +Display the currently logged in user. Inspired by i3 FAQ: https://faq.i3wm.org/question/1618/add-user-name-to-status-bar/ diff --git a/py3status/modules/window_title.py b/py3status/modules/window_title.py index 3972ff6..a24f61c 100644 --- a/py3status/modules/window_title.py +++ b/py3status/modules/window_title.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Py3status plugin - shows current window title. +Display the current window title. Requires: - i3-py (https://github.com/ziberna/i3-py) diff --git a/py3status/modules/xrandr.py b/py3status/modules/xrandr.py index 4ddd856..ef88925 100644 --- a/py3status/modules/xrandr.py +++ b/py3status/modules/xrandr.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """ +Control your screen(s) layout easily. + This modules allows you to handle your screens outputs directly from your bar! - Detect and propose every possible screen combinations - Switch between combinations using click events and mouse scroll |
