本文整理汇总了Python中observable.Observable.trigger方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.trigger方法的具体用法?Python Observable.trigger怎么用?Python Observable.trigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类observable.Observable
的用法示例。
在下文中一共展示了Observable.trigger方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_once_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_once_trigger():
"""test event triggering with event registered with once"""
obs = Observable()
nose.assert_equals(obs._events, {})
@obs.once("once_test")
def once_test():
pass
nose.assert_equals(obs._events, {"once_test": [once_test]})
nose.assert_true(obs.trigger("once_test"))
nose.assert_equals(obs._events, {"once_test": []})
nose.assert_false(obs.trigger("once_test"))
示例2: test_once_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_once_trigger():
"""test event triggering with event registered with once"""
obs = Observable()
nose.assert_false(obs.events)
@obs.once("once_test")
def once_test():
pass
nose.assert_equals(len(obs.events['once_test']), 1)
nose.assert_equals(obs.events['once_test'], [once_test])
nose.assert_true(obs.trigger("once_test"))
nose.assert_equals(obs.events['once_test'], [])
nose.assert_false(obs.trigger("once_test"))
示例3: test_no_event_for_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_no_event_for_trigger():
"""test exception raising for not existing events"""
obs = Observable()
assert not obs.trigger("no_existing_event")
with pytest.raises(EventNotFound):
obs.off("no_existing_event")
示例4: test_once_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_once_trigger():
"""test event triggering with event registered with once"""
obs = Observable()
obj = threading.local()
obj.called = False
@obs.once("once_test")
def once_test(obj):
obj.called = True
assert len(obs._events["once_test"]) == 1
assert obs._events["once_test"] == [once_test]
assert obs.trigger("once_test", obj)
assert obj.called
assert obs._events["once_test"] == []
assert not obs.trigger("once_test", obj)
示例5: test_on_multiple_handlers
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_on_multiple_handlers():
"""test event registering with the on method and multiple handlers"""
obs = Observable()
results = []
def some_test(*args, **kw):
results.append(1)
def some_test_2(*args, **kw):
results.append(2)
obs.on("some_test", some_test, some_test_2)
assert len(obs._events["some_test"]) == 2
obs.trigger("some_test")
assert results == [1, 2]
示例6: test_trigger_arg
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_trigger_arg():
"""test event triggering with arguments"""
obs = Observable()
@obs.on("some_test")
def some_test(some_data):
assert some_data == "some data"
assert obs.trigger("some_test", "some data")
示例7: test_trigger_args
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_trigger_args():
"""test event triggering with argument list"""
obs = Observable()
@obs.on("some_test")
def some_test(some_data, some_other_data):
assert some_data is True
assert some_other_data is False
assert obs.trigger("some_test", *[True, False])
示例8: test_trigger_kwargs
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_trigger_kwargs():
"""test event triggering with keyword-arguments"""
obs = Observable()
@obs.on("some_test")
def some_test(some_data=True, some_other_data=False):
assert some_data is False
assert some_other_data is True
assert obs.trigger("some_test", some_other_data=True, some_data=False)
示例9: test_once_decorator
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_once_decorator():
"""test event registering with the once decorator"""
obs = Observable()
@obs.once("once_test")
def once_test():
pass
assert once_test in obs._events["once_test"]
assert obs.trigger("once_test")
assert once_test not in obs._events["once_test"]
示例10: test_once
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_once():
"""test event registering with the once method"""
obs = Observable()
def once_test():
pass
obs.once("once_test", once_test)
assert len(obs._events["once_test"]) == 1
assert obs.trigger("once_test")
assert obs._events["once_test"] == []
示例11: test_on_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_on_trigger():
"""test event triggering with event registered with on"""
obs = Observable()
obj = threading.local()
obj.called = False
@obs.on("on_test")
def on_test(obj):
obj.called = True
assert obs._events == {"on_test": [on_test]}
assert obs.trigger("on_test", obj)
assert obj.called
示例12: test_off
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
def test_off():
"""test obs.off method"""
obs = Observable()
@obs.on("on_test")
def on_test():
pass
assert obs._events["on_test"] == [on_test]
assert obs.trigger("on_test")
obs.off("on_test", on_test)
assert obs._events["on_test"] == []
obs.off()
assert not obs._events
@obs.on("more_than_one_event")
def func1():
pass
@obs.on("more_than_one_event")
def func2():
pass
@obs.on("more_than_one_event")
def func3():
pass
assert obs._events["more_than_one_event"] == [func1, func2, func3]
obs.off("more_than_one_event", func2)
assert obs._events["more_than_one_event"] == [func1, func3]
obs.off("more_than_one_event")
assert obs._events["more_than_one_event"] == []
示例13: __init__
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import trigger [as 别名]
class PopPi:
# Main application for pop machine
# State information
__acceptingFob = False
__acceptingFunds = False
__creditOnlyMode = False
__lastCreditButtonState = 0
__memberFob = None
__memberCredit = None
__deposited = None
__popCost = None
def __init__(self):
self.__obs = Observable()
conf = Configuration()
self.__rfid = RfidReader(conf.rfid.serialPort)
self.__acceptor = CoinAcceptor(conf.coinAcceptor.serialPort, conf.coinAcceptor.inhibitPin, conf.coinMap)
self.__memberService = MemberService(conf.db.username, conf.db.password, conf.db.hostname, conf.db.port, conf.db.database)
self.__popMachine = PopMachine(conf.popMachine.relayPin)
self.__webService = WebService(conf.web.bindAddress, conf.web.port)
self.__acceptor.inhibit(True)
self.__popCost = self.__popMachine.getPopCost()
self.__obs.on("CardSwiped", self.__onCardRead)
self.__obs.on("CoinAccepted", self.__onCoinAccepted)
self.__obs.on("MemberNotFound", self.__onMemberNotFound)
self.__obs.on("PopPaid", self.__onPopPaid)
self.__obs.on("CreditCompleted", self.__onCreditCompleted)
self.__creditOnlyPin = conf.general.creditOnlyPin
GPIO.setup(self.__creditOnlyPin, GPIO.IN)
def start(self):
self.__fobThread = threading.Thread(target=self.__readCardThread)
self.__fobThread.daemon = True
self.__fobThread.start()
self.__coinThread = threading.Thread(target=self.__readCoinThread)
self.__coinThread.daemon = True
self.__coinThread.start()
self.__creditOnlyThread = threading.Thread(target=self.__readCreditOnlyButton)
self.__creditOnlyThread.daemon = True
self.__creditOnlyThread.start()
self.__resetStates()
self.__acceptingFob = True
def stop(self):
if not self.__rfid is None:
self.__rfid.shutdown()
if not self.__acceptor is None:
self.__acceptor.shutdown()
if not self.__memberService is None:
self.__memberService.shutdown()
if not self.__popMachine is None:
self.__popMachine.shutdown()
if not self.__webService is None:
self.__webService.shutdown()
def __onCardRead(self, card):
if not self.__acceptingFob:
print("Fob swiped while not accepting fobs: Ignoring fob " + str(card))
return
self.__acceptingFob = False
self.__webService.onSwipeStart()
print("Fob " + str(card) + " swiped. Finding member...")
self.__memberCredit = self.__memberService.getCredit(card)
if self.__memberCredit is None:
self.__obs.trigger("MemberNotFound", card)
return
self.__memberFob = card
print("Member " + str(card) + " has " + str(self.__memberCredit) + " cents credit")
self.__acceptingFunds = True
self.__deposited = 0
self.__acceptor.inhibit(False)
self.__webService.onSwipe(self.__memberCredit, self.__popCost)
requiredFunds = self.__getRequiredFunds()
print("Member " + str(card) + " needs to supply " + str(requiredFunds) + " cents")
self.__checkRequiredFunds()
def __onCoinAccepted(self, coin):
if not self.__acceptingFunds:
print("Coin accepted while not accepting coins: Ignoring " + str(coin) + " cents")
return
self.__deposited += coin
self.__webService.onDeposit(coin)
print("Member inserted " + str(coin) + " cents")
self.__checkRequiredFunds()
def __onPopPaid(self):
self.__acceptor.inhibit(True)
self.__acceptingFunds = False
newCredit = (self.__memberCredit + self.__deposited) - self.__popCost
self.__memberService.setCredit(self.__memberFob, newCredit)
print("Member's new credit is " + str(newCredit) + " cents")
self.__webService.onPaid(newCredit)
self.__popMachine.awardPop()
print("Pop awarded to member")
self.__resetStates()
def __onCreditCompleted(self):
self.__acceptor.inhibit(True)
self.__acceptingFunds = False
#.........这里部分代码省略.........