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.
Moved properties above methods in Repeat class.

Changed property names of Repeat to be more conform.
  • Loading branch information
satoon101 committed Oct 22, 2016
commit f205f76257abfb8b1830e620643655218fee6d65
188 changes: 94 additions & 94 deletions addons/source-python/packages/source-python/listeners/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,95 @@ def __init__(
self._delay = None
self._loop_time = None

@property
def loops_remaining(self):
"""Return the remaining number of loops in the repeat.

:rtype: int
"""
# Is there no limit?
if not self._limit:

# Return the limit
return self._limit

# Return the remaining number of loops
return self.total_loops - self._count

@property
def loops_elapsed(self):
"""Return the current number of loops made in the repeat.

:rtype: int
"""
return self._count

@property
def total_loops(self):
"""Return the total number of loops to be made.

:rtype: int
"""
# Is there no limit?
if not self._limit:

# Return the limit
return self._limit

# Return the adjusted limit
return self._limit + self._adjusted

@property
def total_time_remaining(self):
"""Return the remaining time till the end of the repeat.

:rtype: float
"""
return (
self.loops_remaining * self._interval +
self.delay_time_remaining
)

@property
def total_time_elapsed(self):
"""Return the elapsed time since the repeat started.

:rtype: float
"""
return self.total_time - self.total_time_remaining

@property
def total_time(self):
"""Return the total time it will take to complete the repeat.

:rtype: float
"""
return self.total_loops * self._interval

@property
def delay_time_remaining(self):
"""Return the time remaining in the current loop.

:rtype: float
"""
return self._delay.time_remaining

@property
def delay_time_elapsed(self):
"""Return the time elapsed in the current loop.

:rtype: float
"""
return self._delay.time_elapsed

@property
def status(self):
"""Return the status of the repeat.

:rtype: RepeatStatus
"""
return self._status

def start(self, interval, limit, execute_on_start=False):
"""Start the repeat loop.

Expand Down Expand Up @@ -397,7 +486,7 @@ def extend(self, adjustment):
listeners_tick_logger.log_debug('Repeat.extend')

# Is there a limit for this repeat?
if not self.loop_limit:
if not self.total_loops:

# Log a message about no reducing
listeners_tick_logger.log_debug(
Expand Down Expand Up @@ -426,7 +515,7 @@ def reduce(self, adjustment):
listeners_tick_logger.log_debug('Repeat.reduce')

# Is there a limit for this repeat?
if not self.loop_limit:
if not self.total_loops:

# Log a message about no reducing
listeners_tick_logger.log_debug(
Expand All @@ -445,7 +534,7 @@ def reduce(self, adjustment):
self._adjusted -= adjustment

# Are no more loops to be made?
if (self.remaining_loops <= 0 and
if (self.loops_remaining <= 0 and
self.status is RepeatStatus.RUNNING):

# Log the reduce-stopping message
Expand All @@ -464,7 +553,7 @@ def _execute(self):
self._count += 1

# Are any more loops to be made?
if self.remaining_loops or not self._limit:
if self.loops_remaining or not self._limit:

# Is there no limit?
if not self._limit:
Expand All @@ -479,7 +568,7 @@ def _execute(self):
# Log continuing the loop
listeners_tick_logger.log_debug(
'Repeat._execute - Remaining - {0}'.format(
self.remaining_loops))
self.loops_remaining))

# Call the delay again
self._delay = Delay(
Expand All @@ -500,95 +589,6 @@ def _execute(self):
# Call the repeat's callback
self.callback(*self.args, **self.kwargs)

@property
def remaining_loops(self):
"""Return the remaining number of loops in the repeat.

:rtype: int
"""
# Is there no limit?
if not self._limit:

# Return the limit
return self._limit

# Return the remaining number of loops
return self.loop_limit - self._count

@property
def loop_count(self):
"""Return the current number of loops made in the repeat.

:rtype: int
"""
return self._count

@property
def loop_limit(self):
"""Return the total number of loops to be made.

:rtype: int
"""
# Is there no limit?
if not self._limit:

# Return the limit
return self._limit

# Return the adjusted limit
return self._limit + self._adjusted

@property
def time_left(self):
"""Return the remaining time till the end of the repeat.

:rtype: float
"""
return (
self.remaining_loops * self._interval +
self.delay_time_remaining
)

@property
def time_elapsed(self):
"""Return the elapsed time since the repeat started.

:rtype: float
"""
return self.total_time - self.time_left

@property
def total_time(self):
"""Return the total time it will take to complete the repeat.

:rtype: float
"""
return self.loop_limit * self._interval

@property
def status(self):
"""Return the status of the repeat.

:rtype: RepeatStatus
"""
return self._status

@property
def delay_time_remaining(self):
"""Return the time remaining in the current loop.

:rtype: float
"""
return self._delay.time_remaining

@property
def delay_time_elapsed(self):
"""Return the time elapsed in the current loop.

:rtype: float
"""
return self._delay.time_elapsed

def _unload_instance(self):
"""Stop the repeat with being unloaded."""
self.stop()
Expand Down