2014-07-10 18:39:04 +08:00
|
|
|
#encoding=utf8
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
import inspect
|
|
|
|
|
|
|
|
class Wox(object):
|
|
|
|
"""
|
|
|
|
Wox python plugin base
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2014-10-13 13:57:55 +08:00
|
|
|
rpc_request = json.loads(sys.argv[1],encoding="gb2312")
|
2014-07-18 20:00:55 +08:00
|
|
|
self.proxy = rpc_request.get("proxy",{})
|
2014-07-10 18:39:04 +08:00
|
|
|
request_method_name = rpc_request.get("method")
|
|
|
|
request_parameters = rpc_request.get("parameters")
|
|
|
|
methods = inspect.getmembers(self, predicate=inspect.ismethod)
|
|
|
|
|
|
|
|
request_method = dict(methods)[request_method_name]
|
2014-07-10 23:57:08 +08:00
|
|
|
results = request_method(*request_parameters)
|
|
|
|
if request_method_name == "query":
|
|
|
|
print json.dumps({"result": results})
|
2014-07-10 18:39:04 +08:00
|
|
|
|
|
|
|
def query(self,query):
|
|
|
|
"""
|
|
|
|
sub class need to override this method
|
|
|
|
"""
|
|
|
|
return []
|
2014-10-21 18:16:05 +08:00
|
|
|
|
2014-07-18 20:00:55 +08:00
|
|
|
def debug(self,msg):
|
|
|
|
"""
|
|
|
|
alert msg
|
|
|
|
"""
|
2014-10-13 13:57:55 +08:00
|
|
|
print "DEBUG:{}".format(msg)
|
2014-07-18 20:00:55 +08:00
|
|
|
sys.exit()
|
2014-07-10 23:57:08 +08:00
|
|
|
|
|
|
|
class WoxAPI(object):
|
|
|
|
|
|
|
|
@classmethod
|
2014-07-18 23:12:50 +08:00
|
|
|
def change_query(cls,query,requery = False):
|
2014-07-10 23:57:08 +08:00
|
|
|
"""
|
|
|
|
change wox query
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]})
|
2014-10-17 16:36:19 +08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def shell_run(cls,cmd):
|
|
|
|
"""
|
|
|
|
run shell commands
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.ShellRun","parameters":[cmd]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def close_app(cls):
|
|
|
|
"""
|
|
|
|
close wox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.CloseApp","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def hide_app(cls):
|
|
|
|
"""
|
|
|
|
hide wox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.HideApp","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def show_app(cls):
|
|
|
|
"""
|
|
|
|
show wox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.ShowApp","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def show_msg(cls,title,sub_title,ico_path=""):
|
|
|
|
"""
|
|
|
|
show messagebox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.ShowMsg","parameters":[title,sub_title,ico_path]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def open_setting_dialog(cls):
|
|
|
|
"""
|
|
|
|
open setting dialog
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.OpenSettingDialog","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def start_loadingbar(cls):
|
|
|
|
"""
|
|
|
|
start loading animation in wox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.StartLoadingBar","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def stop_loadingbar(cls):
|
|
|
|
"""
|
|
|
|
stop loading animation in wox
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.StopLoadingBar","parameters":[]})
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def reload_plugins(cls):
|
|
|
|
"""
|
|
|
|
reload all wox plugins
|
|
|
|
"""
|
|
|
|
print json.dumps({"method": "Wox.ReloadPlugins","parameters":[]})
|