async def on_drag_fail(self, touch): from kivy.graphics import PushMatrix, PopMatrix, Rotate import asynckivy as ak push_mat = PushMatrix() rotate = Rotate(origin=self.center) pop_mat = PopMatrix() cb = self.canvas.before ca = self.canvas.after try: cb.add(push_mat) cb.add(rotate) ca.add(pop_mat) await ak.and_( ak.animate(rotate, d=.4, angle=720.), ak.animate(self, d=.4, opacity=0.), ) self.parent.remove_widget(self) finally: cb.remove(push_mat) cb.remove(rotate) ca.remove(pop_mat)
async def animate(root): label = root.ids.label.__self__ while True: await ak.or_( ak.event(root, 'on_touch_down'), ak.animate(label, right=root.width), ) label.right = root.width await ak.or_( ak.event(root, 'on_touch_down'), ak.animate(label, top=root.height), ) label.top = root.height await ak.or_( ak.event(root, 'on_touch_down'), ak.animate(label, x=0), ) label.x = 0 await ak.or_( ak.event(root, 'on_touch_down'), ak.animate(label, y=0), ) label.y = 0
def test_list(approx, ready_to_sleep): import asynckivy as ak target = Target() coro = ak.animate(target, lst=[100, 200], d=.4) sleep = ready_to_sleep() ak.start(coro) sleep(.1) assert target.lst == approx([25, 50]) sleep(.1) assert target.lst == approx([50, 100]) sleep(.1) assert target.lst == approx([75, 150]) sleep(.1) assert target.lst == approx([100, 200]) sleep(.1) assert target.lst == approx([100, 200])
def test_dict(approx, ready_to_sleep): import asynckivy as ak target = Target() coro = ak.animate(target, dct={'key': 100}, d=.4) sleep = ready_to_sleep() ak.start(coro) sleep(.1) assert target.dct == approx({'key': 25}) sleep(.1) assert target.dct == approx({'key': 50}) sleep(.1) assert target.dct == approx({'key': 75}) sleep(.1) assert target.dct == approx({'key': 100}) sleep(.1) assert target.dct == approx({'key': 100})
def test_cancel(approx, ready_to_sleep): import asynckivy as ak target = Target() coro = ak.animate( target, num=100, d=.4, ) sleep = ready_to_sleep() ak.raw_start(coro) sleep(.1) assert target.num == approx(25) sleep(.1) assert target.num == approx(50) coro.close() # cancel assert target.num == approx(50)
def test_dict(approx): import asynckivy as ak target = Target() coro = ak.animate(target, dct={'key': 100}, d=.4) clock = Clock() ak.start(coro) clock.sleep(.1) assert target.dct == approx({'key': 25}) clock.sleep(.1) assert target.dct == approx({'key': 50}) clock.sleep(.1) assert target.dct == approx({'key': 75}) clock.sleep(.1) assert target.dct == approx({'key': 100}) clock.sleep(.1) assert target.dct == approx({'key': 100})
def test_list(approx): import asynckivy as ak target = Target() coro = ak.animate(target, lst=[100, 200], d=.4) clock = Clock() ak.start(coro) clock.sleep(.1) assert target.lst == approx([25, 50]) clock.sleep(.1) assert target.lst == approx([50, 100]) clock.sleep(.1) assert target.lst == approx([75, 150]) clock.sleep(.1) assert target.lst == approx([100, 200]) clock.sleep(.1) assert target.lst == approx([100, 200])
def _start_anim(self, *args): if self.children: child = self.children[0] self._coro.close() if not self.do_anim: child.pos = self.pos child.size = self.size return self._coro = ak.start( ak.animate( child, d=self.anim_duration, t=self.anim_transition, x=self.x, y=self.y, width=self.width, height=self.height, ))
def test_cancel(approx, force_final_value): import asynckivy as ak target = Target() coro = ak.animate(target, num=100, d=.4, force_final_value=force_final_value) clock = Clock() ak.start(coro) clock.sleep(.1) assert target.num == approx(25) clock.sleep(.1) assert target.num == approx(50) coro.close() # cancel if force_final_value: assert target.num == approx(100) else: assert target.num == approx(50)