From ac718e7b771302ae6c0c9408ad47333f21919bab Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 25 Jun 2015 13:38:28 +0200 Subject: Adding external_script and static_string modules and mentioning them in readme --- py3status/modules/README.md | 26 +++++++++++++++++ py3status/modules/external_script.py | 56 ++++++++++++++++++++++++++++++++++++ py3status/modules/static_string.py | 39 +++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 py3status/modules/external_script.py create mode 100644 py3status/modules/static_string.py (limited to 'py3status/modules') diff --git a/py3status/modules/README.md b/py3status/modules/README.md index 2b62105..45d52b4 100644 --- a/py3status/modules/README.md +++ b/py3status/modules/README.md @@ -471,4 +471,30 @@ Available modules: @author ultrabug --- +static_string Display static text + + Display static text given by "text" parameter + + Configuration parameters: + - text : text that should be printed + - separator : whether the separator is shown or not (True or False) + - color : color of printed text + - on_click : read goo.gl/u10n0x + + @author frimdo ztracenastopa@centrum.cz + --- +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 + - script_path : script you want to show output of (compulsory) + - color : color of printed text + - on_click : read goo.gl/u10n0x + + @author frimdo ztracenastopa@centrum.cz + --- ``` diff --git a/py3status/modules/external_script.py b/py3status/modules/external_script.py new file mode 100644 index 0000000..9488c79 --- /dev/null +++ b/py3status/modules/external_script.py @@ -0,0 +1,56 @@ +# -*- 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 + - script_path : script you want to show output of (compulsory) + - color : color of printed text + - on_click : read goo.gl/u10n0x + +@author frimdo ztracenastopa@centrum.cz +""" + +import subprocess +from time import time + + +class Py3status: + cache_timeout = 15 + color = None + 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, + 'full_text': return_value.rstrip(), + 'color': self.color + } + + 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(x.cache_timeout) + diff --git a/py3status/modules/static_string.py b/py3status/modules/static_string.py new file mode 100644 index 0000000..d525238 --- /dev/null +++ b/py3status/modules/static_string.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +""" +Display static text + +Display static text given by "text" parameter + +Configuration parameters: + - text : text that should be printed + - separator : whether the separator is shown or not (True or False) + - color : color of printed text + - on_click : read goo.gl/u10n0x + +@author frimdo ztracenastopa@centrum.cz +""" + +class Py3status: + color = None + text = "" + separator = True + + def static_string(self, i3s_output_list, i3s_config): + + response = { + 'full_text': self.text, + 'color': self.color, + 'separator': self.separator + } + + return response + +if __name__ == "__main__": + from time import sleep + x = Py3status() + config = { + 'color_good': '#00FF00', + 'color_bad': '#FF0000', + } + print(x.static_string([], config)) + -- cgit v1.3 From dbf831227b88e5cc82fad74af185b7ac44f895b2 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 25 Jun 2015 16:14:50 +0200 Subject: format RFC support for external_script and static_string --- py3status/modules/README.md | 1 + py3status/modules/external_script.py | 36 ++++++++++++++++++++++++------------ py3status/modules/static_string.py | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 22 deletions(-) (limited to 'py3status/modules') diff --git a/py3status/modules/README.md b/py3status/modules/README.md index 45d52b4..3618da7 100644 --- a/py3status/modules/README.md +++ b/py3status/modules/README.md @@ -484,6 +484,7 @@ static_string Display static text @author frimdo ztracenastopa@centrum.cz --- 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 diff --git a/py3status/modules/external_script.py b/py3status/modules/external_script.py index 9488c79..c2a6977 100644 --- a/py3status/modules/external_script.py +++ b/py3status/modules/external_script.py @@ -11,38 +11,51 @@ Configuration parameters: - script_path : script you want to show output of (compulsory) - color : color of printed text - on_click : read goo.gl/u10n0x + - format : see placeholders below + +Format of status string placeholders: + {output} - output of script given by "script_path" + +i3status.conf example: + +external_script { + script_path = "/usr/bin/whoami" + format = "my name is {output}" + color = "#00FF00" @author frimdo ztracenastopa@centrum.cz """ - + import subprocess from time import time - - + + class Py3status: cache_timeout = 15 + format = '{output}' color = None 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, - 'full_text': return_value.rstrip(), + 'full_text': self.format.format( + output=return_value.rstrip()), 'color': self.color } - + else: response = { 'cached_until': time() + self.cache_timeout, 'full_text': "" } - + return response - + if __name__ == "__main__": from time import sleep x = Py3status() @@ -52,5 +65,4 @@ if __name__ == "__main__": } while True: print(x.external_script([], config)) - sleep(x.cache_timeout) - + sleep(1) diff --git a/py3status/modules/static_string.py b/py3status/modules/static_string.py index d525238..c09176b 100644 --- a/py3status/modules/static_string.py +++ b/py3status/modules/static_string.py @@ -2,38 +2,38 @@ """ Display static text -Display static text given by "text" parameter +Display static text given by "format" parameter Configuration parameters: - text : text that should be printed - separator : whether the separator is shown or not (True or False) + - format : text that should be printed - color : color of printed text - on_click : read goo.gl/u10n0x @author frimdo ztracenastopa@centrum.cz """ - + + class Py3status: color = None - text = "" + format = '' separator = True - + def static_string(self, i3s_output_list, i3s_config): - + response = { - 'full_text': self.text, + 'full_text': self.format, 'color': self.color, 'separator': self.separator } - + return response - + if __name__ == "__main__": - from time import sleep x = Py3status() config = { 'color_good': '#00FF00', 'color_bad': '#FF0000', } print(x.static_string([], config)) - -- cgit v1.3 From ae7af22cd383a37ca72abe762643aedc271e6ec6 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 2 Jul 2015 12:18:16 +0200 Subject: repaired order of modules in readme --- py3status/modules/README.md | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'py3status/modules') diff --git a/py3status/modules/README.md b/py3status/modules/README.md index 3618da7..15f4bd3 100644 --- a/py3status/modules/README.md +++ b/py3status/modules/README.md @@ -96,6 +96,21 @@ Available modules: @author Andre Doser --- +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 + - script_path : script you want to show output of (compulsory) + - color : color of printed text + - on_click : read goo.gl/u10n0x + + @author frimdo ztracenastopa@centrum.cz + --- glpi Display the total number of open tickets from GLPI. Configuration parameters: @@ -345,6 +360,18 @@ Available modules: @author Pierre Guilbert --- +static_string Display static text + + Display static text given by "text" parameter + + Configuration parameters: + - text : text that should be printed + - separator : whether the separator is shown or not (True or False) + - color : color of printed text + - on_click : read goo.gl/u10n0x + + @author frimdo ztracenastopa@centrum.cz + --- sysdata Display system RAM and CPU utilization. NOTE: If you want py3status to show you your CPU temperature, @@ -471,31 +498,4 @@ Available modules: @author ultrabug --- -static_string Display static text - - Display static text given by "text" parameter - - Configuration parameters: - - text : text that should be printed - - separator : whether the separator is shown or not (True or False) - - color : color of printed text - - on_click : read goo.gl/u10n0x - - @author frimdo ztracenastopa@centrum.cz - --- -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 - - script_path : script you want to show output of (compulsory) - - color : color of printed text - - on_click : read goo.gl/u10n0x - - @author frimdo ztracenastopa@centrum.cz - --- ``` -- cgit v1.3