Skip to content

Commit c24b8f0

Browse files
authored
Merge pull request #36 from jjw24/update_py_docs
add how to write and release plugin
2 parents 73f814d + 67a5968 commit c24b8f0

File tree

6 files changed

+84
-7
lines changed

6 files changed

+84
-7
lines changed

_sidebar.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
- Dotnet Plugins
77
- [**Development Guide**](/develop-dotnet-plugins.md)
88
- [**API Reference**](API-Reference/)
9-
- [**Python Plugins**](/develop-py-plugins.md)
10-
- [**Set up your project**](/setup-py-project.md)
11-
- [**Write the code**](/write-code-py.md)
9+
- Python Plugins
10+
- [**Before you start**](/py-develop-plugins.md)
11+
- [**Set up your project**](/py-setup-project.md)
12+
- [**Write the code**](/py-write-code.md)
13+
- [**Add your plugin to Flow**](/py-release-project.md)
1214
- JSONRPC
1315
- [**JSON RPC Introduction**](/json-rpc.md)
1416
- [**Porting Plugins**](/port-plugins.md)
File renamed without changes.

py-release-project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Release your plugin to Flow's Plugin Store
2+
When you are ready to release your plugin for people to enjoy, simply head over to Flow's [plugin repo](https://github.com/Flow-Launcher/Flow.Launcher.PluginsManifest) and follow the instructions there in the readme.
File renamed without changes.

py-write-code.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
### 1. Start with a branch
2+
Since we have created a CI for your plugin in the [previous step](https://flow-launcher.github.io/docs/#/py-setup-project), which includes creating a release when you push/merge to the 'main' branch, it is then neccessary to create another git branch separate to your 'main' branch so you can continue to work on your plugin with git commits and pushes without creating a new release each time.
3+
4+
It is a good practice that you create a branch for each of the new feature/fixes you are releasing for your plugin, if you are not sure how to do so then follow this [video tutorial](https://www.gitkraken.com/learn/git/problems/create-git-branch). Once you have fully finished developing your plugin with your new branch, then you can merge it into the 'main' branch, which will consequently create a new release for your plugin with a version from your `plugin.json`.
5+
6+
### 2. main.py
7+
your main.py should look something like below:
8+
```
9+
import sys,os
10+
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
11+
sys.path.append(parent_folder_path)
12+
sys.path.append(os.path.join(parent_folder_path, 'lib'))
13+
sys.path.append(os.path.join(parent_folder_path, 'plugin'))
14+
15+
from flowlauncher import FlowLauncher
16+
17+
18+
class HelloWorld(FlowLauncher):
19+
20+
def query(self, query):
21+
return [
22+
{
23+
"Title": "Hello World, this is where title goes. {}".format(('Your query is: ' + query , query)[query == '']),
24+
"SubTitle": "This is where your subtitle goes",
25+
"IcoPath": "Images/app.png",
26+
"JsonRPCAction": {
27+
"method": "do_something_for_query",
28+
"parameters": [param1, param2]
29+
}
30+
"ContextData": "ctxData",
31+
}
32+
]
33+
34+
def context_menu(self, data):
35+
return [
36+
{
37+
"Title": "Context menu entry",
38+
"SubTitle": "Data: {}".format(data),
39+
"IcoPath": "Images/app.ico",
40+
}
41+
]
42+
43+
def do_something_for_query(self, param1, param2):
44+
pass
45+
46+
if __name__ == "__main__":
47+
HelloWorld()
48+
49+
```
50+
51+
<br/>
52+
53+
### 3. Query entry point
54+
**def query(self, query):**
55+
56+
This is the main entry to your plugin and the return block will be a list of the results that your plugin returns, which could be a single or many results.
57+
58+
### 4. Assigning an action to your results
59+
**JsonRPCAction**
60+
61+
This is where you specify the method that will be executed when the user selects on the result.
62+
In this example, if the user selects the result, the `do_something_for_query` method will be called with the two parameters, it is then up to you to define what you want the method to do.
63+
64+
### 5. Create an additional context menu
65+
**def context_menu(self, data):**
66+
67+
This method creates a context menu for your results, where the user can carry out additional tasks when the go to the context menue via pressing `Shift + Enter`. A context menu could be helpful if you want some tasks specific to your returned results, for example the Explorer plugin would return a list of file results, and when going to the context menu of one of the result users can select to copy the file.
68+
69+
To attach a method to your context menu result, do the same as for normal results where you define a JsonRPCAction item with the method and parameters you want to call and pass through.
70+
71+
### 6. Your plugin.json
72+
73+
You will also need to if not yet already, create a plugin.json file that will instruct Flow on how to load your plugin.
74+
75+
This file should be placed in the top level folder.
76+
77+
To revisit what to include in your plugin.json, visit [here](https://flow-launcher.github.io/docs/#/plugin.json)

write-code-py.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)