本文介绍了雅培最小的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以使用 Yapsy插件框架提供一个最小的工作示例吗?
Can anyone provide a minimal working example using the Yapsy plugin framework?
推荐答案
这是一个非常简单的示例.它具有三个文件:
Here's a very simple example. It has three files:
- plugins \ plugin1.py-插件.它必须包含一个从IPlugin继承的类.
- plugins \ plugin1.yapsy-plugin-有关插件的信息.
- yapsy-example.py-主脚本.这只会加载它在"plugins"目录中可以找到的所有插件,并在它们上调用一个方法以证明它们可以工作.
您可以将更多插件添加到plugins目录,此脚本将在所有插件周围循环.
You could add more plugins to the plugins directory, and this script would loop around them all.
在 http://lateral.netmanagers.com.ar/weblog/posts/BB923.html(已存档).
yapsy-example.py
from yapsy.PluginManager import PluginManager
def main():
# Load the plugins from the plugin directory.
manager = PluginManager()
manager.setPluginPlaces(["plugins"])
manager.collectPlugins()
# Loop round the plugins and print their names.
for plugin in manager.getAllPlugins():
plugin.plugin_object.print_name()
if __name__ == "__main__":
main()
plugins \ plugin1.py
from yapsy.IPlugin import IPlugin
class PluginOne(IPlugin):
def print_name(self):
print "This is plugin 1"
plugins \ plugin1.yapsy-plugin
[Core]
Name = Plugin 1
Module = plugin1
[Documentation]
Author = John Smith
Version = 0.1
Website = http://lotsofplugins.com
Description = My first plugin
这篇关于雅培最小的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!