Skip to content

Commit 1dc903d

Browse files
committed
🚧 finished flowlauncher package
1 parent 3fd8260 commit 1dc903d

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

flowlauncher/FlowLauncher.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
import inspect
5+
import json
6+
import sys
7+
8+
9+
class FlowLauncher:
10+
"""
11+
Flow.Launcher python plugin base
12+
"""
13+
14+
def __init__(self):
15+
# TODO: try other way to get argv not using index
16+
# with this, to test a plugin, it has to likes `python test.py {}`. Add `{}`.
17+
# It is better with like this `python test.py`, when the input is empty.
18+
rpc_request = json.loads(sys.argv[1])
19+
20+
# proxy is not working now
21+
self.proxy = rpc_request.get("proxy", {})
22+
request_method_name = rpc_request.get("method", "query")
23+
request_parameters = rpc_request.get("parameters", [])
24+
methods = inspect.getmembers(self, predicate=inspect.ismethod)
25+
26+
request_method = dict(methods)[request_method_name]
27+
results = request_method(*request_parameters)
28+
29+
if request_method_name in ["query", "context_menu"]:
30+
print(json.dumps({"result": results}))
31+
32+
def query(self, param: str = ''):
33+
"""
34+
sub class need to override this method
35+
"""
36+
return []
37+
38+
def context_menu(self, data):
39+
"""
40+
optional context menu entries for a result
41+
"""
42+
return []
43+
44+
def debug(self, msg):
45+
"""
46+
alert msg
47+
"""
48+
print("DEBUG:{}".format(msg))
49+
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 json
4+
5+
6+
class FlowLauncherAPI(object):
7+
8+
@classmethod
9+
def change_query(cls, query, requery=False):
10+
"""
11+
change flow launcher query
12+
"""
13+
print(json.dumps({
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(json.dumps({
23+
"method": "Flow.Launcher.ShellRun",
24+
"parameters": [cmd]}))
25+
26+
@classmethod
27+
def close_app(cls):
28+
"""
29+
close flow launcher
30+
"""
31+
print(json.dumps({
32+
"method": "Flow.Launcher.CloseApp",
33+
"parameters": []}))
34+
35+
@classmethod
36+
def hide_app(cls):
37+
"""
38+
hide flow launcher
39+
"""
40+
print(json.dumps({
41+
"method": "Flow.Launcher.HideApp",
42+
"parameters": []}))
43+
44+
@classmethod
45+
def show_app(cls):
46+
"""
47+
show flow launcher
48+
"""
49+
print(json.dumps({
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(json.dumps({
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(json.dumps({
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(json.dumps({
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(json.dumps({
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(json.dumps({
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.'

0 commit comments

Comments
 (0)