mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 11:09:28 +08:00
Use existing installed python
1. use installed python 2. add settings to choose python directory 3. add py3 compability 4. create hello world python example
This commit is contained in:
parent
bc0f5a9136
commit
785843198a
BIN
Plugins/HelloWorldPython/Images/app.png
Normal file
BIN
Plugins/HelloWorldPython/Images/app.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
17
Plugins/HelloWorldPython/main.py
Normal file
17
Plugins/HelloWorldPython/main.py
Normal file
@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from wox import Wox
|
||||
|
||||
class HelloWorld(Wox):
|
||||
|
||||
def query(self, query):
|
||||
results = []
|
||||
results.append({
|
||||
"Title": "Hello World",
|
||||
"SubTitle": "Query: {}".format(query),
|
||||
"IcoPath":"Images/app.ico"
|
||||
})
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
HelloWorld()
|
12
Plugins/HelloWorldPython/plugin.json
Normal file
12
Plugins/HelloWorldPython/plugin.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"ID":"2f4e384e-76ce-45c3-aea2-b16f5e5c328f",
|
||||
"ActionKeyword":"h",
|
||||
"Name":"Hello World Python",
|
||||
"Description":"Hello World",
|
||||
"Author":"happlebao",
|
||||
"Version":"1.0",
|
||||
"Language":"python",
|
||||
"Website":"https://github.com/Wox-launche/Wox",
|
||||
"IcoPath":"Images\\app.png",
|
||||
"ExecuteFileName":"main.py"
|
||||
}
|
107
Plugins/HelloWorldPython/wox.py
Normal file
107
Plugins/HelloWorldPython/wox.py
Normal file
@ -0,0 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import sys
|
||||
import inspect
|
||||
|
||||
class Wox(object):
|
||||
"""
|
||||
Wox python plugin base
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
rpc_request = json.loads(sys.argv[1])
|
||||
self.proxy = rpc_request.get("proxy",{})
|
||||
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]
|
||||
results = request_method(*request_parameters)
|
||||
if request_method_name == "query":
|
||||
print(json.dumps({"result": results}))
|
||||
|
||||
def query(self,query):
|
||||
"""
|
||||
sub class need to override this method
|
||||
"""
|
||||
return []
|
||||
|
||||
def debug(self,msg):
|
||||
"""
|
||||
alert msg
|
||||
"""
|
||||
print("DEBUG:{}".format(msg))
|
||||
sys.exit()
|
||||
|
||||
class WoxAPI(object):
|
||||
|
||||
@classmethod
|
||||
def change_query(cls,query,requery = False):
|
||||
"""
|
||||
change wox query
|
||||
"""
|
||||
print(json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]}))
|
||||
|
||||
@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":[]}))
|
30
PythonHome/wox.py
vendored
30
PythonHome/wox.py
vendored
@ -1,8 +1,8 @@
|
||||
#encoding=utf8
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import sys
|
||||
import inspect
|
||||
import chardet
|
||||
|
||||
class Wox(object):
|
||||
"""
|
||||
@ -10,7 +10,7 @@ class Wox(object):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
rpc_request = json.loads(sys.argv[1],encoding=chardet.detect(sys.argv[1])["encoding"])
|
||||
rpc_request = json.loads(sys.argv[1])
|
||||
self.proxy = rpc_request.get("proxy",{})
|
||||
request_method_name = rpc_request.get("method")
|
||||
request_parameters = rpc_request.get("parameters")
|
||||
@ -19,7 +19,7 @@ class Wox(object):
|
||||
request_method = dict(methods)[request_method_name]
|
||||
results = request_method(*request_parameters)
|
||||
if request_method_name == "query":
|
||||
print json.dumps({"result": results})
|
||||
print(json.dumps({"result": results}))
|
||||
|
||||
def query(self,query):
|
||||
"""
|
||||
@ -31,7 +31,7 @@ class Wox(object):
|
||||
"""
|
||||
alert msg
|
||||
"""
|
||||
print "DEBUG:{}".format(msg)
|
||||
print("DEBUG:{}".format(msg))
|
||||
sys.exit()
|
||||
|
||||
class WoxAPI(object):
|
||||
@ -41,67 +41,67 @@ class WoxAPI(object):
|
||||
"""
|
||||
change wox query
|
||||
"""
|
||||
print json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]})
|
||||
print(json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]}))
|
||||
|
||||
@classmethod
|
||||
def shell_run(cls,cmd):
|
||||
"""
|
||||
run shell commands
|
||||
"""
|
||||
print json.dumps({"method": "Wox.ShellRun","parameters":[cmd]})
|
||||
print(json.dumps({"method": "Wox.ShellRun","parameters":[cmd]}))
|
||||
|
||||
@classmethod
|
||||
def close_app(cls):
|
||||
"""
|
||||
close wox
|
||||
"""
|
||||
print json.dumps({"method": "Wox.CloseApp","parameters":[]})
|
||||
print(json.dumps({"method": "Wox.CloseApp","parameters":[]}))
|
||||
|
||||
@classmethod
|
||||
def hide_app(cls):
|
||||
"""
|
||||
hide wox
|
||||
"""
|
||||
print json.dumps({"method": "Wox.HideApp","parameters":[]})
|
||||
print(json.dumps({"method": "Wox.HideApp","parameters":[]}))
|
||||
|
||||
@classmethod
|
||||
def show_app(cls):
|
||||
"""
|
||||
show wox
|
||||
"""
|
||||
print json.dumps({"method": "Wox.ShowApp","parameters":[]})
|
||||
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]})
|
||||
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":[]})
|
||||
print(json.dumps({"method": "Wox.OpenSettingDialog","parameters":[]}))
|
||||
|
||||
@classmethod
|
||||
def start_loadingbar(cls):
|
||||
"""
|
||||
start loading animation in wox
|
||||
"""
|
||||
print json.dumps({"method": "Wox.StartLoadingBar","parameters":[]})
|
||||
print(json.dumps({"method": "Wox.StartLoadingBar","parameters":[]}))
|
||||
|
||||
@classmethod
|
||||
def stop_loadingbar(cls):
|
||||
"""
|
||||
stop loading animation in wox
|
||||
"""
|
||||
print json.dumps({"method": "Wox.StopLoadingBar","parameters":[]})
|
||||
print(json.dumps({"method": "Wox.StopLoadingBar","parameters":[]}))
|
||||
|
||||
@classmethod
|
||||
def reload_plugins(cls):
|
||||
"""
|
||||
reload all wox plugins
|
||||
"""
|
||||
print json.dumps({"method": "Wox.ReloadPlugins","parameters":[]})
|
||||
print(json.dumps({"method": "Wox.ReloadPlugins","parameters":[]}))
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Wox.Infrastructure.Exception;
|
||||
@ -8,42 +9,105 @@ using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
internal class CSharpPluginLoader : IPluginLoader
|
||||
public static class PluginsLoader
|
||||
{
|
||||
public IEnumerable<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
public const string PATH = "PATH";
|
||||
public const string Python = "python";
|
||||
public const string PythonExecutable = "pythonw.exe";
|
||||
|
||||
public static IEnumerable<PluginPair> CSharpPlugins(IEnumerable<PluginMetadata> source)
|
||||
{
|
||||
var plugins = new List<PluginPair>();
|
||||
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||
var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp);
|
||||
|
||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
Assembly assembly;
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
Log.Warn($"Couldn't load plugin {metadata.Name}: didn't find the class that implement IPlugin");
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
PluginPair pair = new PluginPair
|
||||
{
|
||||
Plugin = Activator.CreateInstance(type) as IPlugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
|
||||
plugins.Add(pair);
|
||||
}
|
||||
assembly = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(new WoxPluginException(metadata.Name, $"Couldn't load plugin", e));
|
||||
Log.Error(new WoxPluginException(metadata.Name, "Couldn't load assembly", e));
|
||||
continue;
|
||||
}
|
||||
var types = assembly.GetTypes();
|
||||
Type type;
|
||||
try
|
||||
{
|
||||
type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Log.Error(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e));
|
||||
continue;
|
||||
}
|
||||
IPlugin plugin;
|
||||
try
|
||||
{
|
||||
plugin = (IPlugin)Activator.CreateInstance(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(new WoxPluginException(metadata.Name, "Can't create instance", e));
|
||||
continue;
|
||||
}
|
||||
PluginPair pair = new PluginPair
|
||||
{
|
||||
Plugin = plugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public static IEnumerable<PluginPair> PythonPlugins(IEnumerable<PluginMetadata> source, string pythonDirecotry)
|
||||
{
|
||||
var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Python);
|
||||
string filename;
|
||||
|
||||
if (string.IsNullOrEmpty(pythonDirecotry))
|
||||
{
|
||||
var paths = Environment.GetEnvironmentVariable(PATH);
|
||||
if (paths != null)
|
||||
{
|
||||
var pythonPaths = paths.Split(';').Where(p => p.ToLower().Contains(Python));
|
||||
if (pythonPaths.Any())
|
||||
{
|
||||
filename = PythonExecutable;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(new WoxException("Python can't be found in PATH."));
|
||||
return new List<PluginPair>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(new WoxException("Path variable is not set."));
|
||||
return new List<PluginPair>();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var path = Path.Combine(pythonDirecotry, PythonExecutable);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
filename = path;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(new WoxException("Can't find python executable in python directory"));
|
||||
return new List<PluginPair>();
|
||||
}
|
||||
}
|
||||
var plugins = metadatas.Select(metadata => new PluginPair
|
||||
{
|
||||
Plugin = new PythonPlugin(filename),
|
||||
Metadata = metadata
|
||||
});
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
internal interface IPluginLoader
|
||||
{
|
||||
IEnumerable<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas);
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent the plugin that using JsonPRC
|
||||
/// every JsonRPC plugin should has its own plugin instance
|
||||
/// </summary>
|
||||
internal abstract class JsonRPCPlugin : IPlugin
|
||||
{
|
||||
@ -22,7 +23,7 @@ namespace Wox.Core.Plugin
|
||||
/// <summary>
|
||||
/// The language this JsonRPCPlugin support
|
||||
/// </summary>
|
||||
public abstract string SupportedLanguage { get; }
|
||||
public abstract string SupportedLanguage { get; set; }
|
||||
|
||||
protected abstract string ExecuteQuery(Query query);
|
||||
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
|
||||
@ -30,7 +31,7 @@ namespace Wox.Core.Plugin
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
string output = ExecuteQuery(query);
|
||||
if (!string.IsNullOrEmpty(output))
|
||||
if (!String.IsNullOrEmpty(output))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -46,7 +47,7 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
if (result1.JsonRPCAction == null) return false;
|
||||
|
||||
if (!string.IsNullOrEmpty(result1.JsonRPCAction.Method))
|
||||
if (!String.IsNullOrEmpty(result1.JsonRPCAction.Method))
|
||||
{
|
||||
if (result1.JsonRPCAction.Method.StartsWith("Wox."))
|
||||
{
|
||||
@ -59,7 +60,7 @@ namespace Wox.Core.Plugin
|
||||
string actionReponse = ExecuteCallback(result1.JsonRPCAction);
|
||||
JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject<JsonRPCRequestModel>(actionReponse);
|
||||
if (jsonRpcRequestModel != null
|
||||
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
|
||||
&& !String.IsNullOrEmpty(jsonRpcRequestModel.Method)
|
||||
&& jsonRpcRequestModel.Method.StartsWith("Wox."))
|
||||
{
|
||||
ExecuteWoxAPI(jsonRpcRequestModel.Method.Substring(4), jsonRpcRequestModel.Parameters);
|
||||
@ -125,7 +126,7 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
using (Process process = Process.Start(startInfo))
|
||||
{
|
||||
if (process != null)
|
||||
if (process != null)
|
||||
{
|
||||
using (StreamReader reader = process.StandardOutput)
|
||||
{
|
||||
@ -135,12 +136,12 @@ namespace Wox.Core.Plugin
|
||||
MessageBox.Show(new Form { TopMost = true }, result.Substring(6));
|
||||
return "";
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
if (String.IsNullOrEmpty(result))
|
||||
{
|
||||
using (StreamReader errorReader = process.StandardError)
|
||||
{
|
||||
string error = errorReader.ReadToEnd();
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
if (!String.IsNullOrEmpty(error))
|
||||
{
|
||||
throw new WoxJsonRPCException(error);
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
internal class JsonRPCPluginLoader<T> : IPluginLoader where T : JsonRPCPlugin, new()
|
||||
{
|
||||
public IEnumerable<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
|
||||
{
|
||||
T jsonRPCPlugin = new T();
|
||||
List<PluginMetadata> jsonRPCPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == jsonRPCPlugin.SupportedLanguage.ToUpper()).ToList();
|
||||
|
||||
return jsonRPCPluginMetadatas.Select(metadata => new PluginPair
|
||||
{
|
||||
Plugin = new T(), //every JsonRPC plugin should has its own plugin instance
|
||||
Metadata = metadata
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -25,13 +25,11 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
|
||||
public static List<PluginPair> AllPlugins { get; private set; }
|
||||
|
||||
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
|
||||
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
|
||||
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
|
||||
public static IPublicAPI API { private set; get; }
|
||||
private static PluginsSettings _settings;
|
||||
|
||||
private static readonly string[] Directories = {Infrastructure.Wox.PreinstalledDirectory, Infrastructure.Wox.UserDirectory };
|
||||
|
||||
@ -57,12 +55,15 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitializePlugins(IPublicAPI api)
|
||||
public static void InitializePlugins(IPublicAPI api, PluginsSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
||||
var metadatas = PluginConfig.Parse(Directories);
|
||||
var plugins1 = new CSharpPluginLoader().LoadPlugin(metadatas);
|
||||
var plugins2 = new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas);
|
||||
var plugins1 = PluginsLoader.CSharpPlugins(metadatas);
|
||||
var plugins2 = PluginsLoader.PythonPlugins(metadatas, _settings.PythonDirectory);
|
||||
AllPlugins = plugins1.Concat(plugins2).ToList();
|
||||
_settings.UpdatePluginSettings(AllPlugins);
|
||||
|
||||
//load plugin i18n languages
|
||||
ResourceMerger.UpdatePluginLanguages();
|
||||
|
@ -1,37 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
internal class PythonPlugin : JsonRPCPlugin
|
||||
{
|
||||
private static readonly string PythonHome = Path.Combine(Infrastructure.Wox.ProgramPath, "PythonHome");
|
||||
private readonly ProcessStartInfo _startInfo;
|
||||
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
|
||||
|
||||
public override string SupportedLanguage => AllowedLanguage.Python;
|
||||
|
||||
public PythonPlugin()
|
||||
public PythonPlugin(string filename)
|
||||
{
|
||||
_startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = @"C:\Program Files\Python 3.5\pythonw.exe",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
};
|
||||
string additionalPythonPath = $"{Path.Combine(PythonHome, "DLLs")};{Path.Combine(PythonHome, "Lib", "site-packages")}";
|
||||
if (!_startInfo.EnvironmentVariables.ContainsKey("PYTHONPATH"))
|
||||
{
|
||||
|
||||
_startInfo.EnvironmentVariables.Add("PYTHONPATH", additionalPythonPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_startInfo.EnvironmentVariables["PYTHONPATH"] = additionalPythonPath;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string ExecuteQuery(Query query)
|
||||
@ -39,11 +27,10 @@ namespace Wox.Core.Plugin
|
||||
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
|
||||
{
|
||||
Method = "query",
|
||||
Parameters = new object[] { query.GetAllRemainingParameter() },
|
||||
Parameters = new object[] { query.Search },
|
||||
HttpProxy = HttpProxy.Instance
|
||||
};
|
||||
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
||||
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
||||
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
||||
|
||||
return Execute(_startInfo);
|
||||
@ -51,7 +38,6 @@ namespace Wox.Core.Plugin
|
||||
|
||||
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
||||
{
|
||||
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
||||
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
|
||||
return Execute(_startInfo);
|
||||
}
|
||||
|
@ -1,16 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UserSettings
|
||||
{
|
||||
public class PluginsSettings
|
||||
{
|
||||
public string PythonDirectory { get; set; }
|
||||
public Dictionary<string, Plugin> Plugins { get; set; } = new Dictionary<string, Plugin>();
|
||||
|
||||
public class PluginSettings
|
||||
public void UpdatePluginSettings(List<PluginPair> plugins)
|
||||
{
|
||||
var metadatas = plugins.Select(p => p.Metadata);
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
if (Plugins.ContainsKey(metadata.ID))
|
||||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
if (settings.ActionKeywords?.Count > 0)
|
||||
{
|
||||
metadata.ActionKeywords = settings.ActionKeywords;
|
||||
metadata.ActionKeyword = settings.ActionKeywords[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugins[metadata.ID] = new Plugin
|
||||
{
|
||||
ID = metadata.ID,
|
||||
Name = metadata.Name,
|
||||
ActionKeywords = metadata.ActionKeywords,
|
||||
Disabled = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateActionKeyword(PluginMetadata metadata)
|
||||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
settings.ActionKeywords = metadata.ActionKeywords;
|
||||
}
|
||||
}
|
||||
public class Plugin
|
||||
{
|
||||
public string ID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<string> ActionKeywords { get; set; }
|
||||
|
||||
public bool Disabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@ -31,7 +29,7 @@ namespace Wox.Core.UserSettings
|
||||
|
||||
// Order defaults to 0 or -1, so 1 will let this property appear last
|
||||
[JsonProperty(Order = 1)]
|
||||
public Dictionary<string, PluginSettings> PluginSettings { get; set; } = new Dictionary<string, PluginSettings>();
|
||||
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
|
||||
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new List<CustomPluginHotkey>();
|
||||
|
||||
[Obsolete]
|
||||
@ -54,61 +52,9 @@ namespace Wox.Core.UserSettings
|
||||
public int ProxyPort { get; set; }
|
||||
public string ProxyUserName { get; set; }
|
||||
public string ProxyPassword { get; set; }
|
||||
|
||||
public void UpdatePluginSettings()
|
||||
{
|
||||
var metadatas = PluginManager.AllPlugins.Select(p => p.Metadata);
|
||||
if (PluginSettings == null)
|
||||
{
|
||||
var configs = new Dictionary<string, PluginSettings>();
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
addPluginMetadata(configs, metadata);
|
||||
}
|
||||
PluginSettings = configs;
|
||||
}
|
||||
else
|
||||
{
|
||||
var configs = PluginSettings;
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
if (configs.ContainsKey(metadata.ID))
|
||||
{
|
||||
var config = configs[metadata.ID];
|
||||
if (config.ActionKeywords?.Count > 0)
|
||||
{
|
||||
metadata.ActionKeywords = config.ActionKeywords;
|
||||
metadata.ActionKeyword = config.ActionKeywords[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addPluginMetadata(configs, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addPluginMetadata(Dictionary<string, PluginSettings> configs, PluginMetadata metadata)
|
||||
{
|
||||
configs[metadata.ID] = new PluginSettings
|
||||
{
|
||||
ID = metadata.ID,
|
||||
Name = metadata.Name,
|
||||
ActionKeywords = metadata.ActionKeywords,
|
||||
Disabled = false
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateActionKeyword(PluginMetadata metadata)
|
||||
{
|
||||
var config = PluginSettings[metadata.ID];
|
||||
config.ActionKeywords = metadata.ActionKeywords;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public enum OpacityMode
|
||||
{
|
||||
Normal = 0,
|
||||
|
@ -78,9 +78,7 @@
|
||||
<Compile Include="Resource\ResourceMerger.cs" />
|
||||
<Compile Include="Plugin\PluginInstaller.cs" />
|
||||
<Compile Include="Plugin\JsonRPCPlugin.cs" />
|
||||
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
|
||||
<Compile Include="Plugin\CSharpPluginLoader.cs" />
|
||||
<Compile Include="Plugin\IPluginLoader.cs" />
|
||||
<Compile Include="Plugin\JsonPRCModel.cs" />
|
||||
<Compile Include="Plugin\PluginConfig.cs" />
|
||||
<Compile Include="Plugin\PluginManager.cs" />
|
||||
|
@ -50,7 +50,7 @@ namespace Wox
|
||||
return;
|
||||
}
|
||||
// update persistant data
|
||||
_settings.UpdateActionKeyword(_plugin.Metadata);
|
||||
_settings.PluginSettings.UpdateActionKeyword(_plugin.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
Close();
|
||||
|
@ -42,10 +42,10 @@ namespace Wox
|
||||
ImageLoader.PreloadImages();
|
||||
|
||||
MainViewModel mainVM = new MainViewModel();
|
||||
var pluginsSettings = mainVM._settings.PluginSettings;
|
||||
API = new PublicAPIInstance(mainVM, mainVM._settings);
|
||||
PluginManager.InitializePlugins(API);
|
||||
PluginManager.InitializePlugins(API, pluginsSettings);
|
||||
|
||||
mainVM._settings.UpdatePluginSettings();
|
||||
|
||||
Window = new MainWindow(mainVM._settings, mainVM);
|
||||
NotifyIconManager notifyIconManager = new NotifyIconManager(API);
|
||||
|
@ -24,7 +24,8 @@
|
||||
<system:String x:Key="language">Sprache</system:String>
|
||||
<system:String x:Key="maxShowResults">Maximale Anzahl Ergebnisse</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignoriere Tastenkombination wenn Fenster im Vollbildmodus ist</system:String>
|
||||
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Plugin</system:String>
|
||||
<system:String x:Key="browserMorePlugins">Suche weitere Plugins</system:String>
|
||||
|
@ -24,6 +24,9 @@
|
||||
<system:String x:Key="language">Language</system:String>
|
||||
<system:String x:Key="maxShowResults">Maximum show results</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignore hotkeys if window is fullscreen</system:String>
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
<system:String x:Key="selectPythonDirectory">Select</system:String>
|
||||
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Plugin</system:String>
|
||||
|
@ -24,7 +24,8 @@
|
||||
<system:String x:Key="language">Langue</system:String>
|
||||
<system:String x:Key="maxShowResults">Résultats à afficher</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignore les raccourcis lorsqu'une application est en plein écran</system:String>
|
||||
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Modules</system:String>
|
||||
<system:String x:Key="browserMorePlugins">Trouver plus de modules</system:String>
|
||||
|
@ -24,6 +24,8 @@
|
||||
<system:String x:Key="language">言語</system:String>
|
||||
<system:String x:Key="maxShowResults">結果の最大表示件数</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">ウィンドウがフルスクリーン時にホットキーを無効にする</system:String>
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">プラグイン</system:String>
|
||||
|
@ -24,7 +24,8 @@
|
||||
<system:String x:Key="language">Язык</system:String>
|
||||
<system:String x:Key="maxShowResults">Максимальное количество результатов</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">Игнорировать горячие клавиши, если окно в полноэкранном режиме</system:String>
|
||||
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Плагины</system:String>
|
||||
<system:String x:Key="browserMorePlugins">Найти больше плагинов</system:String>
|
||||
|
@ -24,6 +24,7 @@
|
||||
<system:String x:Key="language">语言</system:String>
|
||||
<system:String x:Key="maxShowResults">最大结果显示个数</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">全屏模式下忽略热键</system:String>
|
||||
<system:String x:Key="pythonDirectory">Python 路径</system:String>
|
||||
|
||||
<!--设置,插件-->
|
||||
<system:String x:Key="plugin">插件</system:String>
|
||||
|
@ -24,6 +24,7 @@
|
||||
<system:String x:Key="language">語言</system:String>
|
||||
<system:String x:Key="maxShowResults">最大結果顯示個數</system:String>
|
||||
<system:String x:Key="ignoreHotkeysOnFullscreen">全屏模式下忽略熱鍵</system:String>
|
||||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
|
||||
<!--設置,插件-->
|
||||
<system:String x:Key="plugin">插件</system:String>
|
||||
|
@ -45,6 +45,11 @@
|
||||
<TextBlock Text="{DynamicResource maxShowResults}" />
|
||||
<ComboBox Margin="10 0 0 0" Width="45" Name="comboMaxResultsToShow" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{DynamicResource pythonDirectory}" Margin="10"/>
|
||||
<TextBox Width="300" Margin="10" x:Name="PythonDirectory" />
|
||||
<Button Click="SelectPythonDirectoryOnClick" Content="{DynamicResource selectPythonDirectory}" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="{DynamicResource plugin}" x:Name="tabPlugin">
|
||||
@ -280,7 +285,7 @@
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="{DynamicResource proxy}">
|
||||
<TabItem Header="{DynamicResource proxy}" Height="22" VerticalAlignment="Top">
|
||||
<StackPanel>
|
||||
<CheckBox x:Name="cbEnableProxy" Margin="10">
|
||||
<TextBlock Text="{DynamicResource enableProxy}" />
|
||||
|
@ -7,6 +7,7 @@ using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
@ -23,6 +24,12 @@ using Wox.Infrastructure.Image;
|
||||
using Wox.Plugin;
|
||||
using Wox.ViewModel;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
using CheckBox = System.Windows.Controls.CheckBox;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
using Cursors = System.Windows.Input.Cursors;
|
||||
using HorizontalAlignment = System.Windows.HorizontalAlignment;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Wox
|
||||
@ -239,6 +246,30 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectPythonDirectoryOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new FolderBrowserDialog {RootFolder = Environment.SpecialFolder.ProgramFiles};
|
||||
|
||||
var result = dlg.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
string pythonDirectory = dlg.SelectedPath;
|
||||
if (!string.IsNullOrEmpty(pythonDirectory))
|
||||
{
|
||||
var pythonPath = Path.Combine(pythonDirectory, PluginsLoader.PythonExecutable);
|
||||
if (File.Exists(pythonPath))
|
||||
{
|
||||
PythonDirectory.Text = pythonDirectory;
|
||||
_settings.PluginSettings.PythonDirectory = pythonDirectory;
|
||||
MessageBox.Show("Remember to restart Wox use new Python path");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Can't find python in given directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Hotkey
|
||||
@ -553,7 +584,7 @@ namespace Wox
|
||||
pluginId = pair.Metadata.ID;
|
||||
pluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath);
|
||||
|
||||
var customizedPluginConfig = _settings.PluginSettings[pluginId];
|
||||
var customizedPluginConfig = _settings.PluginSettings.Plugins[pluginId];
|
||||
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
|
||||
|
||||
PluginContentPanel.Content = null;
|
||||
@ -571,7 +602,7 @@ namespace Wox
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(pair, e.OldActionKeyword, e.NewActionKeyword);
|
||||
// update persistant data
|
||||
_settings.UpdateActionKeyword(pair.Metadata);
|
||||
_settings.PluginSettings.UpdateActionKeyword(pair.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
};
|
||||
@ -596,7 +627,7 @@ namespace Wox
|
||||
if (pair != null)
|
||||
{
|
||||
var id = pair.Metadata.ID;
|
||||
var customizedPluginConfig = _settings.PluginSettings[id];
|
||||
var customizedPluginConfig = _settings.PluginSettings.Plugins[id];
|
||||
if (customizedPluginConfig.Disabled)
|
||||
{
|
||||
PluginManager.DisablePlugin(pair);
|
||||
@ -804,5 +835,6 @@ namespace Wox
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ namespace Wox.ViewModel
|
||||
var plugins = PluginManager.ValidPluginsForQuery(query);
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
var config = _settings.PluginSettings[plugin.Metadata.ID];
|
||||
var config = _settings.PluginSettings.Plugins[plugin.Metadata.ID];
|
||||
if (!config.Disabled)
|
||||
{
|
||||
Task.Factory.StartNew(() =>
|
||||
|
@ -384,7 +384,7 @@
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\
|
||||
xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\
|
||||
xcopy /Y /D /E $(SolutionDir)PythonHome\* $(TargetDir)PythonHome\
|
||||
xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\*
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user