Skip to content

Commit 73f3afc

Browse files
authored
Merge pull request #1 from Zeroto521/master
base version
2 parents 91905cc + 60d9d9b commit 73f3afc

File tree

11 files changed

+351
-1
lines changed

11 files changed

+351
-1
lines changed

.gitignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
7+
# C extensions
8+
*.so
9+
10+
11+
# Task / packaging
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
31+
# Unit test / coverage reports
32+
htmlcov/
33+
.tox/
34+
.coverage
35+
.coverage.*
36+
.cache
37+
nosetests.xml
38+
coverage.xml
39+
*.cover
40+
.hypothesis/
41+
.pytest_cache/
42+
43+
44+
# vscode
45+
.history
46+
.vscode
47+
48+
49+
# ppt
50+
*.ppt
51+
*.pptx

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sudo: false
2+
language: python
3+
python:
4+
- "3.6"
5+
- "3.7"
6+
- "3.8"
7+
8+
install:
9+
- pip install -r requirements.txt
10+
11+
before_install:
12+
- sudo apt-get update
13+
14+
script:
15+
- echo 'building test'
16+
- sh ./test.sh

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include MANIFEST.in
2+
include README.md

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1-
# Flow.Launcher.JsonRPC.Python
1+
# Flow.Launcher.JsonRPC.Python
2+
3+
[![Build Status](https://travis-ci.org/Zeroto521/Flow.Launcher.JsonRPC.Python.svg?branch=master)](https://travis-ci.org/Zeroto521/Flow.Launcher.JsonRPC.Python)
4+
5+
Flow Launcher supports Python by JsonRPC.
6+
7+
## JSON-RPC
8+
9+
> [JSON-RPC](https://en.wikipedia.org/wiki/JSON-RPC) is a remote procedure call protocol encoded in JSON.
10+
11+
In Flow Launcher, we use JSON-RPC as a **local** procedure call protocol to bind Flow and other program languages.
12+
13+
So we need to build a **common API** between Flow and Plugin.
14+
15+
![JsonRPC](./assets/jsonrpc.png)
16+
17+
### Example
18+
19+
- `-->` denotes data sent to FLow.
20+
- `<--` denotes data coming from Flow.
21+
22+
```json
23+
--> {"method": "query", "parameters": [""]}
24+
<-- {"Title": "title", "SubTitle": "sub title", "IconPath": "favicon.ico"}
25+
```
26+
27+
<!-- TODO: try to add some other examples -->
28+
29+
## Installation
30+
31+
### Using `pip`
32+
33+
``` powershell
34+
>>> pip install git+https://github.com/Flow-Launcher/Flow.Launcher.JsonRPC.Python.git
35+
```
36+
37+
### Using `git`
38+
39+
``` powershell
40+
>>> git clone https://github.com/Flow-Launcher/Flow.Launcher.JsonRPC.Python.git
41+
>>> cd Flow.Launcher.JsonRPC.Python
42+
>>> python setup.py install
43+
```
44+
45+
<!-- TODO: update Example Plugin (HellowWorldPython) for this plugin -->
46+
47+
### License
48+
49+
This project is under the [MIT](./LICENSE) license.
50+
51+
Some of the orignal codes from [JsonRPC/wox.py](https://github.com/Wox-launcher/Wox/blob/master/JsonRPC/wox.py) which is under the [MIT](https://github.com/Wox-launcher/Wox/blob/master/LICENSE) license.

assets/jsonrpc.png

14.1 KB
Loading

flowlauncher/FlowLauncher.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
import inspect
5+
import sys
6+
7+
import demjson
8+
9+
10+
class FlowLauncher:
11+
"""
12+
Flow.Launcher python plugin base
13+
"""
14+
15+
def __init__(self):
16+
17+
# defalut jsonrpc
18+
self.rpc_request = {'method': 'query', 'parameters': ['']}
19+
if len(sys.argv) > 1: # from input to get jsonrpc
20+
self.rpc_request = demjson.decode(sys.argv[1])
21+
22+
# proxy is not working now
23+
# self.proxy = self.rpc_request.get("proxy", {})
24+
25+
request_method_name = self.rpc_request.get("method", "query")
26+
27+
if request_method_name in ["query", "context_menu"]:
28+
request_parameters = self.rpc_request.get("parameters", [])
29+
methods = inspect.getmembers(self, predicate=inspect.ismethod)
30+
request_method = dict(methods)[request_method_name]
31+
results = request_method(*request_parameters)
32+
print(demjson.encode({"result": results}))
33+
34+
def query(self, param: str = '') -> list:
35+
"""
36+
sub class need to override this method
37+
"""
38+
return []
39+
40+
def context_menu(self, data) -> list:
41+
"""
42+
optional context menu entries for a result
43+
"""
44+
return []
45+
46+
def debug(self, msg: str):
47+
"""
48+
alert msg
49+
"""
50+
print(f"DEBUG:{msg}")
51+
sys.exit()

flowlauncher/FlowLauncherAPI.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import demjson
4+
5+
6+
class FlowLauncherAPI:
7+
8+
@classmethod
9+
def change_query(cls, query, requery: bool = False):
10+
"""
11+
change flow launcher query
12+
"""
13+
print(demjson.encode({
14+
"method": "Wox.ChangeQuery",
15+
"parameters": [query, requery]}))
16+
17+
@classmethod
18+
def shell_run(cls, cmd):
19+
"""
20+
run shell commands
21+
"""
22+
print(demjson.encode({
23+
"method": "Flow.Launcher.ShellRun",
24+
"parameters": [cmd]}))
25+
26+
@classmethod
27+
def close_app(cls):
28+
"""
29+
close flow launcher
30+
"""
31+
print(demjson.encode({
32+
"method": "Flow.Launcher.CloseApp",
33+
"parameters": []}))
34+
35+
@classmethod
36+
def hide_app(cls):
37+
"""
38+
hide flow launcher
39+
"""
40+
print(demjson.encode({
41+
"method": "Flow.Launcher.HideApp",
42+
"parameters": []}))
43+
44+
@classmethod
45+
def show_app(cls):
46+
"""
47+
show flow launcher
48+
"""
49+
print(demjson.encode({
50+
"method": "Flow.Launcher.ShowApp",
51+
"parameters": []}))
52+
53+
@classmethod
54+
def show_msg(cls, title: str, sub_title: str, ico_path: str = ""):
55+
"""
56+
show messagebox
57+
"""
58+
print(demjson.encode({
59+
"method": "Flow.Launcher.ShowMsg",
60+
"parameters": [title, sub_title, ico_path]}))
61+
62+
@classmethod
63+
def open_setting_dialog(cls):
64+
"""
65+
open setting dialog
66+
"""
67+
print(demjson.encode({
68+
"method": "Flow.Launcher.OpenSettingDialog",
69+
"parameters": []}))
70+
71+
@classmethod
72+
def start_loadingbar(cls):
73+
"""
74+
start loading animation in flow launcher
75+
"""
76+
print(demjson.encode({
77+
"method": "Flow.Launcher.StartLoadingBar",
78+
"parameters": []}))
79+
80+
@classmethod
81+
def stop_loadingbar(cls):
82+
"""
83+
stop loading animation in flow launcher
84+
"""
85+
print(demjson.encode({
86+
"method": "Flow.Launcher.StopLoadingBar",
87+
"parameters": []}))
88+
89+
@classmethod
90+
def reload_plugins(cls):
91+
"""
92+
reload all flow launcher plugins
93+
"""
94+
print(demjson.encode({
95+
"method": "Flow.Launcher.ReloadPlugins",
96+
"parameters": []}))

flowlauncher/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .FlowLauncher import FlowLauncher
4+
from .FlowLauncherAPI import FlowLauncherAPI
5+
6+
7+
__version__ = '0.1.0'
8+
__license__ = 'MIT'
9+
__short_description__ = 'Flow Launcher supports Python by JsonRPC.'

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
demjson

setup.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
from setuptools import find_packages, setup
5+
6+
7+
NAME = "flowlauncher"
8+
9+
SHORT_DESCRIPTION = __import__(NAME).__short_description__
10+
LONG_DESCRIPTION = open("README.md", "r").read()
11+
12+
VERSION = __import__(NAME).__version__
13+
14+
AUTHOR = "Flow-Launcher"
15+
AUTHOR_EMAIL = "Zeroto521@gmail.com"
16+
MAINTAINER = "Zero"
17+
MAINTAINER_EMAIL = "Zeroto521@gmail.com"
18+
19+
URL = "https://github.com/Flow-Launcher/Flow.Launcher.JsonRPC.Python"
20+
DOWNLOAD_URL = "https://github.com/Flow-Launcher/Flow.Launcher.JsonRPC.Python/archive/master.zip"
21+
22+
LICENSE = __import__(NAME).__license__
23+
24+
PLATFORMS = ["Windows"]
25+
CLASSIFIERS = [
26+
"Development Status :: 3 - Alphaa",
27+
28+
"Intended Audience :: Developers",
29+
30+
"License :: OSI Approved :: MIT License",
31+
32+
"Natural Language :: English",
33+
34+
"Operating System :: Microsoft :: Windows",
35+
"Operating System :: Microsoft :: Windows :: Windows 10",
36+
37+
"Programming Language :: Python",
38+
"Programming Language :: Python :: 3",
39+
"Programming Language :: Python :: 3 :: Only",
40+
"Programming Language :: Python :: 3.6",
41+
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
43+
44+
"Topic :: Software Development",
45+
"Topic :: Software Development :: Libraries",
46+
"Topic :: Software Development :: Libraries :: Application Frameworks",
47+
]
48+
49+
with open("requirements.txt", "r") as f:
50+
REQUIRES = [package.strip() for package in f.readlines()]
51+
52+
53+
setup(
54+
name=NAME,
55+
version=VERSION,
56+
author=AUTHOR,
57+
author_email=AUTHOR_EMAIL,
58+
maintainer=MAINTAINER,
59+
maintainer_email=MAINTAINER_EMAIL,
60+
url=URL,
61+
license=LICENSE,
62+
description=SHORT_DESCRIPTION,
63+
long_description=LONG_DESCRIPTION,
64+
long_description_content_type="text/markdown",
65+
platforms=PLATFORMS,
66+
packages=find_packages(),
67+
include_package_data=True,
68+
download_url=DOWNLOAD_URL,
69+
requires=REQUIRES,
70+
classifiers=CLASSIFIERS
71+
)

0 commit comments

Comments
 (0)