本文整理汇总了Python中notify.signal.Signal类的典型用法代码示例。如果您正苦于以下问题:Python Signal类的具体用法?Python Signal怎么用?Python Signal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Signal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_argument_passing
def test_argument_passing (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit (45, 'abc')
test.assert_results ((45, 'abc'))
开发者ID:berinhard,项目名称:py-notify,代码行数:8,代码来源:signal.py
示例2: test_emission_stop_3
def test_emission_stop_3 (self):
def stop_emission ():
was_stopped = signal.emission_stopped
signal.stop_emission ()
return was_stopped, signal.emission_stopped
signal = Signal (Signal.VALUE_LIST)
signal.connect (stop_emission)
self.assertEqual (signal.emit (), [(False, True)])
开发者ID:berinhard,项目名称:py-notify,代码行数:10,代码来源:signal.py
示例3: test_value_list_accumulator
def test_value_list_accumulator (self):
signal = Signal (AbstractSignal.VALUE_LIST)
self.assertEqual (signal.emit (), [])
signal.connect (lambda: 50)
self.assertEqual (signal.emit (), [50])
signal.connect (lambda: None)
signal.connect (lambda: ())
self.assertEqual (signal.emit (), [50, None, ()])
开发者ID:berinhard,项目名称:py-notify,代码行数:10,代码来源:signal.py
示例4: test_handler_garbage_collection_3
def test_handler_garbage_collection_3 (self):
test = NotifyTestObject ()
signal = Signal (AbstractSignal.ANY_ACCEPTS)
handler = HandlerGarbageCollectionTestCase.HandlerObject (test)
def accepting_handler (*arguments):
test.simple_handler_100 (*arguments)
return arguments[0]
signal.connect (accepting_handler)
signal.connect (handler.simple_handler)
self.assertEqual (len (signal._handlers), 2)
signal.emit (1)
del handler
self.collect_garbage ()
self.assertEqual (len (signal._handlers), 2)
signal.emit (2)
# This time emission is stopped by accumulator, but still the gc-collected handler
# must be removed.
self.assertEqual (len (signal._handlers), 1)
test.assert_results (101, 102)
开发者ID:berinhard,项目名称:py-notify,代码行数:28,代码来源:signal.py
示例5: initialize
def initialize (self):
signal = Signal ()
signal.connect (_ignoring_handler)
signal.connect (_ignoring_handler, 1)
signal.connect (_ignoring_handler, 'a', 'b')
signal.connect (_ignoring_handler, None, True, False)
self.__signal = signal
开发者ID:Distrotech,项目名称:python-notify,代码行数:9,代码来源:emission.py
示例6: test_emission_level_2
def test_emission_level_2 (self):
test = NotifyTestObject ()
signal = Signal ()
def reemit_if_shallow ():
test.results.append (signal.emission_level)
if signal.emission_level < 3:
signal.emit ()
signal.connect (reemit_if_shallow)
signal.emit ()
test.assert_results (1, 2, 3)
开发者ID:berinhard,项目名称:py-notify,代码行数:13,代码来源:signal.py
示例7: test_blocking_1
def test_blocking_1 (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit (1)
with signal.blocking (test.simple_handler):
signal.emit (2)
signal.emit (3)
test.assert_results (1, 3)
开发者ID:Distrotech,项目名称:python-notify,代码行数:14,代码来源:signal.py
示例8: test_block
def test_block (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit (1)
signal.block (test.simple_handler)
signal.emit (2)
test.assert_results (1)
开发者ID:berinhard,项目名称:py-notify,代码行数:11,代码来源:signal.py
示例9: test_disconnect
def test_disconnect (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit ()
signal.disconnect (test.simple_handler)
signal.emit ()
test.assert_results (())
开发者ID:berinhard,项目名称:py-notify,代码行数:11,代码来源:signal.py
示例10: test_blocking_2
def test_blocking_2 (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit (1)
with nested (ignoring_exceptions (), signal.blocking (test.simple_handler)):
signal.emit (2)
raise Exception
signal.emit (3)
test.assert_results (1, 3)
开发者ID:Distrotech,项目名称:python-notify,代码行数:15,代码来源:signal.py
示例11: test_connect_with_arguments
def test_connect_with_arguments (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect_safe (test.simple_handler, 'one argument')
signal.connect_safe (test.simple_handler, 'first', 'second', 3)
signal.emit ()
signal.emit ('a', 'b')
test.assert_results ('one argument', ('first', 'second', 3),
('one argument', 'a', 'b'), ('first', 'second', 3, 'a', 'b'))
开发者ID:berinhard,项目名称:py-notify,代码行数:12,代码来源:signal.py
示例12: test_mixed_argument_passing
def test_mixed_argument_passing (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_keywords_handler)
signal.emit (ham = 'spam')
signal.emit (42)
signal.emit (1, 2, 3, foo = 'bar')
test.assert_results ({ 'ham': 'spam' },
(42, { }),
(1, 2, 3, { 'foo': 'bar' }))
开发者ID:berinhard,项目名称:py-notify,代码行数:12,代码来源:signal.py
示例13: test_last_value_accumulator
def test_last_value_accumulator (self):
signal = Signal (AbstractSignal.LAST_VALUE)
self.assertEqual (signal.emit (), None)
signal.connect (lambda: 15)
self.assertEqual (signal.emit (), 15)
signal.connect (lambda: 'abc')
self.assertEqual (signal.emit (), 'abc')
开发者ID:berinhard,项目名称:py-notify,代码行数:9,代码来源:signal.py
示例14: test_emission_stop_2
def test_emission_stop_2 (self):
def reemit_signal (number):
signal.stop_emission ()
if number < 10:
signal (number + 1)
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.connect (reemit_signal)
# This must never be called since emission is stopped by the previous handler.
signal.connect (test.simple_handler)
signal.emit (0)
test.assert_results (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
开发者ID:berinhard,项目名称:py-notify,代码行数:18,代码来源:signal.py
示例15: test_emission_stop_1
def test_emission_stop_1 (self):
def stop_emission ():
signal.stop_emission ()
test = NotifyTestObject ()
signal = Signal ()
signal.connect (stop_emission)
signal.connect (test.simple_handler)
signal.emit ()
test.assert_results ()
开发者ID:berinhard,项目名称:py-notify,代码行数:12,代码来源:signal.py
示例16: test_handler_garbage_collection_2
def test_handler_garbage_collection_2 (self):
test = NotifyTestObject ()
signal = Signal ()
handler = HandlerGarbageCollectionTestCase.HandlerObject (test)
signal.connect (lambda *ignored: signal.stop_emission ())
signal.connect (handler.simple_handler)
self.assertEqual (len (signal._handlers), 2)
signal.emit (1)
del handler
self.collect_garbage ()
self.assertEqual (len (signal._handlers), 2)
signal.emit (2)
# Even though emission is stopped by the first handler, signal must still notice
# that it should remove the second one.
self.assertEqual (len (signal._handlers), 1)
test.assert_results ()
开发者ID:berinhard,项目名称:py-notify,代码行数:24,代码来源:signal.py
示例17: test_connect
def test_connect (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit ()
self.assert_ (signal.has_handlers ())
self.assert_ (signal)
test.assert_results (())
开发者ID:berinhard,项目名称:py-notify,代码行数:10,代码来源:signal.py
示例18: test_emission_level_1
def test_emission_level_1 (self):
signal = Signal (Signal.VALUE_LIST)
self.assertEqual (signal.emission_level, 0)
signal.connect (lambda: signal.emission_level)
self.assertEqual (signal.emit (), [1])
signal = Signal (Signal.VALUE_LIST)
def stop_emission_and_get_level ():
signal.stop_emission ()
return signal.emission_level
signal.connect (stop_emission_and_get_level)
self.assertEqual (signal.emit (), [1])
开发者ID:berinhard,项目名称:py-notify,代码行数:18,代码来源:signal.py
示例19: test_handler_garbage_collection_1
def test_handler_garbage_collection_1 (self):
test = NotifyTestObject ()
signal = Signal ()
handler = HandlerGarbageCollectionTestCase.HandlerObject (test)
signal.connect (handler.simple_handler)
self.assert_(signal._handlers is not None)
signal.emit (1)
del handler
self.collect_garbage ()
self.assert_(signal._handlers is not None)
signal.emit (2)
self.assert_(signal._handlers is None)
test.assert_results (1)
开发者ID:berinhard,项目名称:py-notify,代码行数:20,代码来源:signal.py
示例20: test_connect_with_keywords
def test_connect_with_keywords (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect_safe (test.simple_keywords_handler, a = 1)
signal.connect_safe (test.simple_keywords_handler, a = 2, b = 3)
signal.emit ()
signal.emit (b = 42)
signal.emit ('ham')
test.assert_results ({ 'a': 1 }, { 'a': 2, 'b' : 3 },
# Note that emission keyword arguments must override
# connection-time keyword arguments.
{ 'a': 1, 'b': 42 }, { 'a': 2, 'b' : 42 },
('ham', { 'a': 1 }), ('ham', { 'a': 2, 'b' : 3 }))
开发者ID:berinhard,项目名称:py-notify,代码行数:16,代码来源:signal.py
注:本文中的notify.signal.Signal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论