ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TileCalorimeter
TileCoolDcs
python
ProgressBar.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
import
sys
4
5
class
progressBar
:
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
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
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
64
def
__str__
(self):
65
return
str(self.
progBar
)
python.ProgressBar.progressBar
Definition
ProgressBar.py:5
python.ProgressBar.progressBar.span
span
Definition
ProgressBar.py:10
python.ProgressBar.progressBar.__str__
__str__(self)
Definition
ProgressBar.py:64
python.ProgressBar.progressBar.amount
int amount
Definition
ProgressBar.py:11
python.ProgressBar.progressBar.width
width
Definition
ProgressBar.py:21
python.ProgressBar.progressBar.suffix
str suffix
Definition
ProgressBar.py:18
python.ProgressBar.progressBar.progBar
str progBar
Definition
ProgressBar.py:7
python.ProgressBar.progressBar.prefix
str prefix
Definition
ProgressBar.py:14
python.ProgressBar.progressBar.__init__
__init__(self, minValue=0, maxValue=10, totalWidth=12, prefix="", suffix="")
Definition
ProgressBar.py:6
python.ProgressBar.progressBar.update
update(self, newAmount=0)
Definition
ProgressBar.py:24
python.ProgressBar.progressBar.done
done(self)
Definition
ProgressBar.py:59
python.ProgressBar.progressBar.max
max
Definition
ProgressBar.py:9
python.ProgressBar.progressBar.nextUpdate
nextUpdate
Definition
ProgressBar.py:12
python.ProgressBar.progressBar.min
min
Definition
ProgressBar.py:8
Generated on
for ATLAS Offline Software by
1.17.0