This commit is contained in:
qianlifeng
2014-01-09 22:16:19 +08:00
parent 8d931e290a
commit 935d26f956
9 changed files with 38 additions and 46 deletions

View File

@@ -7,6 +7,8 @@ class PyWinAlfred():
def query(self,key): def query(self,key):
k = key.split(" ")[1] k = key.split(" ")[1]
if not k:
return ""
r = requests.get('http://movie.douban.com/subject_search?search_text=' + k) r = requests.get('http://movie.douban.com/subject_search?search_text=' + k)
bs = BeautifulSoup(r.text) bs = BeautifulSoup(r.text)
results = [] results = []

View File

@@ -23,6 +23,8 @@ char* Exec(char* directory, char* file, char* method, char* para)
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance; PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance;
char *error; char *error;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ǰִ<C7B0>У<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ͷ<EFBFBD>PyEval_InitThreads<64><73><EFBFBD>õ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̿<DFB3><CCBF><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PyEval_ReleaseLock();
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
// Initialise the Python interpreter // Initialise the Python interpreter
@@ -97,20 +99,19 @@ char* Exec(char* directory, char* file, char* method, char* para)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char* directory = "d:\\github\\WinAlfred\\WinAlfred\\bin\\Debug\\Plugins\\p"; char* directory = "d:\\github\\WinAlfred\\Plugins\\WinAlfred.Plugin.DouBan\\";
char* file = "main"; char* file = "main";
char* method = "query"; char* method = "query";
char* para1 = "p 1"; char* para1 = "movie 1";
char* para2 = "p 2"; char* para2 = "movie 2";
char* para3 = "p 3"; char* para3 = "movie 3";
char* para4 = "p 4"; char* para4 = "movie 4";
int i = 0; int i = 0;
// <20><>ʼ<EFBFBD><CABC> // <20><>ʼ<EFBFBD><CABC>
Py_Initialize(); Py_Initialize();
// <20><>ʼ<EFBFBD><CABC><EFBFBD>߳<EFBFBD>֧<EFBFBD><D6A7> // <20><>ʼ<EFBFBD><CABC><EFBFBD>߳<EFBFBD>֧<EFBFBD><D6A7>
PyEval_InitThreads(); PyEval_InitThreads();
PyEval_ReleaseLock();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ǰִ<C7B0>У<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ͷ<EFBFBD>PyEval_InitThreads<64><73><EFBFBD>õ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̿<DFB3><CCBF><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//std::async(Exec,directory,file,method,para); //std::async(Exec,directory,file,method,para);
std::async(Exec,directory,file,method,para1); std::async(Exec,directory,file,method,para1);
std::async(Exec,directory,file,method,para2); std::async(Exec,directory,file,method,para2);

View File

@@ -9,7 +9,6 @@ extern "C" __declspec(dllexport) void InitPythonEnv()
{ {
Py_Initialize(); Py_Initialize();
PyEval_InitThreads(); PyEval_InitThreads();
PyEval_ReleaseLock();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ǰִ<C7B0>У<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ͷ<EFBFBD>PyEval_InitThreads<64><73><EFBFBD>õ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̿<DFB3><CCBF><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ǰִ<C7B0>У<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ͷ<EFBFBD>PyEval_InitThreads<64><73><EFBFBD>õ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̿<DFB3><CCBF><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} }
@@ -32,8 +31,8 @@ char* Exec(char* directory, char* file, char* method, char* para)
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance; PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance;
char *error; char *error;
PyEval_ReleaseLock();
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
// Build the name object // Build the name object
PyObject *path = PySys_GetObject("path"); PyObject *path = PySys_GetObject("path");
PyList_Append(path, PyString_FromString(directory)); PyList_Append(path, PyString_FromString(directory));
@@ -91,14 +90,13 @@ char* Exec(char* directory, char* file, char* method, char* para)
//PyErr_Clear(); //PyErr_Clear();
PyGILState_Release(gstate); PyGILState_Release(gstate);
return str_ret; return str_ret;
} }
extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, char* method, char* para) extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, char* method, char* para)
{ {
//PyEval_ReleaseLock();
char* s = Exec(directory,file,method,para); char* s = Exec(directory,file,method,para);
PyGILState_Ensure();
return s; return s;
//auto future = std::async(Exec,directory,file,method,para); //auto future = std::async(Exec,directory,file,method,para);
//return future.get(); //return future.get();

View File

@@ -104,7 +104,8 @@ Global
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Win32.ActiveCfg = Release|Any CPU {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Win32.ActiveCfg = Release|Any CPU
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x64.ActiveCfg = Release|Any CPU {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x64.ActiveCfg = Release|Any CPU
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x86.ActiveCfg = Release|Any CPU {353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x86.ActiveCfg = Release|Any CPU
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Any CPU.ActiveCfg = Debug|Win32 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Any CPU.ActiveCfg = Debug|x64
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Any CPU.Build.0 = Debug|x64
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.ActiveCfg = Debug|Win32 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -122,7 +123,7 @@ Global
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.Build.0 = Release|x64 {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.ActiveCfg = Release|Win32
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.Build.0 = 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|Any CPU.ActiveCfg = Debug|x64
{05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {05D72D92-4010-4F92-A147-906930241573}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{05D72D92-4010-4F92-A147-906930241573}.Debug|Win32.ActiveCfg = Debug|Win32 {05D72D92-4010-4F92-A147-906930241573}.Debug|Win32.ActiveCfg = Debug|Win32

View File

@@ -17,4 +17,4 @@
<appender-ref ref="LogFileAppender"/> <appender-ref ref="LogFileAppender"/>
</root> </root>
</log4net> </log4net>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

View File

@@ -8,7 +8,6 @@ using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Shapes; using System.Windows.Shapes;
using IWshRuntimeLibrary;
using Microsoft.Win32; using Microsoft.Win32;
using WinAlfred.Commands; using WinAlfred.Commands;
using WinAlfred.Helper; using WinAlfred.Helper;
@@ -153,21 +152,21 @@ namespace WinAlfred
private void SetAutoStart(bool IsAtuoRun) private void SetAutoStart(bool IsAtuoRun)
{ {
string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; //string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk";
if (IsAtuoRun) //if (IsAtuoRun)
{ //{
WshShell shell = new WshShell(); // WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath); // IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath);
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; // shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
shortcut.WorkingDirectory = Environment.CurrentDirectory; // shortcut.WorkingDirectory = Environment.CurrentDirectory;
shortcut.WindowStyle = 1; //normal window // shortcut.WindowStyle = 1; //normal window
shortcut.Description = "WinAlfred"; // shortcut.Description = "WinAlfred";
shortcut.Save(); // shortcut.Save();
} //}
else //else
{ //{
System.IO.File.Delete(LnkPath); // System.IO.File.Delete(LnkPath);
} //}
} }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)

View File

@@ -19,7 +19,9 @@ namespace WinAlfred.PluginLoader
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin)) foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{ {
IPlugin plugin1 = plugin; IPlugin plugin1 = plugin;
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext() //ThreadPool.QueueUserWorkItem(o =>);
plugin1.Init(new PluginInitContext()
{ {
Plugins = plugins, Plugins = plugins,
ChangeQuery = s => window.ChangeQuery(s), ChangeQuery = s => window.ChangeQuery(s),
@@ -27,7 +29,7 @@ namespace WinAlfred.PluginLoader
HideApp = window.HideApp, HideApp = window.HideApp,
ShowApp = window.ShowApp, ShowApp = window.ShowApp,
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath) ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
})); });
} }
} }

View File

@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WinAlfred</RootNamespace> <RootNamespace>WinAlfred</RootNamespace>
<AssemblyName>WinAlfred</AssemblyName> <AssemblyName>WinAlfred</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@@ -191,17 +191,6 @@
<ItemGroup> <ItemGroup>
<Resource Include="app.ico" /> <Resource Include="app.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup> <PropertyGroup>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" /> <package id="log4net" version="2.0.3" targetFramework="net35" requireReinstallation="True" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" requireReinstallation="True" />
</packages> </packages>