NOX的使用之学习篇【二】

本文介绍如何使用Python开发NOX组件,包括组件的基本结构、添加步骤及依赖配置。通过实例展示如何创建简单的Python组件,并提供了核心API及组件交互的方法。

Developing in NOX:

 

Building a Python only component

Pure python components are much simpler to construct than C++ components. As an example, see src/nox/apps/examples/pyloop.py. A Python component must have the following construction:

   from nox.lib.core import *
   
   class foo(Component):
   
       def __init__(self, ctxt):
           Component.__init__(self, ctxt)
   
       def install(self):
           # register for event here
           pass
   
       def getInterface(self):
           return str(foo)
       
   def getFactory():
       class Factory:
           def instance(self, ctxt):
               return foo(ctxt)
   
       return Factory()

You may optionally add a configure method which is called in the same order as for C++ (before install on startup). The following steps should be all that is needed to build a bare-bones python component for NOX.

Add your .py file to src/nox/coreapps/examples/ Copy code from src/nox/coreapps/examples/pyloop.py (you need to mirror everything except for the code under the install method) Add your Python file(s) to NOX_RUNTIMEFILES in src/nox/apps/examples/Makefile.am Update src/nox/apps/examples/meta.json to include your new app. Make sure that “python” is a dependency (copying is the best approach). After you're done, recompile following the same 3 steps (the build/ directory is already there now)

Pointers:

  • The core python API is in nox/lib/core.py and nox/lib/util.py.
  • To get a handle to another component, use the Component.resolve(..) method on the class or interface to which you want a handle. For example:
   from nox.app.examples.pyswitch import pyswitch
   self.resolve(pyswitch)

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/wangicter/archive/2011/07/01/4767470.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值