diff options
| -rw-r--r-- | README.rst | 2 | ||||
| -rw-r--r-- | doc/example_module.py | 4 | ||||
| -rwxr-xr-x | py3status/__init__.py | 23 | ||||
| -rw-r--r-- | py3status/modules/README.md | 558 | ||||
| -rw-r--r--[-rwxr-xr-x] | py3status/modules/aws_bill.py | 10 | ||||
| -rw-r--r-- | py3status/modules/dpms.py | 30 | ||||
| -rw-r--r-- | py3status/modules/external_script.py | 68 | ||||
| -rw-r--r-- | py3status/modules/imap.py | 16 | ||||
| -rw-r--r-- | py3status/modules/keyboard_layout.py | 3 | ||||
| -rw-r--r-- | py3status/modules/netdata.py | 4 | ||||
| -rw-r--r--[-rwxr-xr-x] | py3status/modules/nvidia_temp.py | 0 | ||||
| -rw-r--r-- | py3status/modules/pomodoro.py | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | py3status/modules/rate_counter.py | 0 | ||||
| -rw-r--r-- | py3status/modules/static_string.py | 40 | ||||
| -rw-r--r-- | py3status/modules/sysdata.py | 147 | ||||
| -rw-r--r-- | py3status/modules/taskwarrior.py | 57 | ||||
| -rw-r--r-- | py3status/modules/volume_status.py | 147 |
17 files changed, 1022 insertions, 93 deletions
@@ -3,7 +3,7 @@ py3status ********* |version| -.. |version| image:: https://pypip.in/version/py3status/badge.png +.. |version| image:: https://img.shields.io/pypi/v/py3status.svg **py3status** is an extensible i3status wrapper written in python. diff --git a/doc/example_module.py b/doc/example_module.py index d132eed..6a952a1 100644 --- a/doc/example_module.py +++ b/doc/example_module.py @@ -51,7 +51,7 @@ from time import time class Py3status: """ - The Py3status class name is mendatory. + The Py3status class name is mandatory. Below you list all the available configuration parameters and their default value for your module which can be overwritten by users @@ -121,5 +121,5 @@ if __name__ == "__main__": 'color_good': '#00FF00' } while True: - print(x.empty([], config)) + print(x.example_method([], config)) sleep(1) diff --git a/py3status/__init__.py b/py3status/__init__.py index bbf2560..d3095cb 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -148,11 +148,18 @@ class I3status(Thread): # self.config = self.i3status_config_reader(i3status_config_path) - def valid_config_param(self, param_name): + def valid_config_param(self, param_name, cleanup=False): """ Check if a given section name is a valid parameter for i3status. """ - valid_config_params = self.i3status_module_names + ['general', 'order'] + if cleanup: + valid_config_params = [ _ for _ in self.i3status_module_names if _ not in [ + 'cpu_usage', 'ddate', 'load', 'time' + ]] + else: + valid_config_params = self.i3status_module_names + [ + 'general', 'order' + ] return param_name.split(' ')[0] in valid_config_params @staticmethod @@ -318,6 +325,14 @@ class I3status(Thread): ) ) + # cleanup unconfigured i3status modules that have no default + for module_name in deepcopy(config['order']): + if (self.valid_config_param(module_name, cleanup=True) and + not config.get(module_name)): + config.pop(module_name) + config['i3s_modules'].remove(module_name) + config['order'].remove(module_name) + return config def set_responses(self, json_list): @@ -473,7 +488,7 @@ class I3status(Thread): Given a temporary file descriptor, write a valid i3status config file based on the parsed one from 'i3status_config_path'. """ - for section_name, conf in self.config.items(): + for section_name, conf in sorted(self.config.items()): if section_name in ['i3s_modules', 'py3_modules']: continue elif section_name == 'order': @@ -484,7 +499,7 @@ class I3status(Thread): tmpfile ) self.write_in_tmpfile('\n', tmpfile) - elif self.valid_config_param(section_name): + elif self.valid_config_param(section_name) and conf: self.write_in_tmpfile('%s {\n' % section_name, tmpfile) for key, value in conf.items(): self.write_in_tmpfile( diff --git a/py3status/modules/README.md b/py3status/modules/README.md new file mode 100644 index 0000000..1bc64e0 --- /dev/null +++ b/py3status/modules/README.md @@ -0,0 +1,558 @@ +``` +Available modules: + aws_bill Display the current AWS bill. + + ##### WARNING ##### + This module generate some costs on the AWS bill. + Take care about the cache_timeout to limit these fees ! + ##### WARNING ##### + + Configuration parameters: + - aws_access_key_id: Your AWS access key + - aws_account_id: the root ID of the AWS account. + Can be found here: https://console.aws.amazon.com/billing/home#/account + - aws_secret_access_key: Your AWS secret key + - billing_file: csv file location + - cache_timeout: how often we refresh this module in seconds + - s3_bucket_name: the bucket where billing files are sent by AWS. + Follow this article to activate this feature: + http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/detailed-billing-reports.html + + Format of status string placeholders: + {bill_amount} - AWS bill amount + + Requires: + - boto + + @author nawadanp + --- + battery_level Display the battery level. + + Configuration parameters: + - color_* : None means - get it from i3status config + - format : text with "text" mode. percentage with % replaces {} + - hide_when_full : hide any information when battery is fully charged + - mode : for primitive-one-char bar, or "text" for text percentage ouput + + Requires: + - the 'acpi' command line + + @author shadowprince, AdamBSteele + @license Eclipse Public License + --- + bitcoin_price Display bitcoin prices using bitcoincharts.com. + + Configuration parameters: + - cache_timeout: Should be at least 15 min according to bitcoincharts. + - color_index : Index of the market responsible for coloration, + meaning that the output is going to be green if the + price went up and red if it went down. + default: -1 means no coloration, + except when only one market is selected + - field : Field that is displayed per market, + see http://bitcoincharts.com/about/markets-api/ + - hide_on_error: Display empty response if True, else an error message + - markets : Comma-separated list of markets. Supported markets can + be found at http://bitcoincharts.com/markets/list/ + - symbols : Try to match currency abbreviations to symbols, + e.g. USD -> $, EUR -> € and so on + + @author Andre Doser <doser.andre AT gmail.com> + --- + bluetooth Display bluetooth status. + + Confiuration parameters: + - format : format when there is a connected device + - format_no_conn : format when there is no connected device + - format_no_conn_prefix : prefix when there is no connected device + - format_prefix : prefix when there is a connected device + + Format of status string placeholders + {name} : device name + {mac} : device MAC address + + Requires: + - hcitool + + @author jmdana <https://github.com/jmdana> + @license GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt> + --- + clementine Display the current "artist - title" playing in Clementine. + + @author Francois LASSERRE <choiz@me.com> + @license GNU GPL http://www.gnu.org/licenses/gpl.html + --- + dpms 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. + + Configuration parameters: + - format_off: string to display when DPMS is disabled + - format_on: string to display when DPMS is enabled + + @author Andre Doser <dosera AT tf.uni-freiburg.de> + --- + external_script Display output of given script. + + Display output of any executable script set by 'script_path'. + Pay attention. The output must be one liner, or will break your i3status ! + The script should not have any parameters, but it could work. + + Configuration parameters: + - cache_timeout : how often we refresh this module in seconds + - color : color of printed text + - format : see placeholders below + - script_path : script you want to show output of (compulsory) + + Format of status string placeholders: + {output} - output of script given by "script_path" + + i3status.conf example: + + external_script { + color = "#00FF00" + format = "my name is {output}" + script_path = "/usr/bin/whoami" + + @author frimdo ztracenastopa@centrum.cz + --- + glpi Display the total number of open tickets from GLPI. + + Configuration parameters: + - critical : set bad color above this threshold + - db : database to use + - host : database host to connect to + - password : login password + - user : login user + - warning : set degraded color above this threshold + + 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. + --- + imap Display the unread messages count from your IMAP account. + + Configuration parameters: + - cache_timeout : how often to run this check + - criterion : status of emails to check for + - format : format to display + - hide_if_zero : don't show on bar if 0 + - imap_server : IMAP server to connect to + - mailbox : name of the mailbox to check + - new_mail_color : what color to output on new mail + - password : login password + - port : IMAP server port + - user : login user + + Format of status string placeholders: + {unseen} - number of unread emails + + @author obb + --- + keyboard_layout Display the current keyboard layout. + + Configuration parameters: + - cache_timeout: check for keyboard layout change every seconds + + Requires: + - xkblayout-state + or + - setxkbmap + + @author shadowprince + @license Eclipse Public License + --- + mpd_status Display information from mpd. + + Configuration parameters: + - format : indicator text format + - hide_when_paused / hide_when_stopped : hide any indicator, if + - host : mpd host + - max_width : if text length will be greater - it'll shrink it + - password : mpd password + - port : mpd port + + 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} + + Requires: + - python-mpd2 (NOT python2-mpd2) + # pip install python-mpd2 + + @author shadowprince + @license Eclipse Public License + --- + net_rate Display the current network transfer rate. + + Confiuration parameters: + - all_interfaces : ignore self.interfaces, but not self.interfaces_blacklist + - devfile : location of dev file under /proc + - format_no_connection : when there is no data transmitted from the start of the plugin + - hide_if_zero : hide indicator if rate == 0 + - interfaces : comma separated list of interfaces to track + - interfaces_blacklist : comma separated list of interfaces to ignore + - precision : amount of numbers after dot + + Format of status string placeholders: + {down} - download rate + {interface} - name of interface + {total} - total rate + {up} - upload rate + + @author shadowprince + @license Eclipse Public License + --- + netdata Display network speed and bandwidth usage. + + Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (2s default) + - low_* / med_* : coloration thresholds + - nic : the network interface to monitor (defaults to eth0) + + @author Shahin Azad <ishahinism at Gmail> + --- + ns_checker 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. + + Configuration parameters: + - domain : domain name to check + - lifetime : resolver lifetime + - nameservers : comma separated list of reference DNS nameservers + - resolvers : comma separated list of DNS resolvers to use + + @author nawadanp + --- + nvidia_temp Display NVIDIA GPU temperature. + + Configuration parameters: + - cache_timeout: how often we refresh this module in seconds + - color_bad: the color used if the temperature can't be read. + - color_good: the color used if everything is OK. + - format_prefix: a prefix for the output. + - format_units: the temperature units. Will appear at the end. + - separator: the separator char between temperatures (only if more than one GPU) + + Requires: + - nvidia-smi + + @author jmdana <https://github.com/jmdana> + @license BSD + --- + online_status Display if a connection to the internet is established. + + Configuration parameters: + - cache_timeout : how often to run the check + - format_offline : what to display when offline + - format_online : what to display when online + - timeout : how long before deciding we're offline + - url : connect to this url to check the connection status + + @author obb + --- + pingdom 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/features/api/documentation/ + + Configuration parameters: + - app_key : create an APP KEY on pingdom first + - cache_timeout : how often to refresh the check from pingdom + - checks : comma separated pindgom check names to display + - login : pingdom login + - max_latency : maximal latency before coloring the output + - password : pingdom password + - request_timeout : pindgom API request timeout + + Requires: + - requests python module from pypi + https://pypi.python.org/pypi/requests + --- + player_control Control music/video players. + + Provides an icon to control simple functions of audio/video players: + - start (left click) + - stop (left click) + - pause (middle click) + + 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) + + @author Federico Ceratto <federico.ceratto@gmail.com>, rixx + @license BSD + --- + pomodoro Display and control a Pomodoro countdown. + + Configuration parameters: + - display_bar: display time in bars when True, otherwise in seconds + - max_breaks: maximum number of breaks + - num_progress_bars: number of progress bars + - sound_break_end: break end sound (file path) + - sound_pomodoro_end: pomodoro end sound (file path) + - sound_pomodoro_start: pomodoro start sound (file path) + - timer_break: normal break time (seconds) (requires pygame) + - timer_long_break: long break time (seconds) (requires pygame) + - timer_pomodoro: pomodoro time (seconds) (requires pygame) + + @author Fandekasp (Adrien Lemaire), rixx, FedericoCeratto + --- + rate_counter Display days/hours/minutes spent and calculate the price of your service. + + Configuration parameters: + - config_file: file path to store the time already spent + and restore it the next session + - hour_price : your price per hour + - tax : tax value (1.02 = 2%) + + @author Amaury Brisou <py3status AT puzzledge.org> + --- + scratchpad_counter Display the amount of windows in your i3 scratchpad. + + @author shadowprince + @license Eclipse Public License + --- + screenshot Take a screenshot and optionally upload it to your online server. + + Display a 'SHOT' button in your i3bar allowing you to take a screenshot and + directly send (if wanted) the file to your online server. + When the screenshot has been taken, 'SHOT' is replaced by the file_name. + + This modules uses the 'gnome-screenshot' program to take the screenshot. + + Configuration parameters: + - file_length: generated file_name length + - push: True/False if yo want to push your screenshot to your server + - save_path: Directory where to store your screenshots. + - upload_path: the remote path where to push the screenshot + - upload_server: your server address + - upload_user: your ssh user + + @author Amaury Brisou <py3status AT puzzledge.org> + --- + spaceapi Display if your favorite hackerspace is open or not. + + Configuration Parameters: + - cache_timeout: Set timeout between calls in seconds + - closed_color: color if space is closed + - closed_text: text if space is closed, strftime parameters will be translated + - open_color: color if space is open + - open_text: text if space is open, strftime parmeters will be translated + - url: URL to SpaceAPI json file of your space + + @author timmszigat + @license WTFPL <http://www.wtfpl.net/txt/copying/> + --- + spotify Display information about the current song playing on Spotify. + + Configuration parameters: + - cache_timeout : how often to update the bar + - format : see placeholders below + + Format of status string placeholders: + {album} - album name + {artist} - artiste name (first one) + {time} - time duration of the song + {title} - name of the song + + i3status.conf example: + + spotify { + format = "{title} by {artist} -> {time}" + } + + @author Pierre Guilbert <pierre@1000mercis.com> + --- + static_string Display static text. + + Configuration parameters: + - color : color of printed text + - format : text that should be printed + - separator : whether the separator is shown or not (true or false) + + @author frimdo ztracenastopa@centrum.cz + --- + sysdata Display system RAM and CPU utilization. + + Configuration parameters: + - format: output format string + - high_threshold: percent to consider CPU or RAM usage as 'high load' + - med_threshold: percent to consider CPU or RAM usage as 'medium load' + + Format of status string placeholders: + {cpu_temp} - cpu temperature + {cpu_usage} - cpu usage percentage + {mem_total} - total memory + {mem_used} - used memory + {mem_used_percent} - used memory percentage + + NOTE: If using the {cpu_temp} option, the 'sensors' command should + be available, provided by the 'lm-sensors' or 'lm_sensors' package. + + @author Shahin Azad <ishahinism at Gmail>, shrimpza + --- + taskwarrior Display currently active (started) taskwarrior tasks. + + Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (5s default) + + Requires + - task + + @author James Smith http://jazmit.github.io/ + @license BSD + --- + vnstat Display vnstat statistics. + + Coloring rules. + + If value is bigger that dict key, status string will turn to color, specified in the value. + Example: + coloring = { + 800: "#dddd00", + 900: "#dd0000", + } + (0 - 800: white, 800-900: yellow, >900 - red) + + Format of status string placeholders: + {down} - download + {total} - total + {up} - upload + + Requires: + - external program called "vnstat" installed and configured to work. + + @author shadowprince + @license Eclipse Public License + --- + volume_status Display current sound volume using amixer. + + Expands on the standard i3status volume module by adding color + and percentage threshold settings. + + Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (10s default) + - channel : "Master" by default, alsamixer channel to track + - device : "default" by default, alsamixer device to use + - format : format the output, available variables: {percentage} + - format_muted : format the output when the volume is muted + - threshold_bad : 20 by default + - threshold_degraded : 50 by default + + Requires: + alsa-utils (tested with alsa-utils 1.0.29-1) + + NOTE: + If you want to refresh the module quicker than the i3status interval, + send a USR1 signal to py3status in the keybinding. + Example: killall -s USR1 py3status + + @author <Jan T> <jans.tuomi@gmail.com> + @license BSD + --- + weather_yahoo Display Yahoo! Weather forecast as icons. + + Based on Yahoo! Weather. forecast, thanks guys ! + http://developer.yahoo.com/weather/ + + Find your city code using: + http://answers.yahoo.com/question/index?qid=20091216132708AAf7o0g + + Configuration parameters: + - cache_timeout : how often to check for new forecasts + - city_code : city code to use + - forecast_days : how many forecast days you want shown + - request_timeout : check timeout + + The city_code in this example is for Paris, France => FRXX0076 + --- + whatismyip Display your public/external IP address and toggle to online status on click. + + Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (default 30s) + - format: the only placeholder available is {ip} (default '{ip}') + - format_offline : what to display when offline + - format_online : what to display when online + - hide_when_offline: hide the module output when offline (default False) + - mode: default mode to display is 'ip' or 'status' (click to toggle) + - negative_cache_timeout: how often to check again when offline + - timeout : how long before deciding we're offline + + @author ultrabug + --- + whoami Display the currently logged in user. + + Inspired by i3 FAQ: + https://faq.i3wm.org/question/1618/add-user-name-to-status-bar/ + --- + window_title Display the 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 + --- + xrandr 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 + - Activate the screen or screen combination on a single click + - It will detect any newly connected or removed screen automatically + + For convenience, this module also proposes some added features: + - Dynamic parameters for POSITION and WORKSPACES assignment (see below) + - Automatic fallback to a given screen or screen combination when no more + screen is available (handy for laptops) + - Automatically apply this screen combination on start: no need for xorg! + - Automatically move workspaces to screens when they are available + + Configuration parameters: + - cache_timeout: how often to (re)detect the outputs + - fallback: when the current output layout is not available anymore, + fallback to this layout if available. This is very handy if you + have a laptop and switched to an external screen for presentation + and want to automatically fallback to your laptop screen when you + disconnect the external screen. + - force_on_start: switch to the given combination mode if available + when the module starts (saves you from having to configure xorg) + - format_clone: string used to display a 'clone' combination + - format_extend: string used to display a 'extend' combination + + Dynamic configuration parameters: + - <OUTPUT>_pos: apply the given position to the OUTPUT + Example: DP1_pos = "-2560x0" + Example: DP1_pos = "left-of LVDS1" + Example: DP1_pos = "right-of eDP1" + + - <OUTPUT>_workspaces: comma separated list of workspaces to move to + the given OUTPUT when it is activated + Example: DP1_workspaces = "1,2,3" + + Example config: + xrandr { + force_on_start = "eDP1+DP1" + DP1_pos = "left-of eDP1" + VGA_workspaces = "7" + } + + @author ultrabug + --- +``` diff --git a/py3status/modules/aws_bill.py b/py3status/modules/aws_bill.py index 98643f6..5452718 100755..100644 --- a/py3status/modules/aws_bill.py +++ b/py3status/modules/aws_bill.py @@ -18,6 +18,9 @@ Configuration parameters: Follow this article to activate this feature: http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/detailed-billing-reports.html +Format of status string placeholders: + {bill_amount} - AWS bill amount + Requires: - boto @@ -41,6 +44,7 @@ class Py3status: aws_secret_access_key = '' billing_file = '/tmp/.aws_billing.csv' cache_timeout = 3600 + format = '{bill_amount}$' s3_bucket_name = '' def _get_bill_amount(self): @@ -90,8 +94,8 @@ class Py3status: def aws_bill(self, i3s_output_list, i3s_config): response = { 'cached_until': time() + self.cache_timeout, - 'full_text': '', - 'color': i3s_config['color_bad'] + 'color': i3s_config['color_bad'], + 'full_text': '' } bill_amount = self._get_bill_amount() @@ -105,7 +109,7 @@ class Py3status: elif bill_amount == 'conn_error': response['full_text'] = 'Check your internet access' elif bill_amount is not False: - response['full_text'] = str(bill_amount) + '$' + response['full_text'] = self.format.format(bill_amount=bill_amount) response['color'] = i3s_config['color_good'] else: response['full_text'] = 'Global error - WTF exception' diff --git a/py3status/modules/dpms.py b/py3status/modules/dpms.py index ecbc3a7..6a5d881 100644 --- a/py3status/modules/dpms.py +++ b/py3status/modules/dpms.py @@ -6,6 +6,10 @@ This module allows activation and deactivation of DPMS (Display Power Management Signaling) by clicking on 'DPMS' in the status bar. +Configuration parameters: + - format_off: string to display when DPMS is disabled + - format_on: string to display when DPMS is enabled + @author Andre Doser <dosera AT tf.uni-freiburg.de> """ @@ -15,6 +19,10 @@ from os import system class Py3status: """ """ + # available configuration parameters + format_off = "DPMS" + format_on = "DPMS" + def dpms(self, i3s_output_list, i3s_config): """ Display a colorful state of DPMS. @@ -23,13 +31,10 @@ class Py3status: self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0 response = { - 'full_text': 'DPMS' + 'full_text': self.format_on if self.run else self.format_off, + 'color': i3s_config['color_good'] if self.run else i3s_config['color_bad'] } - if self.run: - response['color'] = i3s_config['color_good'] - else: - response['color'] = i3s_config['color_bad'] return response def on_click(self, i3s_output_list, i3s_config, event): @@ -43,3 +48,18 @@ class Py3status: else: self.run = True system("xset +dpms;xset s on") + +if __name__ == "__main__": + """ + Test this module by calling it directly. + """ + from time import sleep + x = Py3status() + config = { + 'color_bad': '#FF0000', + 'color_good': '#00FF00', + } + + while True: + print(x.dpms([], config)) + sleep(1) diff --git a/py3status/modules/external_script.py b/py3status/modules/external_script.py new file mode 100644 index 0000000..4b3f2e8 --- /dev/null +++ b/py3status/modules/external_script.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" +Display output of given script. + +Display output of any executable script set by 'script_path'. +Pay attention. The output must be one liner, or will break your i3status ! +The script should not have any parameters, but it could work. + +Configuration parameters: + - cache_timeout : how often we refresh this module in seconds + - color : color of printed text + - format : see placeholders below + - script_path : script you want to show output of (compulsory) + +Format of status string placeholders: + {output} - output of script given by "script_path" + +i3status.conf example: + +external_script { + color = "#00FF00" + format = "my name is {output}" + script_path = "/usr/bin/whoami" + +@author frimdo ztracenastopa@centrum.cz +""" + +import subprocess +from time import time + + +class Py3status: + """ + """ + # available configuration parameters + cache_timeout = 15 + color = None + format = '{output}' + script_path = None + + def external_script(self, i3s_output_list, i3s_config): + if self.script_path: + return_value = subprocess.check_output(self.script_path, + shell=True, + universal_newlines=True) + response = { + 'cached_until': time() + self.cache_timeout, + 'color': self.color, + 'full_text': self.format.format(output=return_value.rstrip()) + } + else: + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': '' + } + return response + + +if __name__ == "__main__": + from time import sleep + x = Py3status() + config = { + 'color_good': '#00FF00', + 'color_bad': '#FF0000', + } + while True: + print(x.external_script([], config)) + sleep(1) diff --git a/py3status/modules/imap.py b/py3status/modules/imap.py index 473c55d..ec1d90e 100644 --- a/py3status/modules/imap.py +++ b/py3status/modules/imap.py @@ -5,15 +5,18 @@ Display the unread messages count from your IMAP account. Configuration parameters: - cache_timeout : how often to run this check - criterion : status of emails to check for + - format : format to display - hide_if_zero : don't show on bar if 0 - imap_server : IMAP server to connect to - mailbox : name of the mailbox to check - - name : format to display - new_mail_color : what color to output on new mail - password : login password - port : IMAP server port - user : login user +Format of status string placeholders: + {unseen} - number of unread emails + @author obb """ @@ -30,7 +33,7 @@ class Py3status: hide_if_zero = False imap_server = '<IMAP_SERVER>' mailbox = 'INBOX' - name = 'Mail: {unseen}' + format = 'Mail: {unseen}' new_mail_color = '' password = '<PASSWORD>' port = '993' @@ -39,9 +42,7 @@ class Py3status: def check_mail(self, i3s_output_list, i3s_config): mail_count = self._get_mail_count() - response = { - 'cached_until': time() + self.cache_timeout - } + response = {'cached_until': time() + self.cache_timeout} if not self.new_mail_color: self.new_mail_color = i3s_config['color_good'] @@ -50,12 +51,12 @@ class Py3status: response['full_text'] = mail_count elif mail_count != 0: response['color'] = self.new_mail_color - response['full_text'] = self.name.format(unseen=mail_count) + response['full_text'] = self.format.format(unseen=mail_count) else: if self.hide_if_zero: response['full_text'] = '' else: - response['full_text'] = self.name.format(unseen=mail_count) + response['full_text'] = self.format.format(unseen=mail_count) return response @@ -78,6 +79,7 @@ class Py3status: except: return 'N/A' + if __name__ == "__main__": """ Test this module by calling it directly. diff --git a/py3status/modules/keyboard_layout.py b/py3status/modules/keyboard_layout.py index f4ad8a9..ec65b91 100644 --- a/py3status/modules/keyboard_layout.py +++ b/py3status/modules/keyboard_layout.py @@ -2,6 +2,9 @@ """ Display the current keyboard layout. +Configuration parameters: + - cache_timeout: check for keyboard layout change every seconds + Requires: - xkblayout-state or diff --git a/py3status/modules/netdata.py b/py3status/modules/netdata.py index 9e81710..c537dbb 100644 --- a/py3status/modules/netdata.py +++ b/py3status/modules/netdata.py @@ -3,7 +3,7 @@ Display network speed and bandwidth usage. Configuration parameters: - - cache_timeout : 0 by default, you usually want continuous monitoring + - cache_timeout : how often we refresh this module in seconds (2s default) - low_* / med_* : coloration thresholds - nic : the network interface to monitor (defaults to eth0) @@ -52,7 +52,7 @@ class Py3status: low_traffic = 400 med_speed = 60 med_traffic = 700 - nic = 'wlp2s0' + nic = 'eth0' def __init__(self): self.old_transmitted = 0 diff --git a/py3status/modules/nvidia_temp.py b/py3status/modules/nvidia_temp.py index ba17d27..ba17d27 100755..100644 --- a/py3status/modules/nvidia_temp.py +++ b/py3status/modules/nvidia_temp.py diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 25149a7..02b0be3 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -106,14 +106,14 @@ class Py3status: bar += PROGRESS_BAR_ITEMS[selector] bar_val -= 1 - bar = bar.ljust(self.num_progress_bars).encode('utf_8') + bar = bar.ljust(self.num_progress_bars) else: bar = self.timer if self.run: - text = '{} [{}]'.format(self.prefix, bar) + text = u'{} [{}]'.format(self.prefix, bar) else: - text = '{} ({})'.format(self.prefix, bar) + text = u'{} ({})'.format(self.prefix, bar) return dict(full_text=text) diff --git a/py3status/modules/rate_counter.py b/py3status/modules/rate_counter.py index 6852c18..6852c18 100755..100644 --- a/py3status/modules/rate_counter.py +++ b/py3status/modules/rate_counter.py diff --git a/py3status/modules/static_string.py b/py3status/modules/static_string.py new file mode 100644 index 0000000..bb12ec2 --- /dev/null +++ b/py3status/modules/static_string.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +""" +Display static text. + +Configuration parameters: + - color : color of printed text + - format : text that should be printed + - separator : whether the separator is shown or not (true or false) + +@author frimdo ztracenastopa@centrum.cz +""" + +from time import time + + +class Py3status: + """ + """ + # available configuration parameters + color = None + format = '' + separator = True + + def static_string(self, i3s_output_list, i3s_config): + response = { + 'cached_until': time() + 60, + 'color': self.color, + 'full_text': self.format, + 'separator': self.separator + } + return response + + +if __name__ == "__main__": + x = Py3status() + config = { + 'color_good': '#00FF00', + 'color_bad': '#FF0000', + } + print(x.static_string([], config)) diff --git a/py3status/modules/sysdata.py b/py3status/modules/sysdata.py index 9343722..7437c01 100644 --- a/py3status/modules/sysdata.py +++ b/py3status/modules/sysdata.py @@ -2,22 +2,36 @@ """ 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! +Configuration parameters: + - format: output format string + - high_threshold: percent to consider CPU or RAM usage as 'high load' + - med_threshold: percent to consider CPU or RAM usage as 'medium load' -@author Shahin Azad <ishahinism at Gmail> +Format of status string placeholders: + {cpu_temp} - cpu temperature + {cpu_usage} - cpu usage percentage + {mem_total} - total memory + {mem_used} - used memory + {mem_used_percent} - used memory percentage + +NOTE: If using the {cpu_temp} option, the 'sensors' command should +be available, provided by the 'lm-sensors' or 'lm_sensors' package. + +@author Shahin Azad <ishahinism at Gmail>, shrimpza """ +import re import subprocess from time import time - class GetData: - """Get system status """ + Get system status + """ + def execCMD(self, cmd, arg): - """Take a system command and its argument, then return the result. + """ + Take a system command and its argument, then return the result. Arguments: - `cmd`: system command. @@ -28,18 +42,19 @@ class GetData: return result def cpu(self): - """Get the cpu usage data from /proc/stat : - cpu 2255 34 2290 22625563 6290 127 456 0 0 - - user: normal processes executing in user mode - - nice: niced processes executing in user mode - - system: processes executing in kernel mode - - idle: twiddling thumbs - - iowait: waiting for I/O to complete - - irq: servicing interrupts - - softirq: servicing softirqs - - steal: involuntary wait - - guest: running a normal guest - - guest_nice: running a niced guest + """ + Get the cpu usage data from /proc/stat : + cpu 2255 34 2290 22625563 6290 127 456 0 0 + - user: normal processes executing in user mode + - nice: niced processes executing in user mode + - system: processes executing in kernel mode + - idle: twiddling thumbs + - iowait: waiting for I/O to complete + - irq: servicing interrupts + - softirq: servicing softirqs + - steal: involuntary wait + - guest: running a normal guest + - guest_nice: running a niced guest These numbers identify the amount of time the CPU has spent performing different kinds of work. Time units are in USER_HZ (typically hundredths of a second) @@ -54,91 +69,90 @@ class GetData: return total_cpu_time, cpu_idle_time def memory(self): - """Execute 'free -m' command, grab the memory capacity and used size + """ + Execute 'free -m' command, grab the memory capacity and used size then return; Memory size 'total_mem', Used_mem, and percentage of used memory. - """ # Run 'free -m' command and make a list from output. mem_data = self.execCMD('free', '-m').split() mem_index = mem_data.index('Mem:') total_mem = int(mem_data[mem_index + 1]) / 1024. used_mem = int(mem_data[mem_index + 2]) / 1024. + # Caculate percentage used_mem_percent = int(used_mem / (total_mem / 100)) # Results are in kilobyte. return total_mem, used_mem, used_mem_percent + def cpuTemp(self): + """ + Tries to determine CPU temperature using the 'sensors' command. + Searches for the CPU temperature by looking for a value prefixed + by either "CPU Temp" or "Core 0" - does not look for or average + out temperatures of all codes if more than one. + """ + + sensors = subprocess.check_output('sensors', shell=True); + m = re.search("(Core 0|CPU Temp).+\+(.+).+\(.+", sensors) + if m: + cpu_temp = m.groups()[1] + else: + cpu_temp = 'Unknown' + + return cpu_temp class Py3status: """ """ # available configuration parameters cache_timeout = 10 - med_threshold = 40 + format = "CPU: {cpu_usage}%, Mem: {mem_used}/{mem_total} GB ({mem_used_percent}%)" high_threshold = 75 + med_threshold = 40 def __init__(self): self.data = GetData() self.cpu_total = 0 self.cpu_idle = 0 - def cpuInfo(self, i3s_output_list, i3s_config): - """Calculate the CPU status and return it. - """ - response = {'full_text': ''} + def sysData(self, i3s_output_list, i3s_config): + # get CPU usage info cpu_total, cpu_idle = self.data.cpu() - used_cpu_percent = 1 - ( - float(cpu_idle-self.cpu_idle)/float(cpu_total-self.cpu_total) + cpu_usage = 1 - ( + float(cpu_idle-self.cpu_idle) / float(cpu_total-self.cpu_total) ) self.cpu_total = cpu_total self.cpu_idle = cpu_idle - if used_cpu_percent <= self.med_threshold/100.0: - response['color'] = i3s_config['color_good'] - elif used_cpu_percent <= self.high_threshold/100.0: - response['color'] = i3s_config['color_degraded'] - else: - response['color'] = i3s_config['color_bad'] - #cpu temp - CPUTEMP = False - if CPUTEMP: - cputemp = subprocess.check_output( - 'sensors | grep "CPU Temp" | cut -f2 -d"+" | cut -f1 -d" "', - shell=True - ) - cputemp = cputemp[:-1].decode('utf-8') - response['full_text'] = "CPU: %.2f%% %s" % ( - used_cpu_percent*100, - cputemp - ) + # if specified as a formatting option, also get the CPU temperature + if '{cpu_temp}' in self.format: + cpu_temp = self.data.cpuTemp() else: - response['full_text'] = "CPU: %.2f%%" % (used_cpu_percent*100) - response['cached_until'] = time() + self.cache_timeout + cpu_temp = '' - return response + # get RAM usage info + mem_total, mem_used, mem_used_percent = self.data.memory() - def ramInfo(self, i3s_output_list, i3s_config): - """Calculate the memory (RAM) status and return it. - """ - response = {'full_text': ''} - total_mem, used_mem, used_mem_percent = self.data.memory() + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': self.format.format( + cpu_usage = '%.2f' % (cpu_usage * 100), + cpu_temp = cpu_temp, + mem_used = '%.2f' % mem_used, + mem_total = '%.2f' % mem_total, + mem_used_percent = '%.2f' % mem_used_percent, + ) + } - if used_mem_percent <= self.med_threshold: + if max(cpu_usage, mem_used_percent/100) <= self.med_threshold / 100.0: response['color'] = i3s_config['color_good'] - elif used_mem_percent <= self.high_threshold: + elif max(cpu_usage, mem_used_percent/100) <= self.high_threshold / 100.0: response['color'] = i3s_config['color_degraded'] else: response['color'] = i3s_config['color_bad'] - response['full_text'] = "RAM: %.2f/%.2f GB (%d%%)" % ( - used_mem, - total_mem, - used_mem_percent - ) - response['cached_until'] = time() + self.cache_timeout - return response if __name__ == "__main__": @@ -148,10 +162,11 @@ 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.cpuInfo([], config)) - print(x.ramInfo([], config)) + print(x.sysData([], config)) sleep(1) diff --git a/py3status/modules/taskwarrior.py b/py3status/modules/taskwarrior.py new file mode 100644 index 0000000..65407e5 --- /dev/null +++ b/py3status/modules/taskwarrior.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +""" +Display currently active (started) taskwarrior tasks. + +Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (5s default) + +Requires + - task + +@author James Smith http://jazmit.github.io/ +@license BSD +""" + +# import your useful libs here +from time import time +from subprocess import check_output +import json +import shlex + + +class Py3status: + """ + """ + # available configuration parameters + cache_timeout = 5 + + def taskWarrior(self, i3s_output_list, i3s_config): + command = 'task start.before:tomorrow status:pending export' + taskwarrior_output = check_output(shlex.split(command)) + tasks_json = json.loads('[' + taskwarrior_output.decode('utf-8') + ']') + + def describeTask(taskObj): + return str(taskObj['id']) + ' ' + taskObj['description'] + + result = ', '.join(map(describeTask, tasks_json)) + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': result + } + return response + + +if __name__ == "__main__": + """ + Test this module by calling it directly. + """ + from time import sleep + x = Py3status() + config = { + 'color_bad': '#FF0000', + 'color_degraded': '#FFFF00', + 'color_good': '#00FF00' + } + while True: + print(x.taskWarrior([], config)) + sleep(1) diff --git a/py3status/modules/volume_status.py b/py3status/modules/volume_status.py new file mode 100644 index 0000000..cddc763 --- /dev/null +++ b/py3status/modules/volume_status.py @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +""" +Display current sound volume using amixer. + +Expands on the standard i3status volume module by adding color +and percentage threshold settings. + +Configuration parameters: + - cache_timeout : how often we refresh this module in seconds (10s default) + - channel : "Master" by default, alsamixer channel to track + - device : "default" by default, alsamixer device to use + - format : format the output, available variables: {percentage} + - format_muted : format the output when the volume is muted + - threshold_bad : 20 by default + - threshold_degraded : 50 by default + +Requires: + alsa-utils (tested with alsa-utils 1.0.29-1) + +NOTE: + If you want to refresh the module quicker than the i3status interval, + send a USR1 signal to py3status in the keybinding. + Example: killall -s USR1 py3status + +@author <Jan T> <jans.tuomi@gmail.com> +@license BSD +""" + +import re +import shlex + +from subprocess import check_output +from time import time + + +class Py3status: + """ + """ + # available configuration parameters + cache_timeout = 10 + channel = 'Master' + device = 'default' + format = u'♪: {percentage}%' + format_muted = u'♪: muted' + threshold_bad = 20 + threshold_degraded = 50 + + # constructor + def __init__(self): + self.text = '' + + # compares current volume to the thresholds, returns a color code + def _perc_to_color(self, i3s_config, string): + try: + value = int(string) + except ValueError: + return i3s_config['color_bad'] + + if value < self.threshold_bad: + return i3s_config['color_bad'] + elif value < self.threshold_degraded: + return i3s_config['color_degraded'] + else: + return i3s_config['color_good'] + + # return the format string formatted with available variables + def _format_output(self, format, percentage): + text = format.format(percentage=percentage) + return text + + # return the current channel volume value as a string + def _get_percentage(self, output): + + # attempt to find a percentage value in square brackets + p = re.compile(r'(?<=\[)\d{1,3}(?=%\])') + text = p.search(output).group() + + # check if the parsed value is sane by checking if it's an integer + try: + int(text) + return text + + # if not, show an error message in output + except ValueError: + return "error: can't parse amixer output." + + # returns True if the channel is muted + def _get_muted(self, output): + p = re.compile(r'(?<=\[)\w{2,3}(?=\])') + text = p.search(output).group() + + # check if the parsed string is either "off" or "on" + if text in ['on', 'off']: + return text == 'off' + + # if not, return False + else: + return False + + # this method is ran by py3status + # returns a response dict + def current_volume(self, i3s_output_list, i3s_config): + + # call amixer + output = check_output(shlex.split('amixer -D {} sget {}'.format( + self.device, self.channel))).decode('utf-8') + + # get the current percentage value + perc = self._get_percentage(output) + + # get info about channel mute status + muted = self._get_muted(output) + + # determine the color based on the current volume level + color = self._perc_to_color(i3s_config, perc) + + # format the output + text = self._format_output(self.format_muted + if muted else self.format, perc) + + # if the text has been changed, update the cached text and + # set transformed to True + transformed = text != self.text + self.text = text + + # create response dict + response = { + 'cached_until': time() + self.cache_timeout, + 'color': color, + 'full_text': text, + 'transformed': transformed + } + return response + +# test if run directly +if __name__ == "__main__": + from time import sleep + x = Py3status() + config = { + 'color_bad': '#FF0000', + 'color_degraded': '#FFFF00', + 'color_good': '#00FF00' + } + + while True: + print(x.current_volume([], config)) + sleep(1) |
