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