Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gottadiveintopython committed Aug 28, 2023
1 parent 3fc8988 commit f6c31d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 5 additions & 7 deletions examples/reacting_to_entering_and_leaving.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kivy.utils import reify
from functools import cached_property
from kivy.properties import NumericProperty
from kivy.app import App
from kivy.lang import Builder
Expand Down Expand Up @@ -95,7 +95,7 @@ class ReactiveDroppableBehavior(KXDroppableBehavior):
'''
__events__ = ('on_drag_enter', 'on_drag_leave', )

@reify
@cached_property
def __ud_key(self):
return 'ReactiveDroppableBehavior.' + str(self.uid)

Expand All @@ -107,9 +107,7 @@ def on_touch_move(self, touch):
if drag_cls is not None:
touch_ud[ud_key] = None
if drag_cls in self.drag_classes:
# Start watching the touch. Use ``ak.or_()`` so that ``_watch_touch()`` will be automatically
# cancelled when the drag is cancelled.
ak.start(ak.or_(
ak.start(ak.wait_any(
self._watch_touch(touch),
ak.event(touch.ud['kivyx_draggable'], 'on_drag_end'),
))
Expand All @@ -122,8 +120,8 @@ async def _watch_touch(self, touch):

self.dispatch('on_drag_enter', touch, ctx, draggable)
try:
async with ak.watch_touch(self, touch) as is_touch_move:
while await is_touch_move():
async with ak.watch_touch(self, touch) as in_progress:
while await in_progress():
if not collide_point(*touch.pos):
return
finally:
Expand Down
7 changes: 3 additions & 4 deletions examples/reorderable_stacklayout.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'''
When you want to make ``StackLayout`` re-orderable, you may want to disable
the ``size_hint`` of each child, or may want to limit the maximum size of
each child, otherwise the layout may be messed up. You can confirm it by
commenting/uncommenting the ``SampleApp.on_start()``'s body.
When you want to make a :class:`kivy.uix.stacklayout.StackLayout` re-orderable, you may want to disable the
``size_hint`` of each child, or may want to limit the maximum size of each child, otherwise the layout will be messed
up. You can confirm that by commenting/uncommenting the part of ``SampleApp.on_start()``.
'''

from kivy.lang import Builder
Expand Down
10 changes: 4 additions & 6 deletions src/kivy_garden/draggable/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def start_dragging_from_others_touch(self, receiver: Widget, touch):
---------
* ``receiver`` ... The widget that received the ``touch``.
* ``touch`` ... A touch that is going to drag me.
* ``touch`` ... The touch that is going to drag me.
'''
if touch.time_end != -1:
return
Expand Down Expand Up @@ -370,9 +370,7 @@ def on_touch_move(self, touch):
if drag_cls is not None:
touch_ud[ud_key] = None
if drag_cls in self.drag_classes:
# Start watching the touch. Use ``ak.or_()`` so that ``_watch_touch()`` will be automatically
# cancelled when the drag is cancelled.
ak.start(ak.or_(
ak.start(ak.wait_any(
self._watch_touch(touch),
ak.event(touch.ud['kivyx_draggable'], 'on_drag_end'),
))
Expand All @@ -395,8 +393,8 @@ async def _watch_touch(self, touch):
touch_ud['kivyx_drag_ctx'].original_state,
ignore_parent=True)
add_widget(spacer)
async with ak.watch_touch(self, touch) as is_touch_move:
while await is_touch_move():
async with ak.watch_touch(self, touch) as in_progress:
while await in_progress():
x, y = touch.pos
if collide_point(x, y):
new_idx = get_drop_insertion_index_move(x, y, spacer)
Expand Down

0 comments on commit f6c31d7

Please sign in to comment.