Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Jan 25, 2024
1 parent 8f63902 commit 2466255
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/examples/guide/plugin_methods/example1.py
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()
23 changes: 23 additions & 0 deletions docs/examples/guide/plugin_methods/example2.py
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()
20 changes: 20 additions & 0 deletions docs/examples/guide/scoring_results/example1.py
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()
19 changes: 19 additions & 0 deletions docs/guide/Plugin methods.md
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"
```
9 changes: 9 additions & 0 deletions docs/guide/scoring_results.md
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"
```

0 comments on commit 2466255

Please sign in to comment.