def func(): self.assertEqual(self.counter, 0) yield Never() | Inc(self) # yield Inc(self) と同じ self.assertEqual(self.counter, 1) yield Never() | Never() # A # yield Never() と同じ self.counter += 1 yield 'TEST' self.counter += 1
def func(): self.assertEqual(self.counter, 0) yield Never() & Inc(self) # A self.assertEqual(self.counter, 1) self.counter += 1 yield 'TEST' self.counter += 1
def func(): self.assertEqual(self.counter, 0) yield Wait(events=( Never(), Inc(self), Inc(self), ), n=1) self.assertEqual(self.counter, 1) yield Wait(events=( Never(), Inc(self), Inc(self), ), n=3) # A self.counter += 1 yield 'TEST' self.counter += 1
def anim_random(self): '''無作為に明かりを点灯させる''' from callbackgoaway import callbackgoaway, Never from callbackgoaway.kivy import Sleep as S, Event as E from kivy.animation import Animation as A from kivy.utils import get_random_color from random import random yield S(0) light_off_color = self.light_off_color[:] def random_duration(): return random() + .5 @callbackgoaway def anim_one_light(property_name): yield S(0) a = None try: while True: yield S(random_duration()) a = A( **{ property_name: get_random_color(), 'duration': random_duration() }) a.start(self) yield E(a, 'on_complete') yield S(random_duration()) a = A( **{ property_name: light_off_color[:], 'duration': random_duration() }) a.start(self) yield E(a, 'on_complete') finally: if a is not None: a.cancel(self) gens = [ anim_one_light(f'_current_{name}_color') for name in ( 'left', 'right', 'center', ) ] try: yield Never() finally: for gen in gens: gen.close()
def anim_main(self): from kivy.animation import Animation as A from callbackgoaway import callbackgoaway, Never from callbackgoaway.kivy import Sleep as S, Event as E yield S(0) @callbackgoaway def anim_repeat_falldown(label, *, delay): yield S(delay) a = ( A(pos_hint={'y': -0.1, }, t='out_cubic') + A(pos_hint={'y': 0, }, d=2, t='out_cubic') + A(pos_hint={'y': -1, }, top=self.y, t='out_cubic') ) try: while True: label.pos_hint['y'] = 1 a.start(label) yield E(a, 'on_complete') yield S(1) finally: a.cancel(label) labels = [Label(font_size=self.font_size, text=c, pos_hint={'y': 1, }) for c in self.text] add_widget = self.add_widget for label in labels: add_widget(label) gens = [ anim_repeat_falldown(label, delay=index * 0.2) for index, label in enumerate(labels) ] try: yield Never() finally: for gen in gens: gen.close()
def func(): try: self.counter += 1 yield Never() except GeneratorExit: self.counter += 1