Skip to content

Instantly share code, notes, and snippets.

@GenevieveBuckley
Last active March 4, 2020 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GenevieveBuckley/02d6e8299b2210cdd80336a5b44a42c5 to your computer and use it in GitHub Desktop.
Save GenevieveBuckley/02d6e8299b2210cdd80336a5b44a42c5 to your computer and use it in GitHub Desktop.
Making gooey and tqdm play nice together
from contextlib import redirect_stderr
import io
import time
import sys
from tqdm import tqdm
from gooey import Gooey, GooeyParser
@Gooey(progress_regex=r"(\d+)%")
def main():
parser = GooeyParser(prog="example_progress_bar_1")
_ = parser.parse_args(sys.argv[1:])
f = io.StringIO()
with redirect_stderr(f):
for i in tqdm(range(21)):
prog = f.getvalue().split('\r ')[-1].strip()
print(prog)
time.sleep(0.2)
if __name__ == "__main__":
sys.exit(main())
from contextlib import redirect_stderr
import io
import time
import sys
from tqdm import tqdm
from gooey import Gooey, GooeyParser
@Gooey(progress_regex=r"(\d+)%")
def main():
parser = GooeyParser(prog="example_progress_bar_1")
_ = parser.parse_args(sys.argv[1:])
progress_bar_output = io.StringIO()
with redirect_stderr(progress_bar_output):
for x in tqdm(range(0, 100, 10), file=sys.stdout):
print(progress_bar_output.read())
time.sleep(0.2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment