mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 00:03:48 +00:00
Change python plugin interface.
This commit is contained in:
parent
a0507bd14d
commit
26294a5742
@ -27,7 +27,7 @@ def query(key):
|
||||
pass
|
||||
return json.dumps(results)
|
||||
|
||||
def killProcess(pid):
|
||||
def killProcess(context,pid):
|
||||
p = psutil.Process(int(pid))
|
||||
if p:
|
||||
p.kill()
|
||||
|
@ -27,7 +27,7 @@ def query(key):
|
||||
results.append(res)
|
||||
return json.dumps(results)
|
||||
|
||||
def openUrl(url):
|
||||
def openUrl(context,url):
|
||||
webbrowser.open(url)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
14
Wox/Helper/WoxPythonException.cs
Normal file
14
Wox/Helper/WoxPythonException.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Helper
|
||||
{
|
||||
public class WoxPythonException : WoxException
|
||||
{
|
||||
public WoxPythonException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Documents;
|
||||
using Newtonsoft.Json;
|
||||
using Python.Runtime;
|
||||
using Wox.Helper;
|
||||
@ -13,7 +10,6 @@ namespace Wox.PluginLoader
|
||||
{
|
||||
public class PythonPluginWrapper : IPlugin
|
||||
{
|
||||
|
||||
private PluginMetadata metadata;
|
||||
private string moduleName;
|
||||
|
||||
@ -50,7 +46,7 @@ namespace Wox.PluginLoader
|
||||
{
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
throw new WoxPythonException(e.Message);
|
||||
}
|
||||
#endif
|
||||
Log.Error(string.Format("Python Plugin {0} query failed: {1}", metadata.Name, e.Message));
|
||||
@ -82,15 +78,29 @@ namespace Wox.PluginLoader
|
||||
if (module == null)
|
||||
{
|
||||
string error = string.Format("Python Invoke failed: {0} doesn't has module {1}",
|
||||
metadata.ExecuteFilePath,moduleName);
|
||||
metadata.ExecuteFilePath, moduleName);
|
||||
Log.Error(error);
|
||||
return json;
|
||||
}
|
||||
|
||||
if (module.HasAttr(func))
|
||||
{
|
||||
PyObject res = paras.Length > 0 ? module.InvokeMethod(func, paras) : module.InvokeMethod(func);
|
||||
json = Runtime.GetManagedString(res.Handle);
|
||||
try
|
||||
{
|
||||
PyObject res = paras.Length > 0 ? module.InvokeMethod(func, paras) : module.InvokeMethod(func);
|
||||
json = Runtime.GetManagedString(res.Handle);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string error = string.Format("Python Invoke failed: {0}", e.Message);
|
||||
Log.Error(error);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new WoxPythonException(error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -99,7 +109,7 @@ namespace Wox.PluginLoader
|
||||
Log.Error(error);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new ArgumentException(error);
|
||||
throw new WoxPythonException(error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -132,6 +132,7 @@
|
||||
<Compile Include="Helper\Log.cs" />
|
||||
<Compile Include="Helper\PluginInstaller.cs" />
|
||||
<Compile Include="Helper\WoxException.cs" />
|
||||
<Compile Include="Helper\WoxPythonException.cs" />
|
||||
<Compile Include="HotkeyControl.xaml.cs">
|
||||
<DependentUpon>HotkeyControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
Loading…
Reference in New Issue
Block a user