Skip to content
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

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions py3status/modules/external_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -21,6 +23,7 @@
(default False)

Format placeholders:
{line} number of lines in the output
Copy link
Owner

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 me

Copy link
Contributor Author

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.

{output} output of script given by "script_path"

i3status.conf example:
Expand Down Expand Up @@ -49,6 +52,7 @@ class Py3status:
"""
"""
# available configuration parameters
button_show_notification = None
cache_timeout = 15
format = '{output}'
localize = True
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 on_click 1 handler, this will now execute both their handler and show notification. Maybe worth adding a flag show_click_notifications, or instead of button_refresh implement button_show_notification (so condition changes to if button == self.button_show_notification). Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already changed to button_show_notification, it's disabled by default so won't suddenly conflict with custom on_click 1 handlers. I think we are good here.



if __name__ == "__main__":
"""
Expand Down