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 diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index d0e279cd..7df0fddb 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -95,7 +95,7 @@ class Plugin(GlancesPlugin): # Build the string message for key in ['cpu', 'mem', 'swap']: - bar.set_percent(self.stats[key]) + bar.percent = self.stats[key] msg = '{0:>4} '.format(key.upper()) ret.append(self.curse_add_line(msg)) msg = '{0}'.format(bar)