Skip to content

Commit

Permalink
made status into a thread class, added resume features
Browse files Browse the repository at this point in the history
  • Loading branch information
akai-katto committed Dec 28, 2019
1 parent f6f1ad5 commit 49706d0
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions src/dandere2xlib/status.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,71 @@
import sys
import time
import threading

from context import Context
from dandere2xlib.utils.thread_utils import CancellationToken


# todo
# This could probably be improved visually for the user.. it's not the most pleasing to look at
# Also, in a very niche case the GUI didn't catch up with the deletion of files, so it ceased updating

def print_status(context: Context):
workspace = context.workspace
extension_type = context.extension_type
frame_count = context.frame_count

last_10 = [0]
class Status(threading.Thread):

for x in range(1, frame_count - 1):
percent = int((x / frame_count) * 100)
def __init__(self, context: Context):
self.context = context
self.workspace = context.workspace
self.extension_type = context.extension_type
self.frame_count = context.frame_count
self.is_alive = True
self._is_stopped = False
self.start_frame = 1

average = 0
for time_count in last_10:
average = average + time_count
# Threading Specific

average = round(average / len(last_10), 2)
self.alive = True
self.cancel_token = CancellationToken()
self._stopevent = threading.Event()
threading.Thread.__init__(self, name="StatusTHread")

sys.stdout.write('\r')
sys.stdout.write("Frame: [%s] %i%% Average of Last 10 Frames: %s sec / frame" % (x, percent, average))

if len(last_10) == 10:
last_10.pop(0)
def join(self, timeout=None):
threading.Thread.join(self, timeout)

now = time.time()
def kill(self):
self.alive = False
self.cancel_token.cancel()
self._stopevent.set()

while x >= context.signal_merged_count:
time.sleep(.00001)
def set_resume_frame(self, resume_frame: int):
self.start_frame = resume_frame

def run(self):

last_10 = [0]

for x in range(self.start_frame, self.frame_count - 1):

if not self.is_alive:
break

percent = int((x / self.frame_count) * 100)

average = 0
for time_count in last_10:
average = average + time_count

average = round(average / len(last_10), 2)

sys.stdout.write('\r')
sys.stdout.write("Frame: [%s] %i%% Average of Last 10 Frames: %s sec / frame" % (x, percent, average))

if len(last_10) == 10:
last_10.pop(0)

now = time.time()

while x >= self.context.signal_merged_count and self.alive:
time.sleep(.00001)

later = time.time()
difference = float(later - now)
last_10.append(difference)

0 comments on commit 49706d0

Please sign in to comment.