本文整理匯總了Python中notify.signal.Signal.emit方法的典型用法代碼示例。如果您正苦於以下問題:Python Signal.emit方法的具體用法?Python Signal.emit怎麽用?Python Signal.emit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類notify.signal.Signal
的用法示例。
在下文中一共展示了Signal.emit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_handler_garbage_collection_3
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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)
示例2: test_custom_accumulator
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
def test_custom_accumulator (self):
class CustomAccumulator (AbstractSignal.AbstractAccumulator):
def get_initial_value (self):
return 10
def accumulate_value (self, accumulated_value, value_to_add):
return accumulated_value + value_to_add
def should_continue (self, accumulated_value):
return accumulated_value <= 50
def post_process_value (self, accumulated_value):
return -accumulated_value
signal = Signal (CustomAccumulator ())
self.assertEqual (signal.emit (), -10)
signal.connect (lambda: 15)
self.assertEqual (signal.emit (), -25)
signal.connect (lambda: 20)
self.assertEqual (signal.emit (), -45)
signal.connect (lambda: 30)
self.assertEqual (signal.emit (), -75)
# This handler should never be invoked.
signal.connect (lambda: 50)
self.assertEqual (signal.emit (), -75)
示例3: test_argument_passing
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
def test_argument_passing (self):
test = NotifyTestObject ()
signal = Signal ()
signal.connect (test.simple_handler)
signal.emit (45, 'abc')
test.assert_results ((45, 'abc'))
示例4: test_last_value_accumulator
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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')
示例5: test_connect
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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 (())
示例6: test_value_list_accumulator
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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, ()])
示例7: test_block
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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)
示例8: test_disconnect
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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 (())
示例9: test_connect_with_arguments
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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'))
示例10: test_emission_stop_1
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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 ()
示例11: test_emission_level_2
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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)
示例12: test_any_accepts_accumulator
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
def test_any_accepts_accumulator (self):
signal = Signal (AbstractSignal.ANY_ACCEPTS)
self.assertEqual (signal.emit (), False)
signal.connect (lambda: False)
self.assertEqual (signal.emit (), False)
signal.connect (lambda: ())
self.assertEqual (signal.emit (), ())
signal.connect (lambda: 'I accept')
self.assertEqual (signal.emit (), 'I accept')
signal.connect (lambda: ())
self.assertEqual (signal.emit (), 'I accept')
示例13: test_all_accept_accumulator
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
def test_all_accept_accumulator (self):
signal = Signal (AbstractSignal.ALL_ACCEPT)
self.assertEqual (signal.emit (), True)
signal.connect (lambda: True)
self.assertEqual (signal.emit (), True)
signal.connect (lambda: 'I accept')
self.assertEqual (signal.emit (), 'I accept')
signal.connect (lambda: [])
self.assertEqual (signal.emit (), [])
signal.connect (lambda: True)
self.assertEqual (signal.emit (), [])
示例14: test_connecting_safely_1
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
def test_connecting_safely_1 (self):
test = NotifyTestObject ()
signal = Signal ()
signal.emit (1)
with signal.connecting_safely (test.simple_handler):
signal.emit (2)
with signal.connecting_safely (test.simple_handler):
signal.emit (3)
signal.emit (4)
signal.emit (5)
test.assert_results (2, 3, 4)
示例15: test_emission_stop_2
# 需要導入模塊: from notify.signal import Signal [as 別名]
# 或者: from notify.signal.Signal import emit [as 別名]
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)