import time
from threading import Thread

class JobProgressTicker(Thread):
    
    def __init__(self, MainGui):
        Thread.__init__(self)
        self.daemon = True
        self.progress_ticker_list = []
        self.MainGui = MainGui
        self.ticker_running = False
        self.abort = False
        self.run_count = 0
        self.started = False
    
    def run(self):
        self.abort = False
        self.ticker_status_update()
        
    def add_to_progress_ticker(self,update):
        time.sleep(0.1)
        if self.abort == False:
            self.progress_ticker_list.append(update)
        
    def sub_status_update(self, status):
        self.MainGui.progressSubStatusLabel.setText(status)
    
    def abort_thread(self, status=True):
        self.abort = status
    
    def ticker_status_update(self):
        if self.ticker_running == False:
            self.ticker_running = True
            while self.abort == False:
                self.updated = 0
                if len(self.progress_ticker_list) > 0:
                    self.sub_status_update(self.progress_ticker_list[0])
                    self.progress_ticker_list.pop(0)
                    time.sleep(0.7)
                    self.updated = self.updated +1
                if self.updated == 0:
                    time.sleep(0.5)
                self.run_count = self.run_count + 1
            self.ticker_running == False
            print("Ticker Complete!")