Aluode/PerceptionLabPortable
0
1"""2Using ProgressDialog to show progress updates in a nested process.3 4"""5 6import time7 8import pyqtgraph as pg9 10app = pg.mkQApp("Progress Dialog Example")11 12 13def runStage(i):14 """Waste time for 2 seconds while incrementing a progress bar.15 """16 with pg.ProgressDialog("Running stage %s.." % i, maximum=100, nested=True) as dlg:17 for j in range(100):18 time.sleep(0.02)19 dlg += 120 if dlg.wasCanceled():21 print("Canceled stage %s" % i)22 break23 24 25def runManyStages(i):26 """Iterate over runStage() 3 times while incrementing a progress bar.27 """28 with pg.ProgressDialog("Running stage %s.." % i, maximum=3, nested=True, wait=0) as dlg:29 for j in range(1,4):30 runStage('%d.%d' % (i, j))31 dlg += 132 if dlg.wasCanceled():33 print("Canceled stage %s" % i)34 break35 36 37with pg.ProgressDialog("Doing a multi-stage process..", maximum=5, nested=True, wait=0) as dlg1:38 for i in range(1,6):39 if i == 3:40 # this stage will have 3 nested progress bars41 runManyStages(i)42 else:43 # this stage will have 2 nested progress bars44 runStage(i)45 46 dlg1 += 147 if dlg1.wasCanceled():48 print("Canceled process")49 break50 