zoukankan      html  css  js  c++  java
  • 简单说pyglet.event

    emitter,就是pyglet.event.EventDispatcher的子类, 负责发出事件的消息,并且规定了响应消息的函数名。

    class Consumer(pyglet.event.EventDispatcher):
        def call(self):
            self.dispatch_event('response')
    Consumer.register_event_type('response')

    call方法就是在发送一个叫'response'的事件

    listener, 就是一个实现了事件响应函数的类的对象,

    class TaxiDriver(object):
        def __init__(self, DidiApp):
            DidiApp.push_handlers(self)
        def response(self):
            print("I'm coming soon!")

    需要将自己传递给emittor, 并且实现上面的response方法

    运行:

    c = Consumer()
    t = TaxiDriver(c)
    c.call()

    当c调用call方法的时候,就发出了"response"事件消息,然后遍历执行handlers中的response方法

  • 相关阅读:
    vpp编写plugin
    vrf 命令
    vxlan + 多个vrf
    dpdk helloworld
    Go函数高级
    Go_defer
    Go递归函数
    Go作用域
    Go函数
    Go字符串
  • 原文地址:https://www.cnblogs.com/wenning/p/5096792.html
Copyright © 2011-2022 走看看