当前位置: 首页>>代码示例>>Python>>正文


Python EventEmitter.block方法代码示例

本文整理汇总了Python中vispy.util.event.EventEmitter.block方法的典型用法代码示例。如果您正苦于以下问题:Python EventEmitter.block方法的具体用法?Python EventEmitter.block怎么用?Python EventEmitter.block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vispy.util.event.EventEmitter的用法示例。


在下文中一共展示了EventEmitter.block方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_emitter_block

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import block [as 别名]
def test_emitter_block():
    state = [False, False]
    
    def a(ev):
        state[0] = True
        
    def b(ev):
        state[1] = True
        
    e = EventEmitter(source=None, type='event')
    e.connect(a)
    e.connect(b)
    
    def assert_state(a, b):
        assert state == [a, b]
        state[0] = False
        state[1] = False
    
    e()
    assert_state(True, True)
    
    # test global blocking
    e.block()
    e()
    assert_state(False, False)
    e.block()
    e()
    assert_state(False, False)
    
    # test global unlock, multiple depth
    e.unblock()
    e()
    assert_state(False, False)
    e.unblock()
    e()
    assert_state(True, True)
    
    # test unblock failure
    try:
        e.unblock()
        raise Exception("Expected RuntimeError")
    except RuntimeError:
        pass
    
    # test single block
    e.block(a)
    e()
    assert_state(False, True)
    
    e.block(b)
    e()
    assert_state(False, False)
    
    e.block(b)
    e()
    assert_state(False, False)

    # test single unblock
    e.unblock(a)
    e()
    assert_state(True, False)
    
    e.unblock(b)
    e()
    assert_state(True, False)
    
    e.unblock(b)
    e()
    assert_state(True, True)
    
    # Test single unblock failure
    try:
        e.unblock(a)
        raise Exception("Expected RuntimeError")
    except RuntimeError:
        pass

    # test global blocker
    with e.blocker():
        e()
        assert_state(False, False)
        
        # test nested blocker
        with e.blocker():
            e()
            assert_state(False, False)
        
        e()
        assert_state(False, False)

    e()
    assert_state(True, True)

    # test single blocker
    with e.blocker(a):
        e()
        assert_state(False, True)
        
        # test nested gloabel blocker
        with e.blocker():
#.........这里部分代码省略.........
开发者ID:almarklein,项目名称:vispy,代码行数:103,代码来源:test_event_emitter.py


注:本文中的vispy.util.event.EventEmitter.block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。