def init_download(self):
'''
Gets checkboxes state and adds it to query.
Starts threading
'''
for choice in self.choices:
if (choice.enabled.get()) and ((choice.tag in to_download) == False):
to_download.append(choice)
elif (choice.enabled.get() == False) and (choice.tag in to_download):
to_download.remove(choice)
self.thread = threading.Thread(target=self.queue)
self.thread.daemon = True
self.thread.start()
def queue(self):
'''
-Setups ui disable checkboxes and place downloading widgets
-Starts downloading from queue
'''
self.label_status['text'] = "Preparing queue"
if to_download == []:
self.label_path["text"] = "You need to select item to download"
return False
self.button_start.destroy()
self.label_path.destroy()
self.progressbar.place(x=30, y=525, width=740, height=10)
self.label_eta.place(x=26, y=540)
self.label_speed.place(x=690, y=540, width=100)
self.label_status.place(x=30, y=500, width=740, height=20)
self.label_status["text"] = "Preparing queue... | {0} items in queue)".format(
len(to_download)
)
self.disable_checkboxes()
for con in to_download:
self.start_download(con)
def start_download(self, content):
'''
Starts downloading and update widgets (eta, speed and status)
'''
if "mediafire" in content.url:
content.url = tools.scrap_mediafire(content.url)
downloader = SmartDL(content.url, gmod_dir, progress_bar=False)
try:
downloader.start(blocking=False)
except:
self.label_status["text"] = "Cant reach {}".format(content.name)
self.button_action.place(x=380, y=545)
while not downloader.isFinished():
if is_close:
break
self.label_speed["text"] = downloader.get_speed(human=True)
self.label_eta["text"] = downloader.get_eta(human=True)
self.progressbar["value"] = downloader.get_progress()*100
self.label_status["text"] = ("{} {} ({}/{}) | {} files in queue").format(
downloader.get_status(),
content.name,
downloader.get_dl_size(human=True),
tools.size_format(downloader.filesize),
str(len(to_download))
)
sleep(0.2)
if is_close:
return True
if downloader.isSuccessful():
self.label_status["text"] = "Downloading {} completed".format(
content.name)
to_download.remove(content)
self.label_status["text"] = "Unziping..."
is_unzipped = tools.unzip(content.url, gmod_dir)
if is_unzipped[0]:
self.label_status["text"] = "Completed {}".format(content.name)
else:
self.label_status["text"] = "Unziping {} FAILED! You have to unzip it manualy.".format(
is_unzipped[1]
)
if to_download == []:
self.button_action["text"] = "Exit"
print(to_download)
return True
else:
self.label_status["text"] = "Downloading {} FAILED!".format(
content.name)
return False