diff --git a/PyWinAlfred/Main.cpp b/PyWinAlfred/Main.cpp index 4e923cb76c..5934d9f01a 100644 --- a/PyWinAlfred/Main.cpp +++ b/PyWinAlfred/Main.cpp @@ -7,7 +7,7 @@ extern "C" __declspec(dllexport) void InitPythonEnv() } -extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, char* query) +extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, char* method, char* para) { try{ PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance; @@ -16,9 +16,9 @@ extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, c Py_Initialize(); // Create GIL/enable threads - PyEval_InitThreads(); + //PyEval_InitThreads(); - PyGILState_STATE gstate = PyGILState_Ensure(); + //PyGILState_STATE gstate = PyGILState_Ensure(); // // Get the default thread state // PyThreadState* state = PyThreadState_Get(); // // Once in each thread @@ -52,10 +52,10 @@ extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, c } // Call a method of the class with two parameters - pValue = PyObject_CallMethod(pInstance,"query", "(s)",query); + pValue = PyObject_CallMethod(pInstance,method, "(s)",para); char * str_ret = PyString_AsString(pValue); - PyGILState_Release(gstate); + //PyGILState_Release(gstate); //PyEval_SaveThread(); // Finish the Python Interpreter diff --git a/WinAlfred.Plugin/PythonResult.cs b/WinAlfred.Plugin/PythonResult.cs new file mode 100644 index 0000000000..45c4a844eb --- /dev/null +++ b/WinAlfred.Plugin/PythonResult.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WinAlfred.Plugin +{ + public class PythonResult : Result + { + public string ActionName { get; set; } + public string ActionPara { get; set; } + } +} diff --git a/WinAlfred.Plugin/WinAlfred.Plugin.csproj b/WinAlfred.Plugin/WinAlfred.Plugin.csproj index dae34c2341..e0b1b3869d 100644 --- a/WinAlfred.Plugin/WinAlfred.Plugin.csproj +++ b/WinAlfred.Plugin/WinAlfred.Plugin.csproj @@ -62,6 +62,7 @@ + diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 260ea04791..7eea9d3832 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -144,6 +144,7 @@ namespace WinAlfred case Key.Enter: resultCtrl.AcceptSelect(); + HideWinAlfred(); e.Handled = true; break; } diff --git a/WinAlfred/PluginLoader/PythonPluginWrapper.cs b/WinAlfred/PluginLoader/PythonPluginWrapper.cs index 4040476e45..f87550aad9 100644 --- a/WinAlfred/PluginLoader/PythonPluginWrapper.cs +++ b/WinAlfred/PluginLoader/PythonPluginWrapper.cs @@ -11,7 +11,7 @@ namespace WinAlfred.PluginLoader private PluginMetadata metadata; [DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - private extern static IntPtr ExecPython(string directory, string file, string query); + private extern static IntPtr ExecPython(string directory, string file,string method,string para); [DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] private extern static void InitPythonEnv(); @@ -22,9 +22,16 @@ namespace WinAlfred.PluginLoader public List Query(Query query) { - string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), query.RawQuery)); - List o = JsonConvert.DeserializeObject>(s); - return o; + string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery)); + List o = JsonConvert.DeserializeObject>(s); + List r = new List(); + foreach (PythonResult pythonResult in o) + { + PythonResult ps = pythonResult; + ps.Action = () => ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),ps.ActionName,ps.ActionPara); + r.Add(ps); + } + return r; } public void Init()