PowerToys/Wox/PluginLoader/PythonPluginLoader.cs

56 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
2013-12-20 19:38:10 +08:00
using System.Linq;
using System.Threading;
2014-01-11 00:19:14 +08:00
using Python.Runtime;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
using Wox.Helper;
2013-12-20 19:38:10 +08:00
2014-01-29 18:33:24 +08:00
namespace Wox.PluginLoader
2013-12-20 19:38:10 +08:00
{
public class PythonPluginLoader : BasePluginLoader
2013-12-20 19:38:10 +08:00
{
public override List<PluginPair> LoadPlugin()
2013-12-20 19:38:10 +08:00
{
if (!CheckPythonEnvironmentInstalled()) return new List<PluginPair>();
List<PluginPair> plugins = new List<PluginPair>();
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.Python.ToUpper()).ToList();
foreach (PluginMetadata metadata in metadatas)
{
2013-12-23 19:21:51 +08:00
PythonPluginWrapper python = new PythonPluginWrapper(metadata);
PluginPair pair = new PluginPair()
{
Plugin = python,
Metadata = metadata
};
plugins.Add(pair);
}
2013-12-20 19:38:10 +08:00
return plugins;
}
private bool CheckPythonEnvironmentInstalled() {
try
{
SetPythonHome();
PythonEngine.Initialize();
PythonEngine.Shutdown();
}
catch {
2014-03-23 17:43:46 +08:00
Log.Warn("Could't find python environment, all python plugins disabled.");
return false;
}
return true;
}
private void SetPythonHome()
{
//Environment.SetEnvironmentVariable("PYTHONHOME",Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"PythonHome"));
//PythonEngine.PythonHome =
//PythonEngine.ProgramName
}
2013-12-20 19:38:10 +08:00
}
}