Skip to content
This repository has been archived by the owner on Jun 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #57 from rockbass2560/master
Browse files Browse the repository at this point in the history
System updated to support pause and resume actions using a button
  • Loading branch information
Bob123a1 authored Oct 9, 2018
2 parents 46a296c + cceff37 commit 9bd9423
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions CDNSP-GUI-Bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def add_to_installed(tid, ver):
enxhop = False
current_mode = ""
nsp_location = ""
pause_download = False
downloading = False

import os, sys
import re
Expand Down Expand Up @@ -819,10 +821,16 @@ def download_file(url, fPath, fSize=0):

if fSize >= 10000:
t = tqdm(initial=dlded, total=int(fSize), desc=fName, unit='B', unit_scale=True, leave=False, mininterval=0.5)
global downloading
downloading = True
for chunk in r.iter_content(4096):
f.write(chunk)
dlded += len(chunk)
t.update(len(chunk))
if pause_download:
while pause_download:
time.sleep(.5)
downloading = False
t.close()
else:
f.write(r.content)
Expand Down Expand Up @@ -1984,9 +1992,11 @@ def __init__(self, root, titleID, titleKey, title, dbURL, info_list=None):
download_bottom_txt = _("Download")
dl_btn = Button(game_info_frame, text=download_bottom_txt, command=self.download)
dl_btn.grid(row=50, column=1, pady=(20,0), padx=(5,0))
self.pause_btn = Button(game_info_frame, text=("Pause Download"), command=self.pause_download_command)
self.pause_btn.grid(row=51, column=0, pady=(20,0), columnspan=2)

update_btn = Button(game_info_frame, text=_("Update Titlekeys"), command=self.update_titlekeys)
update_btn.grid(row=51, column=0, pady=(20, 0), columnspan=2)
update_btn.grid(row=52, column=0, pady=(20, 0), columnspan=2)

#-----------------------------------------
# Setup GUI Functions
Expand Down Expand Up @@ -2826,8 +2836,22 @@ def threaded_download(self):
return

def download(self):
thread = threading.Thread(target = self.threaded_download)
thread.start()
self.thread = threading.Thread(target = self.threaded_download)
self.thread.start()

def pause_download_command(self):
global pause_download
global downloading
if downloading:
pause_download = not pause_download
if pause_download:
self.pause_btn["text"] = "Resume Download"
print("\nDownload paused, waiting for the user resumes the download again")
else:
self.pause_btn["text"] = "Pause Download"
print("\nDownload resumed")
else:
print("\n There is not a download in progress")

def export_persistent_queue(self):
self.dump_persistent_queue(self.normalize_file_path(filedialog.asksaveasfilename(initialdir = self.path, title = "Select file", filetypes = (("JSON files","*.json"),("all files","*.*")))))
Expand Down

0 comments on commit 9bd9423

Please sign in to comment.