regular update

This commit is contained in:
qianlifeng 2013-12-23 23:53:38 +08:00
parent fffb97ea8d
commit 87225e64fa
15 changed files with 136 additions and 42 deletions

View File

@ -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")

View File

@ -1,7 +1,7 @@
#include <tchar.h>
#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();

View File

@ -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; }
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace WinAlfred.Plugin

View File

@ -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

View File

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd-HH:mm:ss" />
<file value="log.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd-HH:mm:ss"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="Date%date Level%-5level Msg%message%newline" />
<conversionPattern value="Date%date Level%-5level Msg%message%newline"/>
</layout>
</appender>
<root>
<appender-ref ref="LogFileAppender" />
<appender-ref ref="LogFileAppender"/>
</root>
</log4net>
</configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

View File

@ -91,12 +91,12 @@ namespace WinAlfred
resultCtrl.SelectFirst();
}
public void HideWinAlfred()
private void HideWinAlfred()
{
Hide();
}
public void ShowWinAlfred()
private void ShowWinAlfred()
{
tbQuery.SelectAll();
Focus();

View File

@ -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)
{

View File

@ -19,7 +19,7 @@ namespace WinAlfred.PluginLoader
{
try
{
Assembly asm = Assembly.LoadFile(metadata.ExecuteFile);
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
List<Type> types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof (IPlugin))).ToList();
if (types.Count == 0)
{

View File

@ -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<Result> Query(Query query)
{
List<Result> results = new List<Result>();
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<Result> o = JsonConvert.DeserializeObject<List<Result>>(s);
return o;
}
public void Init()

View File

@ -5,7 +5,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ScrollViewer MaxHeight="300" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="pnlContainer">
</StackPanel>
</ScrollViewer>
</UserControl>

View File

@ -4,9 +4,6 @@ using WinAlfred.Plugin;
namespace WinAlfred
{
/// <summary>
/// Result.xaml 的交互逻辑
/// </summary>
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();
}

View File

@ -15,6 +15,7 @@
<WarningLevel>4</WarningLevel>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -35,14 +36,21 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>app.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -110,7 +118,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -135,6 +145,9 @@
<ItemGroup>
<Resource Include="Images\ctrl.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="app.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

BIN
WinAlfred/app.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

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