WEB开发网
开发学院软件开发Python Python 与 Gnumeric 共舞 阅读

Python 与 Gnumeric 共舞

 2008-09-30 13:08:46 来源:WEB开发网   
核心提示: 代码 2 test_functions函数原型字典test_functions = {'py_printf': func_printf,'py_capwords': ('s', 'sentence', func_capword

代码 2 test_functions函数原型字典

test_functions = {
    'py_printf': func_printf,
    'py_capwords': ('s', 'sentence', func_capwords),
    
    
    'py_bitand':  ('ff', 'num1, num2', func_bitand)
}
   

在函数原型字典中,参数类型是用特殊的字符来表示的,例如func_bitand的两个浮点数参数表示为"ff"。常见参数类型的字符串表示总结如下:

Python 与 Gnumeric 共舞

另外一个结构简单的XML文件plugins.xml (1) ,是开发者向Gnumeric提供的配置信息。information标签中的name和description标签提供了该插件的名字和描述信息,而且这些信息的国际化也很简单,只需要在有语言标记的相应标签中填写国际化信息即可。loader标签中attribute标签的value属性、service标签中id属性、function标签中的name属性是最重要的,分别对应于Python脚本文件名、脚本中的函数原型字典名(不包括后缀)、函数原型函数的key。对于本例,属性值为py_func,test,py_printf,py_capwords,py_bitand,则对应于插件分别为py_func.py和test_functions,py_printf,py_capwords,py_bitand。这些对应关系一定要一致,否则Gnumeric就会向你抱怨了。

代码 3 py-func.py的plugin.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<plugin id="Gnumeric_PyFunc">
    <information>
        <name>Python functions</name>
        <description>Sample Python plugin providing
               some (useless) functions.
        </description>
        <require_explicit_enabling/>
    </information>
    <loader type="Gnumeric_PythonLoader:python">
        <attribute value="py_func" name="module_name"/>
    </loader>
    <services>
        <service type="function_group" id="test">
            <category>Python</category>
            <category xml:lang="zh_CN">
                Python
            </category>
            <functions>
                <function name="py_printf"/>
                <function name="py_capwords"/>
                <function name="py_bitand"/>
            </functions>
        </service>
    </services>
</plugin>

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Python Gnumeric 共舞

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接