Ulauncher
Ulauncher copied to clipboard
Extension tutorial: Update with real functional extension example(s)
Description
From https://github.com/Ulauncher/Ulauncher/pull/1097#issuecomment-1196054319:
I think we should move this extension to the Ulauncher repos and also use it for the documentation since it's extremely simple, yet demonstrating a valid use case of multiple keyword arguments.
import hashlib
from ulauncher.api import Extension, ExtensionResult
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
class Hash2(Extension):
def on_input(self, input_text, trigger_id):
# Show the algorithm specified as keyword, or all if the keyword was "hash"
algorithms = hashlib.algorithms_guaranteed if trigger_id == 'hash' else [trigger_id]
for algorithm in algorithms:
try:
seed = hashlib.new(algorithm)
seed.update(input_text.encode())
hash = seed.hexdigest()
yield ExtensionResult(
name=hash,
description=algorithm,
on_enter=CopyToClipboardAction(hash),
)
except:
pass
if __name__ == '__main__':
Hash2().run()
We can also use the name "Ulauncher Hash" for the new repo since brpaz unpublished his original package and deleted the repo.
This is a good beginner example, but it would be good to add more examples to cover other parts of the API covering all the class methods for event binding in the class.
- [x] Move repo to Ulauncher organization and rename to drop the "2"
- [x] Publish the new link in ext.ulauncher.io
- [x] Unpublish the previous link
- [ ] Rewrite tutorial to show how to create Ulauncher Hash