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

Conversation

maximbaz
Copy link
Contributor

In light of new Zen #1582, I'm submitting a simple implementation for the pattern I use with external_script. In my mind is good enough until we come up with some sophisticated support for notifications in core. This replaces #1439.


Before:

  • external_script shows only first line of output, no way to see entire output
  • refreshes on any button click

After:

Why:

I use external_script with the same pattern for different purposes. Don't expect you to understand what exactly they are doing, just showing you a repeating pattern for which I'm implementing this PR.

Examples of why I need this for external_script
  • Check updates for official packages:

    • I have a script that outputs updates, one line per package
    • In status bar I have official updates: 3 (this is why I need line placeholder)
    • On click I show notification that shows names of those 3 packages
    • I don't want left click to refresh the module, because script is slow to execute, thus need for button_refresh, but I want to refresh on middle click
  • Check updates for unofficial packages:

    • I have a script that outputs updates, one line per package
    • In status bar I have unofficial updates: 3
    • On click I show notification that shows names of those 3 packages
    • I want left click to only show notification, and middle click to refresh
  • Check updates for VCS packages:

    • I have a script that outputs updates, one line per package
    • In status bar I have VCS updates: 3
    • On click I show notification that shows names of those 3 packages
    • I want left click to only show notification, and middle click to refresh
  • Check which packages need to be rebuild because of updated dependencies:

    • I have a script that outputs them, one line per package
    • In status bar I have packages to rebuild: 3
    • On click I show notification that shows names of those 3 packages
    • I want left click to only show notification, and middle click to refresh
  • Check which configs need to be updated because of updated packages:

    • I have a script that outputs them, one line per config
    • In status bar I have configs to update: 3
    • On click I show notification that shows names of those 3 configs
    • I want left click to only show notification, and middle click to refresh

button = event["button"]
if button != self.button_refresh:
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.

button = event["button"]
if button != self.button_refresh:
self.py3.notify_user(self.output)
self.py3.prevent_refresh()
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.

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

@ultrabug ultrabug self-assigned this Dec 2, 2018
@ultrabug ultrabug merged commit 9865a2e into ultrabug:master Dec 2, 2018
@ultrabug
Copy link
Owner

ultrabug commented Dec 2, 2018

Good enough and respects default behavior. This is in!

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants