-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
external_script: notifications #1585
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
The script should not have any parameters, but it could work. | ||
|
||
Configuration parameters: | ||
button_show_notification: button to show notification with full output | ||
(default None) | ||
cache_timeout: how often we refresh this module in seconds | ||
(default 15) | ||
format: see placeholders below (default '{output}') | ||
|
@@ -21,6 +23,7 @@ | |
(default False) | ||
|
||
Format placeholders: | ||
{line} number of lines in the output | ||
{output} output of script given by "script_path" | ||
|
||
i3status.conf example: | ||
|
@@ -49,6 +52,7 @@ class Py3status: | |
""" | ||
""" | ||
# available configuration parameters | ||
button_show_notification = None | ||
cache_timeout = 15 | ||
format = '{output}' | ||
localize = True | ||
|
@@ -64,8 +68,8 @@ def external_script(self): | |
response = {} | ||
response['cached_until'] = self.py3.time_in(self.cache_timeout) | ||
try: | ||
output = self.py3.command_output(self.script_path, shell=True, localized=self.localize) | ||
output_lines = output.splitlines() | ||
self.output = self.py3.command_output(self.script_path, shell=True, localized=self.localize) | ||
output_lines = self.output.splitlines() | ||
if len(output_lines) > 1: | ||
output_color = output_lines[1] | ||
if re.search(r'^#[0-9a-fA-F]{6}$', output_color): | ||
|
@@ -97,9 +101,15 @@ def external_script(self): | |
output = '' | ||
|
||
response['full_text'] = self.py3.safe_format( | ||
self.format, {'output': output}) | ||
self.format, {'output': output, 'line': len(output_lines)}) | ||
return response | ||
|
||
def on_click(self, event): | ||
button = event["button"] | ||
if button == self.button_show_notification: | ||
self.py3.notify_user(self.output) | ||
self.py3.prevent_refresh() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One problem I see with this simple approach is that if a user added a custom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already the case with all click enabled modules and is the expected behavior. I'd do nothing here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already changed to |
||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about plural
lines
instead? should more logical to meThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, to me too, I was following earlier comment 🙂 Changed back to
lines
now.