Merge pull request #153 from facetoe/master
Cycle available interfaces on click
This commit is contained in:
commit
0ff58efc69
@ -1,6 +1,4 @@
|
|||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import netifaces
|
import netifaces
|
||||||
|
|
||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule
|
||||||
@ -91,6 +89,8 @@ class Network(IntervalModule):
|
|||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
("interface", "Interface to obtain information for"),
|
("interface", "Interface to obtain information for"),
|
||||||
|
("ignore_interfaces", "Array of interfaces to ignore when cycling through "
|
||||||
|
"with right click. Eg, 'lo'"),
|
||||||
"format_up", "color_up",
|
"format_up", "color_up",
|
||||||
"format_down", "color_down",
|
"format_down", "color_down",
|
||||||
("detached_down", "If the interface doesn't exist, display it as if it were down"),
|
("detached_down", "If the interface doesn't exist, display it as if it were down"),
|
||||||
@ -99,6 +99,7 @@ class Network(IntervalModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
name = interface = "eth0"
|
name = interface = "eth0"
|
||||||
|
ignore_interfaces = ["lo"]
|
||||||
format_up = "{interface}: {v4}"
|
format_up = "{interface}: {v4}"
|
||||||
format_down = "{interface}"
|
format_down = "{interface}"
|
||||||
color_up = "#00FF00"
|
color_up = "#00FF00"
|
||||||
@ -106,6 +107,8 @@ class Network(IntervalModule):
|
|||||||
detached_down = True
|
detached_down = True
|
||||||
unknown_up = False
|
unknown_up = False
|
||||||
on_leftclick = "nm-connection-editor"
|
on_leftclick = "nm-connection-editor"
|
||||||
|
on_rightclick = "cycle_interface"
|
||||||
|
interval = 1
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.interface not in netifaces.interfaces() and not self.detached_down:
|
if self.interface not in netifaces.interfaces() and not self.detached_down:
|
||||||
@ -167,6 +170,14 @@ class Network(IntervalModule):
|
|||||||
|
|
||||||
return color, format, fdict, up
|
return color, format, fdict, up
|
||||||
|
|
||||||
|
def cycle_interface(self):
|
||||||
|
interfaces = [i for i in netifaces.interfaces() if i not in self.ignore_interfaces]
|
||||||
|
if self.interface in interfaces:
|
||||||
|
next_index = (interfaces.index(self.interface) + 1) % len(interfaces)
|
||||||
|
self.interface = interfaces[next_index]
|
||||||
|
elif len(interfaces) > 0:
|
||||||
|
self.interface = interfaces[0]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
color, format, fdict, up = self.collect()
|
color, format, fdict, up = self.collect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user