From eb8b581fcffe07f297f513c0029798bfb3072edf Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sat, 15 Sep 2018 13:42:53 -0400 Subject: [PATCH] New featrure - OneLineProgressMeters, New Demo_Progress_Meters --- Demo_Progress_Meters.py | 45 +++++++++++++++++++++++++++++++++++++++++ PySimpleGUI.py | 3 +-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 Demo_Progress_Meters.py diff --git a/Demo_Progress_Meters.py b/Demo_Progress_Meters.py new file mode 100644 index 00000000..9b013e45 --- /dev/null +++ b/Demo_Progress_Meters.py @@ -0,0 +1,45 @@ +from time import sleep +import PySimpleGUI as sg + +""" + Demonstration of multiple OneLineProgressMeter's + + Shows how 2 progress meters can be running at the same time. + Note -- If the user wants to cancel a meter, it's important to use the "Cancel" button, not the X + If the software determined that a meter should be cancelled early, + calling OneLineProgresMeterCancel(key) will cancel the meter with the matching key +""" + +sg.ChangeLookAndFeel('Dark') + +layout = [ + [sg.T('One-Line Progress Meter Demo', font=('Any 18'))], + [sg.T('Outer Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountOuter', do_not_clear=True), + sg.T('Delay'), sg.In(default_text='10', key='TimeOuter', size=(5,1), do_not_clear=True), sg.T('ms')], + [sg.T('Inner Loop Count', size=(15,1), justification='r'), sg.In(default_text='100', size=(5,1), key='CountInner', do_not_clear=True) , + sg.T('Delay'), sg.In(default_text='10', key='TimeInner', size=(5,1), do_not_clear=True), sg.T('ms')], + [sg.SimpleButton('Show', pad=((0,0), 3), bind_return_key=True), sg.T('me the meters!')] + ] + +form = sg.FlexForm('One-Line Progress Meter Demo') +form.Layout(layout) + +while True: + button, values = form.Read() + if button is None: + break + if button == 'Show': + max_outer = int(values['CountOuter']) + max_inner = int(values['CountInner']) + delay_inner = int(values['TimeInner']) + delay_outer = int(values['TimeOuter']) + for i in range(max_outer): + if not sg.OneLineProgressMeter('Outer Loop', i+1, max_outer, 'outer'): + break + sleep(delay_outer/1000) + for j in range(max_inner): + if not sg.OneLineProgressMeter('Inner Loop', j+1, max_inner, 'inner'): + break + sleep(delay_inner/1000) + +exit(69) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index d2a05608..0c215650 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -3127,7 +3127,7 @@ def EasyProgressMeterCancel(title, *args): _one_line_progress_meters = {} # ============================== OneLineProgressMeter =====# -def OneLineProgressMeter(title, current_value, max_value, *args, orientation=None, bar_color=(None,None), button_color=None, size=DEFAULT_PROGRESS_BAR_SIZE, scale=(None, None), border_width=None, key=None): +def OneLineProgressMeter(title, current_value, max_value, key, *args, orientation=None, bar_color=(None,None), button_color=None, size=DEFAULT_PROGRESS_BAR_SIZE, scale=(None, None), border_width=None): global _one_line_progress_meters @@ -3162,7 +3162,6 @@ def OneLineProgressMeter(title, current_value, max_value, *args, orientation=Non if current_value >= meter_data.MaxValue or not rc: del _one_line_progress_meters[key] return False - return rc # return whatever the update told us