chriskiehl / Gooey

Turn (almost) any Python command line program into a full GUI application with one line
MIT License
20.69k stars 1.02k forks source link

Progress bar time remaining goes missing when progress_regex not a match #864

Open simularis opened 1 year ago

simularis commented 1 year ago

Minimal code example

from time import sleep
from gooey import Gooey, GooeyParser
from itertools import cycle

@Gooey(
    terminal_font_family='Courier New',
    progress_regex=r"^progress: (?P<current>-?\d+)/(?P<total>\d+)$",
    progress_expr="current / total * 100",
    timing_options={
        'show_time_remaining':True,
        'hide_time_remaining_on_complete':False
    })
def parse_args():
    parser = GooeyParser(prog="example_progress_bar_5")
    parser.add_argument("alpha", type=float, help="Seconds per 10% progress", default=1)
    parser.add_argument("beta", type=int, help="Extra messages between progress updates",default=3)
    parser.add_argument("gamma", type=str, nargs='+', help="List of your messages",
        default=["info ...", "message ...", "warning ..."])
    args = parser.parse_args()
    return args.alpha, args.beta, args.gamma

def main():
    alpha, beta, gamma = parse_args()
    myprocess = cycle(gamma)

    print("Step 1")
    for i in range(0, 51, 10):
        sleep(alpha)
        print("progress: {}/{}".format(i,100),flush=True)

    print("Step 2")
    for i in range(50, 101, 10):
        sleep(alpha / (beta+1))
        for j in range(beta):
            # some extra text before progress
            print(next(myprocess),flush=True)
            sleep(alpha / (beta+1))
        print("progress: {}/{}".format(i,100),flush=True)

if __name__ == "__main__":
    main()

Screenshots

What Screenshot
Console Screenshot 2022-12-15 172822
Progress bar during step 1 (progress messages only) Screenshot 2022-12-15 172725
Progress bar during step 2 (progress messages and other messages) Screenshot 2022-12-15 172751

Relevant excerpts

ProcessController

https://github.com/chriskiehl/Gooey/blob/be4b11b8f27f500e7326711641755ad44576d408/gooey/gui/processor.py#L114-L129

https://github.com/chriskiehl/Gooey/blob/a451f5265a405951be367217ef8363bf88a46176/gooey/gui/processor.py#L152-L162

Timing

https://github.com/chriskiehl/Gooey/blob/a451f5265a405951be367217ef8363bf88a46176/gooey/gui/util/time.py#L19-L25

Suggested fix

Update gooey/gui/util/time.py:

@@ -19,7 +19,7 @@ class Timing(object):
     def _updateEstimate(self, *args, **kwargs):
         prog = kwargs.get('progress')
         if(not prog): 
-            self.estimatedRemaining = None
+            # self.estimatedRemaining = None
             return
         if(prog > 0):
             self.estimatedRemaining = estimate_time_remaining(prog,self.startTime)