summaryrefslogtreecommitdiffstats
path: root/glances/outputs/glances_bars.py
diff options
context:
space:
mode:
authorAlessio Sergi <al3hex@gmail.com>2015-03-10 17:00:00 +0100
committerAlessio Sergi <al3hex@gmail.com>2015-03-10 17:00:00 +0100
commit308a8b6b50e540711a02437e4a5105fcc49ef114 (patch)
tree849344ba887c7aa74e6409a065560a7e33e45570 /glances/outputs/glances_bars.py
parent0a0fed767e1e11a0190ed958cd2baa58ee5832ae (diff)
Replace getters/setters with properties - Round 5
Diffstat (limited to 'glances/outputs/glances_bars.py')
-rw-r--r--glances/outputs/glances_bars.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py
index 492b14ac..f149fef3 100644
--- a/glances/outputs/glances_bars.py
+++ b/glances/outputs/glances_bars.py
@@ -33,7 +33,7 @@ class Bar(object):
import time
b = Bar(10)
for p in range(0, 100):
- b.set_percent(p)
+ b.percent = p
print("\r%s" % b),
time.sleep(0.1)
sys.stdout.flush()
@@ -55,32 +55,36 @@ class Bar(object):
self.__empty_char = empty_char
self.__with_text = with_text
- def get_size(self, with_decoration=False):
+ @property
+ def size(self, with_decoration=False):
# Return the bar size, with or without decoration
if with_decoration:
return self.__size
if self.__with_text:
return self.__size - 6
- def set_size(self, size):
- self.__size = size
+ # @size.setter
+ # def size(self, value):
+ # self.__size = value
- def get_percent(self):
+ @property
+ def percent(self):
return self.__percent
- def set_percent(self, percent):
- assert percent >= 0
- assert percent <= 100
- self.__percent = percent
+ @percent.setter
+ def percent(self, value):
+ assert value >= 0
+ assert value <= 100
+ self.__percent = value
def __str__(self):
- """Return the bars"""
- frac, whole = modf(self.get_size() * self.get_percent() / 100.0)
+ """Return the bars."""
+ frac, whole = modf(self.size * self.percent / 100.0)
ret = curses_bars[8] * int(whole)
if frac > 0:
ret += curses_bars[int(frac * 8)]
whole += 1
- ret += self.__empty_char * int(self.get_size() - whole)
+ ret += self.__empty_char * int(self.size - whole)
if self.__with_text:
- ret = '{0}{1:>5}%'.format(ret, self.get_percent())
+ ret = '{0}{1:>5}%'.format(ret, self.percent)
return self.__pre_char + ret + self.__post_char