博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Hiero中的Events机制

Posted on 2015-10-10 18:11  SolHe  阅读(221)  评论(0编辑  收藏  举报

The hiero.core.events module allows you to register method callbacks to respond to events sent by Hiero. Hiero uses this for the callback mechanism to allow Python scripts to get notifications when interesting things happen. It also allows for the creation of custom event types and for sending custom events.

译文:

Hiero.core.events模块允许用户注册callbacks方法去响应Hiero运行中发生的事件,Hiero通过使用这个callbacks机制让python脚本能够在关联事件发生时收到通知。Hiero也允许用户自定义事件类生成自定义的事件。

 

An event is an object which is passed to registered callbacks.

译文:

event实际上是一个被传递给已注册的callbacks的对象。Callbacks响应event的时候,event会作为一个对象传递给callbacks。

 

If the event comes from Hiero itself (and is not a custom user registered event), it contains three attributes:

译文:

如果事件来源于Hiero自身,且不是用户自己注册事件,那么它会包含以下三个属性:

 

1.    type - indicates the type of the EventType (e.g. kShowContextMenu) 类型

2.    subtype - indicates the subtype of the EventType (e.g. kTimeline)    子类型

3.    sender (generally a view, or action which triggered the event)       触发事件

 

The type and subtype attributes indicate the type and subtype of the event, respectively. The sender is the object that sent the event, and varies by event type (and sometimes by subtype event).

译文:

Type及subtype都是包含了event类型,触发事件则是发出event的对象,类型不同,触发事件也不一而论。

 

Note

The subtype attribute can be None. This is the case if an event is sent without a subtype. Generally, the type and subtype are strings, usually from the EventType enumeration.

译文:

Subtype属性可以为空,这个因为发出的事件往往也是没有子类型。但一般来说,type和subtype都是字符串型,通常来自于eventype的清单。

 

The most basic event callback takes the following form:

 

def eventCallback(event):

  print "Event fired with type %s, subtype %s and sender %s" % (event.type, event.subtype, str(event.sender))