mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
add pywinalfred test project
This commit is contained in:
parent
5893564f46
commit
188e7910dd
155
PyWinAlfred.Test/PyWinAlfred.Test.vcxproj
Normal file
155
PyWinAlfred.Test/PyWinAlfred.Test.vcxproj
Normal file
@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{05D72D92-4010-4F92-A147-906930241573}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>PyWinAlfredTest</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Python27\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Python27\libs;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Python27\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Python27\libs;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Source.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
22
PyWinAlfred.Test/PyWinAlfred.Test.vcxproj.filters
Normal file
22
PyWinAlfred.Test/PyWinAlfred.Test.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Source.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
124
PyWinAlfred.Test/Source.cpp
Normal file
124
PyWinAlfred.Test/Source.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
#include "Python.h"
|
||||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
char* GetErrorMessage()
|
||||
{
|
||||
char *pStrErrorMessage = NULL;
|
||||
|
||||
if(PyErr_Occurred()){
|
||||
PyObject *ptype, *pvalue, *ptraceback;
|
||||
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
|
||||
pStrErrorMessage = PyString_AsString(pvalue);
|
||||
}
|
||||
|
||||
return pStrErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
char* Exec(char* directory, char* file, char* method, char* para)
|
||||
{
|
||||
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance;
|
||||
char *error;
|
||||
|
||||
//PyThreadState* global_state = PyThreadState_Get();
|
||||
//PyThreadState* ts = Py_NewInterpreter();
|
||||
//PyThreadState_Swap(ts);
|
||||
// Initialise the Python interpreter
|
||||
|
||||
// Create GIL/enable threads
|
||||
|
||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||
// // Get the default thread state
|
||||
// PyThreadState* state = PyThreadState_Get();
|
||||
// // Once in each thread
|
||||
//PyThreadState* stateForNewThread = PyThreadState_New(state->interp);
|
||||
//PyEval_RestoreThread(stateForNewThread);
|
||||
|
||||
// Build the name object
|
||||
PyObject *sys = PyImport_ImportModule("sys");
|
||||
PyObject *path = PyObject_GetAttrString(sys, "path");
|
||||
PyList_Append(path, PyString_FromString(directory));
|
||||
|
||||
pName = PyString_FromString(file);
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(error, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
pModule = PyImport_Import(pName);
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(err, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
pDict = PyModule_GetDict(pModule);
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(err, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
pClass = PyDict_GetItemString(pDict,"PyWinAlfred");
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(err, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
pInstance = PyObject_CallObject(pClass, NULL);
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(err, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Call a method of the class with two parameters
|
||||
pValue = PyObject_CallMethod(pInstance,method, "(s)",para);
|
||||
error = GetErrorMessage();
|
||||
if(error != NULL){
|
||||
char* err =new char[5000]();
|
||||
sprintf(err, "%s:%s","PYTHONERROR",error);
|
||||
return err;
|
||||
}
|
||||
|
||||
char * str_ret = PyString_AsString(pValue);
|
||||
|
||||
//PyEval_SaveThread();
|
||||
|
||||
// Finish the Python Interpreter
|
||||
|
||||
//PyErr_Clear();
|
||||
//Py_EndInterpreter(ts);
|
||||
//PyThreadState_Swap(global_state);
|
||||
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
return str_ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char* directory = "d:\\Personal\\WinAlfred\\WinAlfred\\bin\\Debug\\Plugins\\p4pperson\\";
|
||||
char* file = "main";
|
||||
char* method = "query";
|
||||
char* para = "p q";
|
||||
Py_Initialize();
|
||||
PyEval_InitThreads();
|
||||
for(int i=0;i++;i<10){
|
||||
auto future = std::async(Exec,directory,file,method,para);
|
||||
printf("%s",future.get());
|
||||
}
|
||||
Py_Finalize();
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
@ -3,8 +3,11 @@
|
||||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
int i = 0;
|
||||
|
||||
extern "C" __declspec(dllexport) void InitPythonEnv()
|
||||
{
|
||||
i++;
|
||||
Py_Initialize();
|
||||
PyEval_InitThreads();
|
||||
}
|
||||
@ -27,6 +30,7 @@ char* Exec(char* directory, char* file, char* method, char* para)
|
||||
{
|
||||
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance;
|
||||
char *error;
|
||||
i++;
|
||||
|
||||
PyThreadState* global_state = PyThreadState_Get();
|
||||
PyThreadState* ts = Py_NewInterpreter();
|
||||
|
@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinA
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred", "PyWinAlfred\PyWinAlfred.vcxproj", "{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred.Test", "PyWinAlfred.Test\PyWinAlfred.Test.vcxproj", "{05D72D92-4010-4F92-A147-906930241573}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -104,6 +106,22 @@ Global
|
||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.Build.0 = Release|x64
|
||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.Build.0 = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.Build.0 = Debug|x64
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Debug|x86.Build.0 = Debug|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|Win32.Build.0 = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|x64.ActiveCfg = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|x86.ActiveCfg = Release|Win32
|
||||
{05D72D92-4010-4F92-A147-906930241573}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user