File: ProgressDialog.py

package info (click to toggle)
python-pyqtgraph 0.13.7-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,072 kB
  • sloc: python: 54,043; makefile: 127; ansic: 40; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Using ProgressDialog to show progress updates in a nested process.

"""

import time

import pyqtgraph as pg

app = pg.mkQApp("Progress Dialog Example")


def runStage(i):
    """Waste time for 2 seconds while incrementing a progress bar.
    """
    with pg.ProgressDialog("Running stage %s.." % i, maximum=100, nested=True) as dlg:
        for j in range(100):
            time.sleep(0.02)
            dlg += 1
            if dlg.wasCanceled():
                print("Canceled stage %s" % i)
                break


def runManyStages(i):
    """Iterate over runStage() 3 times while incrementing a progress bar.
    """
    with pg.ProgressDialog("Running stage %s.." % i, maximum=3, nested=True, wait=0) as dlg:
        for j in range(1,4):
            runStage('%d.%d' % (i, j))
            dlg += 1
            if dlg.wasCanceled():
                print("Canceled stage %s" % i)
                break


with pg.ProgressDialog("Doing a multi-stage process..", maximum=5, nested=True, wait=0) as dlg1:
    for i in range(1,6):
        if i == 3:
            # this stage will have 3 nested progress bars
            runManyStages(i)
        else:
            # this stage will have 2 nested progress bars
            runStage(i)
        
        dlg1 += 1
        if dlg1.wasCanceled():
            print("Canceled process")
            break