From 87225e64faf906255d9d0fbd8839f80617dc6ad1 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Mon, 23 Dec 2013 23:53:38 +0800 Subject: [PATCH] regular update --- Plugins/WinAlfred.Plugin.DouBan/main.py | 20 +++++- PyWinAlfred/Main.cpp | 8 ++- WinAlfred.Plugin/PluginMetadata.cs | 3 +- WinAlfred.Plugin/Result.cs | 1 + WinAlfred.sln | 66 ++++++++++++++++++ WinAlfred/App.config | 16 ++--- WinAlfred/MainWindow.xaml.cs | 4 +- WinAlfred/PluginLoader/BasePluginLoader.cs | 9 +-- WinAlfred/PluginLoader/CSharpPluginLoader.cs | 2 +- WinAlfred/PluginLoader/PythonPluginWrapper.cs | 18 ++--- WinAlfred/ResultPanel.xaml | 6 +- WinAlfred/ResultPanel.xaml.cs | 9 +-- WinAlfred/WinAlfred.csproj | 15 +++- WinAlfred/app.ico | Bin 0 -> 4286 bytes WinAlfred/packages.config | 1 + 15 files changed, 136 insertions(+), 42 deletions(-) create mode 100644 WinAlfred/app.ico diff --git a/Plugins/WinAlfred.Plugin.DouBan/main.py b/Plugins/WinAlfred.Plugin.DouBan/main.py index 94bd01fd36..00eaf442d9 100644 --- a/Plugins/WinAlfred.Plugin.DouBan/main.py +++ b/Plugins/WinAlfred.Plugin.DouBan/main.py @@ -1,4 +1,22 @@ -import os +#encoding=utf8 +import requests +from bs4 import BeautifulSoup +import json +class PyWinAlfred(): + def query(self,key): + k = key.split(" ")[1] + r = requests.get('http://movie.douban.com/subject_search?search_text=' + k) + bs = BeautifulSoup(r.text) + results = [] + for i in bs.select(".article table .pl2 a"): + res = {} + t = i.text.strip().replace(" ","") + res["Title"] = t.replace("\\n","") + results.append(res) + return json.dumps(results) +if __name__ == "__main__": + p = PyWinAlfred() + print p.query("movie geo") diff --git a/PyWinAlfred/Main.cpp b/PyWinAlfred/Main.cpp index fbbe45c01d..7f3f8a00b1 100644 --- a/PyWinAlfred/Main.cpp +++ b/PyWinAlfred/Main.cpp @@ -1,7 +1,7 @@ #include #include "Python.h" -extern "C" __declspec(dllexport) void ExecPython(char* directory, char* file, char* query) +extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, char* query) { try{ PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pClass, *pInstance ; @@ -32,14 +32,16 @@ extern "C" __declspec(dllexport) void ExecPython(char* directory, char* file, ch else { PyErr_Print(); - return; + return "failed"; } // Call a method of the class with two parameters pValue = PyObject_CallMethod(pInstance,"query", "(s)",query); - + char * str_ret = PyString_AsString(pValue); // Finish the Python Interpreter Py_Finalize(); + + return str_ret; } catch(int& value){ PyErr_Print(); diff --git a/WinAlfred.Plugin/PluginMetadata.cs b/WinAlfred.Plugin/PluginMetadata.cs index 5238f84ad0..23d54b8c24 100644 --- a/WinAlfred.Plugin/PluginMetadata.cs +++ b/WinAlfred.Plugin/PluginMetadata.cs @@ -12,7 +12,8 @@ namespace WinAlfred.Plugin public string Version { get; set; } public string Language { get; set; } public string Description { get; set; } - public string ExecuteFile { get; set; } + public string ExecuteFilePath { get; set; } + public string ExecuteFileName { get; set; } public string PluginDirecotry { get; set; } public string ActionKeyword { get; set; } } diff --git a/WinAlfred.Plugin/Result.cs b/WinAlfred.Plugin/Result.cs index 80ae99bda3..a66b8851df 100644 --- a/WinAlfred.Plugin/Result.cs +++ b/WinAlfred.Plugin/Result.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; namespace WinAlfred.Plugin diff --git a/WinAlfred.sln b/WinAlfred.sln index cb022396d0..a478b6711d 100644 --- a/WinAlfred.sln +++ b/WinAlfred.sln @@ -13,46 +13,112 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinAlfred.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred", "PyWinAlfred\PyWinAlfred.vcxproj", "{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|Win32.ActiveCfg = Debug|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|x64.ActiveCfg = Debug|Any CPU {FF742965-9A80-41A5-B042-D6C7D3A21708}.Debug|x86.ActiveCfg = Debug|Any CPU {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|Any CPU.Build.0 = Release|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|Win32.ActiveCfg = Release|Any CPU + {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|x64.ActiveCfg = Release|Any CPU {FF742965-9A80-41A5-B042-D6C7D3A21708}.Release|x86.ActiveCfg = Release|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Win32.ActiveCfg = Debug|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|Win32.Build.0 = Debug|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|x64.ActiveCfg = Debug|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|x86.ActiveCfg = Debug|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|x86.Build.0 = Debug|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.ActiveCfg = Release|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.Build.0 = Release|Any CPU + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.Build.0 = Release|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.ActiveCfg = Release|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.Build.0 = Release|x86 + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x64.ActiveCfg = Release|Any CPU {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x86.ActiveCfg = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Any CPU.ActiveCfg = Debug|x64 {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Any CPU.Build.0 = Debug|x64 + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Win32.ActiveCfg = Debug|Any CPU + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|x64.ActiveCfg = Debug|x64 {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|x86.ActiveCfg = Debug|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|x86.Build.0 = Debug|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|Any CPU.Build.0 = Release|Any CPU + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|Win32.ActiveCfg = Release|Any CPU + {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x64.ActiveCfg = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x86.ActiveCfg = Release|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|Win32.ActiveCfg = Debug|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|x64.ActiveCfg = Debug|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Debug|x86.ActiveCfg = Debug|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Release|Any CPU.Build.0 = Release|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Release|Win32.ActiveCfg = Release|Any CPU + {E515011D-A769-418B-8761-ABE6F29827A0}.Release|x64.ActiveCfg = Release|Any CPU {E515011D-A769-418B-8761-ABE6F29827A0}.Release|x86.ActiveCfg = Release|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Win32.ActiveCfg = Debug|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x64.ActiveCfg = Debug|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|x86.ActiveCfg = Debug|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.Build.0 = Release|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Win32.ActiveCfg = Release|Any CPU + {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.ActiveCfg = Release|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.ActiveCfg = Release|Any CPU + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.Build.0 = Debug|x64 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.ActiveCfg = Debug|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.Build.0 = Debug|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x64.ActiveCfg = Debug|x64 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x64.Build.0 = Debug|x64 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x86.ActiveCfg = Debug|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x86.Build.0 = Debug|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Any CPU.ActiveCfg = Release|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Mixed Platforms.Build.0 = Release|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Win32.ActiveCfg = Release|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Win32.Build.0 = Release|Win32 + {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.ActiveCfg = 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.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinAlfred/App.config b/WinAlfred/App.config index 0383125086..e1eb5518f6 100644 --- a/WinAlfred/App.config +++ b/WinAlfred/App.config @@ -1,20 +1,20 @@ - +
- - - - + + + + - + - + - \ No newline at end of file + diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index ea1489f472..265330a070 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -91,12 +91,12 @@ namespace WinAlfred resultCtrl.SelectFirst(); } - public void HideWinAlfred() + private void HideWinAlfred() { Hide(); } - public void ShowWinAlfred() + private void ShowWinAlfred() { tbQuery.SelectAll(); Focus(); diff --git a/WinAlfred/PluginLoader/BasePluginLoader.cs b/WinAlfred/PluginLoader/BasePluginLoader.cs index dd03940731..d16042b494 100644 --- a/WinAlfred/PluginLoader/BasePluginLoader.cs +++ b/WinAlfred/PluginLoader/BasePluginLoader.cs @@ -61,8 +61,9 @@ namespace WinAlfred.PluginLoader metadata.Language = ini.GetSetting("plugin", "Language"); metadata.Version = ini.GetSetting("plugin", "Version"); metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); - metadata.ExecuteFile = AppDomain.CurrentDomain.BaseDirectory + directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); + metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory + directory + "\\"; + metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile"); if (!AllowedLanguage.IsAllowed(metadata.Language)) { @@ -76,10 +77,10 @@ namespace WinAlfred.PluginLoader #endif return null; } - if (!File.Exists(metadata.ExecuteFile)) + if (!File.Exists(metadata.ExecuteFilePath)) { - string error = string.Format("Parse ini {0} failed: ExecuteFile didn't exist {1}", iniPath, - metadata.ExecuteFile); + string error = string.Format("Parse ini {0} failed: ExecuteFilePath didn't exist {1}", iniPath, + metadata.ExecuteFilePath); Log.Error(error); #if (DEBUG) { diff --git a/WinAlfred/PluginLoader/CSharpPluginLoader.cs b/WinAlfred/PluginLoader/CSharpPluginLoader.cs index a3cc75a28e..db857a8304 100644 --- a/WinAlfred/PluginLoader/CSharpPluginLoader.cs +++ b/WinAlfred/PluginLoader/CSharpPluginLoader.cs @@ -19,7 +19,7 @@ namespace WinAlfred.PluginLoader { try { - Assembly asm = Assembly.LoadFile(metadata.ExecuteFile); + Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath); List types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof (IPlugin))).ToList(); if (types.Count == 0) { diff --git a/WinAlfred/PluginLoader/PythonPluginWrapper.cs b/WinAlfred/PluginLoader/PythonPluginWrapper.cs index 4d9ff8bef8..094b0a4a9a 100644 --- a/WinAlfred/PluginLoader/PythonPluginWrapper.cs +++ b/WinAlfred/PluginLoader/PythonPluginWrapper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using Newtonsoft.Json; using WinAlfred.Plugin; namespace WinAlfred.PluginLoader @@ -10,27 +11,18 @@ namespace WinAlfred.PluginLoader private PluginMetadata metadata; [DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public extern static void ExecPython(string directory, string file, string query); - - static PythonPluginWrapper() - { - - } + private extern static IntPtr ExecPython(string directory, string file, string query); public PythonPluginWrapper(PluginMetadata metadata) { this.metadata = metadata; } - public List Query(Query query) { - List results = new List(); - ExecPython(metadata.PluginDirecotry, metadata.ExecuteFile.Replace(".py", ""), query.RawQuery); - results.Add(new Result() - { - }); - return results; + string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), query.RawQuery)); + List o = JsonConvert.DeserializeObject>(s); + return o; } public void Init() diff --git a/WinAlfred/ResultPanel.xaml b/WinAlfred/ResultPanel.xaml index 620f156891..125ab2c053 100644 --- a/WinAlfred/ResultPanel.xaml +++ b/WinAlfred/ResultPanel.xaml @@ -5,7 +5,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + + - + + diff --git a/WinAlfred/ResultPanel.xaml.cs b/WinAlfred/ResultPanel.xaml.cs index fe07367545..6f6d5d3b81 100644 --- a/WinAlfred/ResultPanel.xaml.cs +++ b/WinAlfred/ResultPanel.xaml.cs @@ -4,9 +4,6 @@ using WinAlfred.Plugin; namespace WinAlfred { - /// - /// Result.xaml 的交互逻辑 - /// public partial class ResultPanel : UserControl { public delegate void ResultItemsChanged(); @@ -26,7 +23,7 @@ namespace WinAlfred { Result result = results[i]; ResultItem control = new ResultItem(result); - control.SetIndex(i+1); + control.SetIndex(i + 1); pnlContainer.Children.Add(control); } @@ -39,7 +36,7 @@ namespace WinAlfred if (resultItem != null) resultItemHeight = resultItem.ActualHeight; } - Height = pnlContainer.Height = results.Count * resultItemHeight; + pnlContainer.Height = results.Count * resultItemHeight; OnResultItemChangedEvent(); } @@ -118,4 +115,4 @@ namespace WinAlfred InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index d3f4c70f67..1397806efd 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -15,6 +15,7 @@ 4 ..\ true + AnyCPU @@ -35,14 +36,21 @@ prompt 4 + + app.ico + ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + ..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll + + @@ -110,7 +118,9 @@ Resources.Designer.cs - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs @@ -135,6 +145,9 @@ + + +