ATLAS Offline Software
Loading...
Searching...
No Matches
python.ProgressBar.progressBar Class Reference
Collaboration diagram for python.ProgressBar.progressBar:

Public Member Functions

 __init__ (self, minValue=0, maxValue=10, totalWidth=12, prefix="", suffix="")
 update (self, newAmount=0)
 done (self)
 __str__ (self)

Public Attributes

str progBar = "[]"
 min = minValue
 max = maxValue
 span = maxValue - minValue
int amount = 0
 nextUpdate = minValue+float(self.span/100.0)
str prefix = prefix+" ["
str suffix = "] " + suffix
 width = totalWidth - len(self.prefix) - len(self.suffix)

Detailed Description

Definition at line 5 of file ProgressBar.py.

Constructor & Destructor Documentation

◆ __init__()

python.ProgressBar.progressBar.__init__ ( self,
minValue = 0,
maxValue = 10,
totalWidth = 12,
prefix = "",
suffix = "" )

Definition at line 6 of file ProgressBar.py.

6 def __init__(self, minValue = 0, maxValue = 10, totalWidth=12, prefix="", suffix=""):
7 self.progBar = "[]" # This holds the progress bar string
8 self.min = minValue
9 self.max = maxValue
10 self.span = maxValue - minValue
11 self.amount = 0 # When amount == max, we are 100% done
12 self.nextUpdate = minValue+float(self.span/100.0)
13 if len(prefix):
14 self.prefix=prefix+" ["
15 else:
16 self.prefix="["
17 if len(suffix):
18 self.suffix="] " + suffix
19 else:
20 self.suffix="]"
21 self.width = totalWidth - len(self.prefix) - len(self.suffix)
22 self.update(0) # Build progress bar string
23

Member Function Documentation

◆ __str__()

python.ProgressBar.progressBar.__str__ ( self)

Definition at line 64 of file ProgressBar.py.

64 def __str__(self):
65 return str(self.progBar)

◆ done()

python.ProgressBar.progressBar.done ( self)

Definition at line 59 of file ProgressBar.py.

59 def done(self):
60 self.update(self.max)
61 sys.stdout.write('\r' + self.progBar + '\n')
62 sys.stdout.flush()# force updating of screen
63

◆ update()

python.ProgressBar.progressBar.update ( self,
newAmount = 0 )

Definition at line 24 of file ProgressBar.py.

24 def update(self, newAmount = 0):
25 if newAmount < self.min:
26 newAmount = self.min
27 if newAmount > self.max:
28 newAmount = self.max
29
30 #=== only continue if something new to draw
31 if newAmount < self.nextUpdate and newAmount<self.max :
32 return
33 self.nextUpdate = self.nextUpdate+float(self.span/100.0)
34 self.amount = newAmount
35
36 # Figure out the new percent done, round to an integer
37 diffFromMin = float(self.amount - self.min)
38 percentDone = (diffFromMin / float(self.span)) * 100.0 if self.span>0 else 100.
39 percentDone = round(percentDone)
40 percentDone = int(percentDone)
41
42 # Figure out how many hash bars the percentage should be
43 numHashes = (percentDone / 100.0) * self.width
44 numHashes = int(round(numHashes))
45
46 # build a progress bar with hashes and spaces
47 self.progBar = self.prefix + '#'*numHashes + ' '*(self.width-numHashes) + self.suffix
48
49 # figure out where to put the percentage, roughly centered
50 percentPlace = (len(self.progBar) // 2) - len(str(percentDone))
51 percentString = str(percentDone) + "%"
52
53 # slice the percentage into the bar
54 self.progBar = self.progBar[0:percentPlace] + percentString + self.progBar[percentPlace+len(percentString):]
55
56 sys.stdout.write('\r' + self.progBar)
57 sys.stdout.flush()# force updating of screen
58

Member Data Documentation

◆ amount

int python.ProgressBar.progressBar.amount = 0

Definition at line 11 of file ProgressBar.py.

◆ max

python.ProgressBar.progressBar.max = maxValue

Definition at line 9 of file ProgressBar.py.

◆ min

python.ProgressBar.progressBar.min = minValue

Definition at line 8 of file ProgressBar.py.

◆ nextUpdate

python.ProgressBar.progressBar.nextUpdate = minValue+float(self.span/100.0)

Definition at line 12 of file ProgressBar.py.

◆ prefix

str python.ProgressBar.progressBar.prefix = prefix+" ["

Definition at line 14 of file ProgressBar.py.

◆ progBar

python.ProgressBar.progressBar.progBar = "[]"

Definition at line 7 of file ProgressBar.py.

◆ span

python.ProgressBar.progressBar.span = maxValue - minValue

Definition at line 10 of file ProgressBar.py.

◆ suffix

str python.ProgressBar.progressBar.suffix = "] " + suffix

Definition at line 18 of file ProgressBar.py.

◆ width

python.ProgressBar.progressBar.width = totalWidth - len(self.prefix) - len(self.suffix)

Definition at line 21 of file ProgressBar.py.


The documentation for this class was generated from the following file: