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


Python EventEmitter.disconnect方法代码示例

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


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

示例1: test_chained_emitters

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import disconnect [as 别名]
    def test_chained_emitters(self):
        """Chained emitters"""
        em1 = EventEmitter(source=None, type='test_event1')
        em2 = EventEmitter(source=self, type='test_event2')
        em1.connect(em2)
        em1.connect(self.record_event)
        self.result = None
        ev = em1()
        self.assert_result(
            event=ev,
            event_class=Event,
            source=None,
            type='test_event1',
            sources=[None])

        # sources look different from second emitter, but type is the same.
        em1.disconnect(self.record_event)
        em2.connect(self.record_event)
        self.result = None
        ev = em1()
        self.assert_result(
            event=ev,
            event_class=Event,
            source=self,
            type='test_event1',
            sources=[
                None,
                self])
开发者ID:almarklein,项目名称:vispy,代码行数:30,代码来源:test_event_emitter.py

示例2: test_emission_order

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import disconnect [as 别名]
    def test_emission_order(self):
        """Event emission order"""
        em = EventEmitter(type='test_event')
        def cb1(ev):
            self.result = 1
        def cb2(ev):
            self.result = 2
            
        em.connect(cb1)
        em.connect(cb2)
        self.result = None
        em()
        assert self.result == 1, "Events emitted in wrong order"

        em.disconnect()
        em.connect(cb2)
        em.connect(cb1)
        self.result = None
        em()
        assert self.result == 2, "Events emitted in wrong order"
开发者ID:ds604,项目名称:vispy,代码行数:22,代码来源:test_event_emitter.py

示例3: test_disconnect

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import disconnect [as 别名]
    def test_disconnect(self):
        """Emitter disconnection"""
        em = EventEmitter(type='test_event')

        def cb1(ev):
            self.result = 1

        def cb2(ev):
            self.result = 2

        em.connect((self, 'record_event'))
        em.connect(cb1)
        em.connect(cb2)
        self.result = None
        em.disconnect(cb2)
        em.disconnect(cb2)  # should pass silently
        ev = em()
        self.assert_result(event=ev)

        self.result = None
        em.disconnect((self, 'record_event'))
        ev = em()
        assert self.result == 1

        self.result = None
        em.connect(cb1)
        em.connect(cb2)
        em.connect((self, 'record_event'))
        em.disconnect()
        em()
        assert self.result is None
开发者ID:almarklein,项目名称:vispy,代码行数:33,代码来源:test_event_emitter.py

示例4: test_source_stack_integrity

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import disconnect [as 别名]
 def test_source_stack_integrity(self):
     """Emitter checks source stack"""
     em = EventEmitter(type='test_event')
     
     def cb(ev):
         ev._sources.append('x')
     em.connect(cb)
     
     try:
         em()
     except RuntimeError as err:
         if str(err) != 'Event source-stack mismatch.':
             raise
         
     em.disconnect()
     def cb(ev):
         ev._sources = []
     em.connect(cb)
     
     try:
         em()
     except IndexError:
         pass
开发者ID:ds604,项目名称:vispy,代码行数:25,代码来源:test_event_emitter.py

示例5: test_event_connect_order

# 需要导入模块: from vispy.util.event import EventEmitter [as 别名]
# 或者: from vispy.util.event.EventEmitter import disconnect [as 别名]
def test_event_connect_order():
    """Test event connection order"""
    def a():
        return

    def b():
        return

    def c():
        return

    def d():
        return

    def e():
        return

    def f():
        return

    em = EventEmitter(type='test_event')
    assert_raises(ValueError, em.connect, c, before=['c', 'foo'])
    assert_raises(ValueError, em.connect, c, position='foo')
    assert_raises(TypeError, em.connect, c, ref=dict())
    em.connect(c, ref=True)
    assert_equal((c,), tuple(em.callbacks))
    em.connect(c)
    assert_equal((c,), tuple(em.callbacks))
    em.connect(d, ref=True, position='last')
    assert_equal((c, d), tuple(em.callbacks))
    em.connect(b, ref=True)  # position='first'
    assert_equal((b, c, d), tuple(em.callbacks))
    assert_raises(RuntimeError, em.connect, a, before='c', after='d')  # can't
    em.connect(a, ref=True, before=['c', 'd'])  # first possible pos == 0
    assert_equal((a, b, c, d), tuple(em.callbacks))
    em.connect(f, ref=True, after=['c', 'd'])
    assert_equal((a, b, c, d, f), tuple(em.callbacks))
    em.connect(e, ref=True, after='d', before='f')
    assert_equal(('a', 'b', 'c', 'd', 'e', 'f'), tuple(em.callback_refs))
    em.disconnect(e)
    em.connect(e, ref=True, after='a', before='f', position='last')
    assert_equal(('a', 'b', 'c', 'd', 'e', 'f'), tuple(em.callback_refs))
    em.disconnect(e)
    em.connect(e, ref='e', after='d', before='f', position='last')
    assert_equal(('a', 'b', 'c', 'd', 'e', 'f'), tuple(em.callback_refs))
    em.disconnect(e)
    em.connect(e, after='d', before='f', position='first')  # no name
    assert_equal(('a', 'b', 'c', 'd', None, 'f'), tuple(em.callback_refs))
    em.disconnect(e)
    assert_raises(ValueError, em.connect, e, ref='d')  # duplicate name
    em.connect(e, ref=True, after=[], before='f', position='last')
    assert_equal(('a', 'b', 'c', 'd', 'e', 'f'), tuple(em.callback_refs))
    assert_equal((a, b, c, d, e, f), tuple(em.callbacks))

    old_e = e

    def e():
        return

    assert_raises(ValueError, em.connect, e, ref=True)  # duplicate name
    em.connect(e)
    assert_equal((None, 'a', 'b', 'c', 'd', 'e', 'f'),
                 tuple(em.callback_refs))
    assert_equal((e, a, b, c, d, old_e, f), tuple(em.callbacks))
开发者ID:almarklein,项目名称:vispy,代码行数:66,代码来源:test_event_emitter.py


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