Skip to content

Tick Repeat/Delay updates #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 4, 2016
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix for issue #145.
Updated doc strings for Delay/Repeat changes.

Updated Repeat argument structure to match Delay's new structure.

Changed args to use tuple() as it is immutable and should work fine in place of None.
  • Loading branch information
satoon101 committed Sep 23, 2016
commit bf006a12fb29f9fbac6ac1922cfa0e38c018a613
24 changes: 13 additions & 11 deletions addons/source-python/packages/source-python/listeners/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ class Delay(WeakAutoUnload):
"""Execute a callback after a given delay."""

def __init__(
self, delay, callback, args=None, kwargs=None, cancel_on_map_end=False
self, delay, callback, args=(), kwargs=None, cancel_on_map_end=False
):
"""Initialize the delay.

:param float delay: The delay in seconds.
:param callback: A callable object that should be called after the
delay expired.
:param tuple args: Arguments that should be passed to the callback.
:param dict kwargs: Keyword arguments that should be passed to the
callback.
:param bool cancel_on_map_end: Whether or not to cancel the delay at
the end of the map.
:param args: Arguments that should be passed to the callback.
:param kwargs: Keyword arguments that should be passed to the
callback.
:raises ValueError: If the given callback is not callable.
"""
if not callable(callback):
Expand All @@ -131,7 +131,7 @@ def __init__(
self._start_time = time.time()
self.exec_time = self._start_time + delay
self.callback = callback
self.args = args if args is not None else tuple()
self.args = args
self.kwargs = kwargs if kwargs is not None else dict()
self.cancel_on_map_end = cancel_on_map_end
_delay_manager.add(self)
Expand Down Expand Up @@ -205,22 +205,24 @@ class RepeatStatus(IntEnum):
class Repeat(AutoUnload):
"""Class used to create and call repeats."""

def __init__(self, callback, cancel_on_map_end=False, *args, **kwargs):
def __init__(
self, callback, args=(), kwargs=None, cancel_on_map_end=False
):
"""Store all instance attributes.

:param callback: A callable object that should be called at the
end of each loop.
:param tuple args: Arguments that should be passed to the callback.
:param dict kwargs: Keyword arguments that should be passed to the
callback.
:param bool cancel_on_map_end: Whether or not to cancel the repeat at
the end of the map.
:param args: Arguments that should be passed to the callback.
:param kwargs: Keyword arguments that should be passed to the
callback.
"""
# Store the base attributes
self.callback = callback
self.cancel_on_map_end = cancel_on_map_end
self.args = args
self.kwargs = kwargs
self.kwargs = kwargs if kwargs is not None else dict()
self.cancel_on_map_end = cancel_on_map_end

# Log the __init__ message
listeners_tick_logger.log_debug(
Expand Down