Use different format strings for each auto-detected network interface (#565)
* network - Use different format strings for each autodetected interface Introduce format_active_up dictionary. Each key can be a valid globbing pattern for fnmatch.fnmatch(). Fall back to format_up if no match could be found. * network - Always honor disabled dynamic_color Disable the calculation of color values if detect_active is enabled and dynamic_color is disabled. This resulted in "#000000" for some reason.
This commit is contained in:
parent
c6464aeecb
commit
811ade8160
@ -1,3 +1,5 @@
|
||||
from fnmatch import fnmatch
|
||||
|
||||
import netifaces
|
||||
|
||||
from i3pystatus import IntervalModule, formatp
|
||||
@ -284,6 +286,10 @@ class Network(IntervalModule, ColorRangeModule):
|
||||
|
||||
settings = (
|
||||
("format_up", "format string"),
|
||||
("format_active_up", "Dictionary containing format strings for auto-detected interfaces. "
|
||||
"Each key can be either a full interface name, or a pattern matching "
|
||||
"a interface, eg 'e*' for ethernet interfaces. "
|
||||
"Fallback to format_up if no pattern could be matched."),
|
||||
("format_down", "format string"),
|
||||
"color_up",
|
||||
"color_down",
|
||||
@ -314,6 +320,7 @@ class Network(IntervalModule, ColorRangeModule):
|
||||
interface = 'eth0'
|
||||
|
||||
format_up = "{interface} {network_graph}{kbs}KB/s"
|
||||
format_active_up = {}
|
||||
format_down = "{interface}: DOWN"
|
||||
color_up = "#00FF00"
|
||||
color_down = "#FF0000"
|
||||
@ -410,6 +417,7 @@ class Network(IntervalModule, ColorRangeModule):
|
||||
format_values['network_graph'] = self.get_network_graph(kbs, limit)
|
||||
format_values['kbs'] = "{0:.1f}".format(round(kbs, 2))
|
||||
|
||||
if self.dynamic_color:
|
||||
if self.separate_color and self.pango_enabled:
|
||||
color = self.color_up
|
||||
color_template = "<span color=\"{}\">{}</span>"
|
||||
@ -430,11 +438,18 @@ class Network(IntervalModule, ColorRangeModule):
|
||||
color = self.get_gradient(percent, self.colors, 100)
|
||||
else:
|
||||
color = None
|
||||
else:
|
||||
color = None
|
||||
|
||||
if sysfs_interface_up(self.interface, self.unknown_up):
|
||||
if not color:
|
||||
color = self.color_up
|
||||
format_str = self.format_up
|
||||
|
||||
if self.detect_active:
|
||||
for pattern in self.format_active_up:
|
||||
if fnmatch(self.interface, pattern):
|
||||
format_str = self.format_active_up.get(pattern, self.format_up)
|
||||
else:
|
||||
color = self.color_down
|
||||
format_str = self.format_down
|
||||
|
Loading…
Reference in New Issue
Block a user