-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pyflowlauncher import Plugin, Result, send_results | ||
from pyflowlauncher.result import ResultResponse | ||
|
||
plugin = Plugin() | ||
|
||
|
||
@plugin.on_method | ||
def query(query: str) -> ResultResponse: | ||
r = Result( | ||
Title="This is a title!", | ||
SubTitle="This is the subtitle!", | ||
JsonRPCAction={"method": "action", "parameters": []} | ||
) | ||
return send_results([r]) | ||
|
||
|
||
@plugin.on_method | ||
def action(params: list[str]): | ||
pass | ||
# Do stuff here | ||
# ... | ||
|
||
|
||
plugin.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pyflowlauncher import Plugin, Result, send_results | ||
from pyflowlauncher.result import ResultResponse | ||
|
||
plugin = Plugin() | ||
|
||
|
||
@plugin.on_method | ||
def query(query: str) -> ResultResponse: | ||
r = Result( | ||
Title="This is a title!", | ||
SubTitle="This is the subtitle!", | ||
JsonRPCAction=plugin.action(action, ["stuff"]) | ||
) | ||
return send_results([r]) | ||
|
||
|
||
def action(params: list[str]): | ||
pass | ||
# Do stuff here | ||
# ... | ||
|
||
|
||
plugin.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from pyflowlauncher import Plugin, Result, send_results | ||
from pyflowlauncher.result import ResultResponse | ||
from pyflowlauncher.utils import score_results | ||
|
||
plugin = Plugin() | ||
|
||
|
||
@plugin.on_method | ||
def query(query: str) -> ResultResponse: | ||
results = [] | ||
for _ in range(100): | ||
r = Result( | ||
Title="This is a title!", | ||
SubTitle="This is the subtitle!", | ||
) | ||
results.append(r) | ||
return send_results(score_results(query, results)) | ||
|
||
|
||
plugin.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Triggering Plugin methods | ||
|
||
Flow Launcher can call custom methods created by your plugin as well. To do so simply register the method with your plugin. | ||
|
||
You can register any Function by using the `on_method` decorator or by using the `add_method` method from `Plugin`. | ||
|
||
## Example 1 | ||
|
||
```py | ||
--8<-- "docs/examples/guide/plugin_methods/example1.py" | ||
``` | ||
|
||
Alternativley you can register and add the Method to a Result in one line by using `action` method. | ||
|
||
## Example 2 | ||
|
||
```py | ||
--8<-- "docs/examples/guide/plugin_methods/example2.py" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Score results | ||
|
||
PyFlowLauncher comes with a handy utility to help score your results in a similar manner to how Flow Launcher does internally. | ||
|
||
## Example | ||
|
||
```py | ||
--8<-- "docs/examples/guide/scoring_results/example1.py" | ||
``` |