Last active
March 4, 2020 03:30
-
-
Save GenevieveBuckley/02d6e8299b2210cdd80336a5b44a42c5 to your computer and use it in GitHub Desktop.
Making gooey and tqdm play nice together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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