-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add support to an user defined progress bar inside download function. #241
base: main
Are you sure you want to change the base?
Conversation
gdown/download.py
Outdated
pbar.update(len(chunk)) | ||
else: | ||
chunk_count += len(chunk) | ||
bar(chunk_count, total) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can make bar as the same api as tqdm.tqdm? and rename it to pbar in the argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @wkentaro. Do you mean have the attributes update
and close
like tqdm or just a function with one parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jcfaracco. Yeah, I don't mind dropping tqdm
if there is an ultimate API to support pbar
as function argument.
I wonder how the other libraries are doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we analyze progress, we can see a similar approach to tqdm but using different function names. Again, I'm not proposing to drop tqdm, just the ability to use a user-defined pbar. For example, mine is a ipywidget that unfortunately does not work well with tqdm :-( I would love to use gdown with my widget. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example of progress. To understand more deeply about your needs, can you give me a short snippet of how you want to use with ipywidget?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @wkentaro
This is some simple example
import threading
from IPython import display as disp
from ipywidgets import HBox, FloatProgress, Label
class NotebookProgressBar(threading.Thread):
MIN_CUR = -2
MIN_TOTAL = -1
def __init__(self):
threading.Thread.__init__(self)
self.bar = None
self.percentage = None
self.data = None
self.__lock = threading.Lock()
self.__current = self.MIN_CUR
self.__total = self.MIN_TOTAL
self.__error = False
def show(self):
self.bar = FloatProgress(value=0, min=0, max=100)
self.percentage = Label(value='0 %')
self.data = Label(value='')
box = HBox((self.percentage, self.bar, self.data))
disp.display(box)
def set_current(self, current, total):
with self.__lock:
self.__current = current
self.__total = total
def set_error(self, error):
self.__error = error
def run(self):
while (not self.__error and self.__current < self.__total):
time.sleep(1)
if self.__current != self.MIN_CUR and self.__total != self.MIN_TOTAL:
progress = (self.__current / self.__total) * 100
self.bar.value = progress
self.percentage.value = f"{int(self.bar.value)} %%"
self.data.value = f"{int(self.__current)} / {int(self.__total)}"
if not self.__error:
self.bar.style.bar_color = '#03c04a'
else:
self.bar.style.bar_color = '#ff0000'
All I need to do is update the bar with set_current()
method. I usually use with wget, but this module does not work properly with Google Files for obvious reasons.
What is the status of this pull request? would like to use a progress bar in my python app. |
I think I can jump back to this feature, because I still need it @wkentaro. I also updated the PR description. |
This commit just introduces a new argument to the download function: `bar`. The argument let the person who is developing code define his own progress bar using whatever he wants to. It also requires the pattern of passing the current size of the downloaded chunk. This callable function respects the tqdm API. Signed-off-by: Julio Faracco <[email protected]>
This commit just introduces a new argument to the download function:
bar
. The argument let the person who is developing code define his own progress bar using whatever he wants to. It also requires the pattern of passing the current size of the file and the total size.An external function should be defined like
And then used as:
Signed-off-by: Julio Faracco [email protected]