Skip to content

Commit 9949d54

Browse files
authored
Merge pull request #40 from Flow-Launcher/update_python_docs
Update Python example plugin docs
2 parents a6bfe6f + bcb8e03 commit 9949d54

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

py-develop-plugins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ When building a Python plugins there are several things to be mindful of:
99
2. Publish all as a zip- zip up your project including a lib directory that contains the modules and publish it to GitHub Releases page.
1010
3. Point your module imports to the lib directory- reference all the modules to that directory where they are first imported.
1111

12-
* The user can use their own system installed Python with Flow Launcher. But in most circumstances the user will most likely be using Flow Launcher's own embedded Python executable. [Embedded Python](https://docs.python.org/3/using/windows.html#the-embeddable-package) is isolated from the users system and does not prepend the scripts run directory to the system `PATH`.<sup>[ref](https://bugs.python.org/issue28245)</sup> If you need to import external files please follow the example below.
12+
* User can use their own system installed Python with Flow Launcher. But in most circumstances they will most likely be using Flow Launcher's own embedded Python executable. [Embedded Python](https://docs.python.org/3/using/windows.html#the-embeddable-package) is isolated from the users system and does not prepend the scripts run directory to the system `PATH`.<sup>[ref](https://bugs.python.org/issue28245)</sup> If you need to import external files please follow the example below.
1313

1414
### Simple Example
15-
Have a look at this simple example plugin [here](https://github.com/Flow-Launcher/plugin-samples/tree/master/HelloWorldPython), notice it has a folder called '.github/workflows' and a file called 'Publish Release.yml'. This is the workflow file that GitHub Workflow uses to run the CICD for the project. Moving out of that folder you can go into the [main.py](https://github.com/Flow-Launcher/plugin-samples/blob/master/HelloWorldPython/plugin.json) file, this is the entry file for your plugin. Notice it has this code block:
15+
Have a look at this simple example plugin [here](https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython), notice it has a folder called '.github/workflows' and a file called 'Publish Release.yml'. This is the workflow file that GitHub Workflow uses to run the CICD for the project. Moving out of that folder you can go into the [main.py](https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython/blob/main/main.py) file, this is the entry file for your plugin. Notice it has this code block:
1616
```python
1717
import sys,os
1818
parent_folder_path = os.path.abspath(os.path.dirname(__file__))

py-setup-project.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### 1. Add GitHub workflow
2-
The workflow [file](https://github.com/Flow-Launcher/plugin-samples/blob/master/HelloWorldPython/.github/workflows/Publish%20Release.yml) will help build and deploy your project, it does the following things:
2+
The workflow [file](https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython/blob/main/.github/workflows/Publish%20Release.yml) will help build and deploy your project, it does the following things:
33
1. `workflow_dispatch:` gives you the option to manually run your workflow from the Actions section of your project
44
2. On pushes to main, it will kick off the workflow but ignore the push if it's only changes made to the workflow file.
55
```yml
@@ -22,25 +22,25 @@ push:
2222
path: 'plugin.json'
2323
prop_path: 'Version'
2424
```
25-
5. The 'Install dependencies' section is where you will do most of your CI work. Notice it installs the requirements.txt and outputs it with the `-t` parameter to the `./lib` folder. This tells pip to dump all the installed modules to the local lib folder which you will zip up along with your project using the `zip -r <NAME-OF-YOUR-PLUGIN>.zip . -x '*.git*'`, where you replace this `<NAME-OF-YOUR-PLUGIN>` with the name of your plugin.
25+
5. The 'Install dependencies' section is where you will do most of your CI work. Notice it installs the requirements.txt and outputs it with the `-t` parameter to the `./lib` folder. This tells pip to dump all the installed modules to the local lib folder which you will zip up along with your project using the `zip -r Flow.Launcher.Plugin.HelloWorldPython.zip . -x '*.git*'`, where you replace this `Flow.Launcher.Plugin.HelloWorldPython` with the name of your plugin.
2626

2727
You can also add additional steps here to unpack/install any additional depedencies your plugin requires, for example compiling additional translation files like [this](https://github.com/deefrawley/Flow.Launcher.Plugin.Currency/blob/23770ee929af059b1b1b7f9b5f3327b692ac9587/.github/workflows/Publish%20Release.yml#L34)
2828
```yml
2929
- name: Install dependencies
3030
run: |
3131
python -m pip install --upgrade pip
3232
pip install -r ./requirements.txt -t ./lib
33-
zip -r <NAME-OF-YOUR-PLUGIN>.zip . -x '*.git*'
33+
zip -r Flow.Launcher.Plugin.HelloWorldPython.zip . -x '*.git*'
3434
```
3535

3636
### 2. Publish as zip
37-
The final step to the workflow file is this publish section, which will publish the zip file you generated, upload to GitHub Releases page and tag with the version generated from the previous step from your plugin.json file. Remmember again to replace `<NAME-OF-YOUR-PLUGIN>` with the name of your plugin.
37+
The final step to the workflow file is this publish section, which will publish the zip file you generated, upload to GitHub Releases page and tag with the version generated from the previous step from your plugin.json file. Remember again to replace `Flow.Launcher.Plugin.HelloWorldPython` with the name of your plugin.
3838
```yml
3939
- name: Publish
40-
if: success() && github.ref == 'refs/heads/main'
40+
if: success()
4141
uses: softprops/action-gh-release@v1
4242
with:
43-
files: '<NAME-OF-YOUR-PLUGIN>.zip'
43+
files: 'Flow.Launcher.Plugin.HelloWorldPython.zip'
4444
tag_name: "v${{steps.version.outputs.prop}}"
4545
env:
4646
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -58,4 +58,4 @@ sys.path.append(os.path.join(parent_folder_path, 'lib'))
5858
sys.path.append(os.path.join(parent_folder_path, 'plugin'))
5959
6060
```
61-
Add the above code into your init file at the top, usually this is the [main.py](https://github.com/Flow-Launcher/plugin-samples/blob/master/HelloWorldPython/main.py) file. This block of code appends the path of your lib and plugin directories on the user's machine to `sys.path`. `sys.path` is a built-in variable within the sys module, which contains a list of directories that the Python interpreter will search in for the required module. Effectively we are telling the interpreter if the required modules in your plugin are not found among its built-in modules then look through the list of directories defined by sys.path, which should have all the modules installed by your GitHub workflow in the 'lib' folder.
61+
Add the above code into your init file at the top, usually this is the [main.py](https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython/blob/main/main.py) file. This block of code appends the path of your lib and plugin directories on the user's machine to `sys.path`. `sys.path` is a built-in variable within the sys module, which contains a list of directories that the Python interpreter will search in for the required module. Effectively we are telling the interpreter if the required modules in your plugin are not found among its built-in modules then look through the list of directories defined by sys.path, which should have all the modules installed by your GitHub workflow in the 'lib' folder.

py-write-code.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ sys.path.append(os.path.join(parent_folder_path, 'lib'))
1313
sys.path.append(os.path.join(parent_folder_path, 'plugin'))
1414
1515
from flowlauncher import FlowLauncher
16+
import webbrowser
1617
1718
1819
class HelloWorld(FlowLauncher):
@@ -21,27 +22,30 @@ class HelloWorld(FlowLauncher):
2122
return [
2223
{
2324
"Title": "Hello World, this is where title goes. {}".format(('Your query is: ' + query , query)[query == '']),
24-
"SubTitle": "This is where your subtitle goes",
25+
"SubTitle": "This is where your subtitle goes, press enter to open Flow's url",
2526
"IcoPath": "Images/app.png",
2627
"JsonRPCAction": {
27-
"method": "do_something_for_query",
28-
"parameters": [param1, param2]
28+
"method": "open_url",
29+
"parameters": ["https://github.com/Flow-Launcher/Flow.Launcher"]
2930
}
30-
"ContextData": "ctxData",
3131
}
3232
]
3333
3434
def context_menu(self, data):
3535
return [
3636
{
37-
"Title": "Context menu entry",
38-
"SubTitle": "Data: {}".format(data),
39-
"IcoPath": "Images/app.ico",
37+
"Title": "Hello World Python's Context menu",
38+
"SubTitle": "Press enter to open Flow the plugin's repo in GitHub",
39+
"IcoPath": "Images/app.png",
40+
"JsonRPCAction": {
41+
"method": "open_url",
42+
"parameters": ["https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldPython"]
43+
}
4044
}
4145
]
4246
43-
def do_something_for_query(self, param1, param2):
44-
pass
47+
def open_url(self, url):
48+
webbrowser.open(url)
4549
4650
if __name__ == "__main__":
4751
HelloWorld()
@@ -59,14 +63,14 @@ This is the main entry to your plugin and the return block will be a list of the
5963
**JsonRPCAction**
6064

6165
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.
66+
In this example, if the user selects the result, the `open_url` method will be called with the url parameter that opens the Flow Launcher GitHub repo.
6367

6468
### 5. Create an additional context menu
6569
**def context_menu(self, data):**
6670

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.
71+
This method creates a context menu for your results, where the user can carry out additional tasks when they 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.
6872

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.
73+
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. In this case the context menu will simply open the HelloWorldPython plugin's GitHub repo.
7074

7175
### 6. Your plugin.json
7276

0 commit comments

Comments
 (0)