Added multi_colors option to MemBar.
This commit is contained in:
parent
fbd852b79b
commit
a789b31d6d
@ -1,16 +1,17 @@
|
||||
from i3pystatus import IntervalModule
|
||||
from psutil import virtual_memory
|
||||
from i3pystatus.core.color import ColorRangeModule
|
||||
from i3pystatus.core.util import make_bar
|
||||
|
||||
|
||||
class MemBar(IntervalModule):
|
||||
class MemBar(IntervalModule, ColorRangeModule):
|
||||
"""
|
||||
Shows memory load as a bar.
|
||||
|
||||
Available formatters:
|
||||
* {used_mem_bar}
|
||||
|
||||
Requires psutil (from PyPI)
|
||||
Requires psutil and colour (from PyPI)
|
||||
"""
|
||||
|
||||
format = "{used_mem_bar}"
|
||||
@ -19,6 +20,10 @@ class MemBar(IntervalModule):
|
||||
alert_color = "#FF0000"
|
||||
warn_percentage = 50
|
||||
alert_percentage = 80
|
||||
multi_colors = False
|
||||
|
||||
def init(self):
|
||||
self.colors = self.get_hex_color_range(self.color, self.alert_color, 100)
|
||||
|
||||
settings = (
|
||||
("format", "format string used for output."),
|
||||
@ -29,14 +34,16 @@ class MemBar(IntervalModule):
|
||||
"defines the color used wann warn percentage ist exceeded"),
|
||||
("alert_color",
|
||||
"defines the color used when alert percentage is exceeded"),
|
||||
("multi_colors", "whether to use range of colors from 'color' to 'alert_color' based on memory usage."),
|
||||
)
|
||||
|
||||
def run(self):
|
||||
memory_usage = virtual_memory()
|
||||
|
||||
if memory_usage.percent >= self.alert_percentage:
|
||||
if self.multi_colors:
|
||||
color = self.get_gradient(memory_usage.percent, self.colors)
|
||||
elif memory_usage.percent >= self.alert_percentage:
|
||||
color = self.alert_color
|
||||
|
||||
elif memory_usage.percent >= self.warn_percentage:
|
||||
color = self.warn_color
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user