Skip to content
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

gui toolkit-specific progress bar? #297

Open
anntzer opened this issue Oct 27, 2016 · 6 comments
Open

gui toolkit-specific progress bar? #297

anntzer opened this issue Oct 27, 2016 · 6 comments
Labels
p3-enhancement 🔥 Much new such feature p4-enhancement-future 🧨 On the back burner submodule ⊂ Periphery/subclasses

Comments

@anntzer
Copy link
Contributor

anntzer commented Oct 27, 2016

It would be nice if tqdm could rely on a gui toolkit's native progress bar (say, Tk/Qt/Gtk) rather than on matplotlib, which is a pretty large beast (additionally, I think that the matplotlib gui progressbar provides way too much information by default -- I asked for a progress bar, not a full plot of the history of the iteration :-)).

@casperdcl
Copy link
Sponsor Member

hey, feel free to implement one in any of your preferred GUI. the matplotlib one was just my hacky example of how you can use tqdm as a backend for anything.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 27, 2016

I looked into _tqdm_gui.py and it seems that there is a lot of things being done there that may or may not be relevant to my case. Is the API that a backend must implement documented somewhere?

@lrq3000
Copy link
Member

lrq3000 commented Oct 28, 2016

There will be a new simpler API with the bar_format PR that is coming, you
won't have to reimplement everything, just the GUI display and callbacks to
tqdm. The matplotlib example is a very integrated example so it's very
efficient, the callback API will be less efficient but it will be simpler.

I'll give you more details tomorrow.

2016-10-28 0:11 GMT+02:00 Antony Lee notifications@github.com:

I looked into _tqdm_gui.py and it seems that there is a lot of things
being done there that may or may not be relevant to my case. Is the API
that a backend must implement documented somewhere?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#297 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABES3jwWuZsrkklMwr6cuD8V68grwz4Sks5q4SF2gaJpZM4Kh-o0
.

@notpushkin
Copy link

I've tried to make a basic Tk GUI, although it certainly isn't feature-complete and also very hacky as it forks another process to display the window. You can take a look: https://github.com/iamale/tqdm/blob/master/tqdm/_tqdm_tk.py

@lrq3000
Copy link
Member

lrq3000 commented Oct 29, 2016

@iamale Thank you, very nice! Can you do a PR so that we integrate it in tqdm?

@anntzer and @iamale : to make GUI interfaces with tqdm, you can base your own tqdm submodule on PR #223 (branch custom_symbols).

Here is the documentation relevant to this PR:

Integration in a GUI

tqdm can easily be integrated in your own GUI by providing bar_format with a callback function that will update your GUI bar display:

from tqdm import tqdm
from time import sleep
from awesome import GUI

class my_gui_bar(object):
    '''Toy GUI bar'''
    def __init__(self):
        self.gui_bar = GUI()
        self.gui_bar.init()
        # etc.

    def update(self, bar_args={}):
        '''Callback for tqdm to update the bar display'''
        self.gui_bar.set_text = "{n_fmt}/{n_total} [{elapsed}>{remaining}]".format(bar_args)
        self.gui_bar.set_progress = bar_args['n']

gbar = my_gui_bar()
for i in tqdm(range(100), bar_format=gbar.update):
    sleep(0.1)

Note the bar_format=gbar.update in the tqdm() call: this is the key new feature of the PR #223. By providing a callback, everytime tqdm gets called it's tqdm that will directly callback your GUI function. This way, you don't have to manage the internals of bar looping nor refresh rate, tqdm does it all. You just need to provide a function or method (the callback) that will receive tqdm updates so that you can display on your GUI (the update() method above).

@lrq3000 lrq3000 added p3-enhancement 🔥 Much new such feature p4-enhancement-future 🧨 On the back burner submodule ⊂ Periphery/subclasses labels Oct 29, 2016
@hildogjr
Copy link

Could this discussion be merged with #172?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-enhancement 🔥 Much new such feature p4-enhancement-future 🧨 On the back burner submodule ⊂ Periphery/subclasses
Projects
None yet
Development

No branches or pull requests

5 participants