Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/asynckivy/_etc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ async def rotate_widget(widget, *, angle=360.):
with sync_attr((widget, 'x'), (obj, 'xx')):
assert widget.x == obj.xx
'''
__slots__ = ("__exit__", )
__slots__ = ("_exit", )

def __init__(self, from_: tuple[EventDispatcher, str], to_: tuple[T.Any, str]):
setattr(*to_, getattr(*from_))
bind_uid = from_[0].fbind(from_[1], partial(self._sync, setattr, *to_))
self.__exit__ = partial(self._unbind, *from_, bind_uid)
self._exit = partial(self._unbind, *from_, bind_uid)

@staticmethod
def _sync(setattr, obj, attr_name, event_dispatcher, new_value):
Expand All @@ -197,6 +197,9 @@ def _unbind(event_dispatcher, event_name, bind_uid, *__):
def __enter__(self):
pass

def __exit__(self, *__):
self._exit()


class sync_attrs:
'''
Expand Down Expand Up @@ -248,13 +251,13 @@ async def scale_and_rotate_widget(widget, *, scale=2.0, angle=360.):
with sync_attrs((widget, 'x'), (obj, 'xx')):
assert widget.x is obj.xx
'''
__slots__ = ("__exit__", )
__slots__ = ("_exit", )

def __init__(self, from_: tuple[EventDispatcher, str], *to_):
sync = partial(self._sync, setattr, to_)
sync(None, getattr(*from_))
bind_uid = from_[0].fbind(from_[1], sync)
self.__exit__ = partial(self._unbind, *from_, bind_uid)
self._exit = partial(self._unbind, *from_, bind_uid)

@staticmethod
def _sync(setattr, to_, event_dispatcher, new_value):
Expand All @@ -266,6 +269,9 @@ def _sync(setattr, to_, event_dispatcher, new_value):
def __enter__(self):
pass

def __exit__(self, *__):
self._exit()


class smooth_attr:
'''
Expand Down Expand Up @@ -307,7 +313,7 @@ class smooth_attr:

.. versionadded:: 0.8.0
'''
__slots__ = ("__exit__", )
__slots__ = ("_exit", )
_NUMERIC_TYPES = (P.NumericProperty, P.BoundedNumericProperty, )
_SEQUENCE_TYPES = (P.ColorProperty, P.ReferenceListProperty, P.ListProperty, )

Expand All @@ -325,7 +331,7 @@ def __init__(self, target: tuple[EventDispatcher, str], follower: tuple[T.Any, s
partial(update, *target, *follower, -speed, -min_diff, min_diff), 0
)
bind_uid = target_obj.fbind(target_attr, trigger)
self.__exit__ = partial(self._cleanup, trigger, target_obj, target_attr, bind_uid)
self._exit = partial(self._cleanup, trigger, target_obj, target_attr, bind_uid)

@staticmethod
def _cleanup(trigger, target_obj, target_attr, bind_uid, *__):
Expand All @@ -335,6 +341,9 @@ def _cleanup(trigger, target_obj, target_attr, bind_uid, *__):
def __enter__(self):
pass

def __exit__(self, *__):
self._exit()

def _update_follower(getattr, setattr, math_exp, target_obj, target_attr, follower_obj, follower_attr,
negative_speed, min, max, dt):
t_value = getattr(target_obj, target_attr)
Expand Down