mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-23 17:44:40 +00:00
UI staff
This commit is contained in:
parent
db18b0f8e2
commit
ece5cc7dd5
@ -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
|
||||
|
13
WinAlfred.Plugin/PythonResult.cs
Normal file
13
WinAlfred.Plugin/PythonResult.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
@ -62,6 +62,7 @@
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="PluginMetadata.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PythonResult.cs" />
|
||||
<Compile Include="Query.cs" />
|
||||
<Compile Include="Result.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -144,6 +144,7 @@ namespace WinAlfred
|
||||
|
||||
case Key.Enter:
|
||||
resultCtrl.AcceptSelect();
|
||||
HideWinAlfred();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
|
@ -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<Result> Query(Query query)
|
||||
{
|
||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), query.RawQuery));
|
||||
List<Result> o = JsonConvert.DeserializeObject<List<Result>>(s);
|
||||
return o;
|
||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery));
|
||||
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
||||
List<Result> r = new List<Result>();
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user