Skip to content

Commit

Permalink
adapt to asynckivy 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gottadiveintopython committed Aug 23, 2023
1 parent 44f765e commit 041eae8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions examples/customizing_animation_ver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from kivy.graphics import Rotate, Scale

import asynckivy as ak
from asynckivy import vanim
from asynckivy.utils import transform
from asynckivy import vanim, transform

from kivy_garden.draggable import KXDroppableBehavior, KXDraggableBehavior

Expand Down
6 changes: 3 additions & 3 deletions examples/shopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ async def _init_database(conn: sqlite3.Connection):
# FIXME: The Session object may not be thread-safe so it's probably better not to share it between threads...
with ThreadPoolExecutor() as executer, requests.Session() as session:
async def download_one_image(name, image_url) -> Tuple[bytes, str]:
image = await ak.run_in_executer(lambda: session.get(image_url).content, executer)
image = await ak.run_in_executor(executer, lambda: session.get(image_url).content)
return (image, name)
tasks = await ak.and_from_iterable(
tasks = await ak.wait_all(*(
download_one_image(name, image_url)
for name, image_url in cur.execute("SELECT name, image_url FROM Foods")
)
))

# save images
cur.executemany(
Expand Down
8 changes: 4 additions & 4 deletions src/kivy_garden/draggable/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def _see_if_a_touch_actually_is_a_dragging_gesture(self, touch):
ak.sleep(self.drag_timeout / 1000.),
self._true_when_a_touch_ended_false_when_it_moved_too_much(touch),
)
if tasks[0].done:
if tasks[0].finished:
# The given touch is a dragging gesture.
if self._can_be_dragged:
await self._treat_a_touch_as_a_drag(touch, do_transform=True)
Expand Down Expand Up @@ -187,7 +187,7 @@ async def _treat_a_touch_as_a_drag(self, touch, *, do_transform=False, touch_rec

# store the task object so that the user can cancel it
self._drag_task.cancel()
self._drag_task = await ak.get_current_task()
self._drag_task = await ak.current_task()

# actual dragging process
self.dispatch('on_drag_start', touch, ctx)
Expand All @@ -207,11 +207,11 @@ async def _treat_a_touch_as_a_drag(self, touch, *, do_transform=False, touch_rec
else:
r = self.dispatch('on_drag_succeed', touch, ctx)
self.drag_state = 'succeeded'
async with ak.cancel_protection():
async with ak.disable_cancellation():
if isawaitable(r):
await r
await ak.sleep(-1) # This is necessary in order to work with Magnet iirc.
except GeneratorExit:
except ak.Cancelled:
self.dispatch('on_drag_cancel', touch, ctx)
self.drag_state = 'cancelled'
raise
Expand Down

0 comments on commit 041eae8

Please sign in to comment.