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