mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-08 01:52:52 +08: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{
|
try{
|
||||||
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance;
|
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();
|
Py_Initialize();
|
||||||
|
|
||||||
// Create GIL/enable threads
|
// Create GIL/enable threads
|
||||||
PyEval_InitThreads();
|
//PyEval_InitThreads();
|
||||||
|
|
||||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
//PyGILState_STATE gstate = PyGILState_Ensure();
|
||||||
// // Get the default thread state
|
// // Get the default thread state
|
||||||
// PyThreadState* state = PyThreadState_Get();
|
// PyThreadState* state = PyThreadState_Get();
|
||||||
// // Once in each thread
|
// // 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
|
// 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);
|
char * str_ret = PyString_AsString(pValue);
|
||||||
|
|
||||||
PyGILState_Release(gstate);
|
//PyGILState_Release(gstate);
|
||||||
//PyEval_SaveThread();
|
//PyEval_SaveThread();
|
||||||
|
|
||||||
// Finish the Python Interpreter
|
// 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="Plugin.cs" />
|
||||||
<Compile Include="PluginMetadata.cs" />
|
<Compile Include="PluginMetadata.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="PythonResult.cs" />
|
||||||
<Compile Include="Query.cs" />
|
<Compile Include="Query.cs" />
|
||||||
<Compile Include="Result.cs" />
|
<Compile Include="Result.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -144,6 +144,7 @@ namespace WinAlfred
|
|||||||
|
|
||||||
case Key.Enter:
|
case Key.Enter:
|
||||||
resultCtrl.AcceptSelect();
|
resultCtrl.AcceptSelect();
|
||||||
|
HideWinAlfred();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace WinAlfred.PluginLoader
|
|||||||
private PluginMetadata metadata;
|
private PluginMetadata metadata;
|
||||||
|
|
||||||
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[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)]
|
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
private extern static void InitPythonEnv();
|
private extern static void InitPythonEnv();
|
||||||
|
|
||||||
@ -22,9 +22,16 @@ namespace WinAlfred.PluginLoader
|
|||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), query.RawQuery));
|
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery));
|
||||||
List<Result> o = JsonConvert.DeserializeObject<List<Result>>(s);
|
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
||||||
return o;
|
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()
|
public void Init()
|
||||||
|
Loading…
Reference in New Issue
Block a user