Formatting fixes, fixed state management and added some icons
This commit is contained in:
parent
448ab6de83
commit
c7df1926dc
1 changed files with 19 additions and 17 deletions
|
@ -16,9 +16,9 @@ class Module(core.module.Module):
|
||||||
@core.decorators.every(seconds=10)
|
@core.decorators.every(seconds=10)
|
||||||
def __init__(self, config, theme):
|
def __init__(self, config, theme):
|
||||||
super().__init__(config, theme, core.widget.Widget(self.network))
|
super().__init__(config, theme, core.widget.Widget(self.network))
|
||||||
self._is_wireless = True
|
self.__is_wireless = True
|
||||||
self._interface = None
|
self.__interface = None
|
||||||
self._message = None
|
self.__message = None
|
||||||
self.__signal = -110
|
self.__signal = -110
|
||||||
|
|
||||||
# Set up event handler for left mouse click
|
# Set up event handler for left mouse click
|
||||||
|
@ -33,48 +33,50 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
# Attempt to extract a valid network interface device
|
# Attempt to extract a valid network interface device
|
||||||
try:
|
try:
|
||||||
self._interface = route_tokens[route_tokens.index("dev") + 1]
|
self.__interface = route_tokens[route_tokens.index("dev") + 1]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._interface = None
|
self.__interface = None
|
||||||
|
|
||||||
# Check to see if the interface (if it exists) is wireless
|
# Check to see if the interface (if it exists) is wireless
|
||||||
if self._interface:
|
if self.__interface:
|
||||||
with open("/proc/net/wireless", "r") as f:
|
with open("/proc/net/wireless", "r") as f:
|
||||||
self._is_wireless = self._interface in f.read()
|
self.__is_wireless = self.__interface in f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# setup message to send to the user
|
# setup message to send to the user
|
||||||
if self._interface is None:
|
if self.__interface is None:
|
||||||
self._message = "Not connected to a network"
|
self.__message = " No connection"
|
||||||
elif self._is_wireless:
|
elif self.__is_wireless:
|
||||||
cmd = "iwgetid"
|
cmd = "iwgetid"
|
||||||
iw_dat = util.cli.execute(cmd)
|
iw_dat = util.cli.execute(cmd)
|
||||||
has_ssid = "ESSID" in iw_dat
|
has_ssid = "ESSID" in iw_dat
|
||||||
ssid = iw_dat[iw_dat.index(":") + 2: -2] if has_ssid else "Unknown"
|
ssid = iw_dat[iw_dat.index(":") + 2: -2] if has_ssid else "Unknown"
|
||||||
|
|
||||||
# Get connection strength
|
# Get connection strength
|
||||||
cmd = "iwconfig {}".format(self._interface)
|
cmd = "iwconfig {}".format(self.__interface)
|
||||||
config_dat = " ".join(util.cli.execute(cmd).split())
|
config_dat = " ".join(util.cli.execute(cmd).split())
|
||||||
config_tokens = config_dat.replace("=", " ").split()
|
config_tokens = config_dat.replace("=", " ").split()
|
||||||
strength = config_tokens[config_tokens.index("level") + 1]
|
strength = config_tokens[config_tokens.index("level") + 1]
|
||||||
self.__signal = util.format.asint(strength, minimum=-110, maximum=-30)
|
self.__signal = util.format.asint(strength, minimum=-110, maximum=-30)
|
||||||
|
|
||||||
self._message = self.__generate_wireless_message(ssid, self.__signal)
|
self.__message = self.__generate_wireles_message(ssid, self.__signal)
|
||||||
else:
|
else:
|
||||||
self._message = self._message
|
self.__signal = -30
|
||||||
|
self.__message = " Ethernet"
|
||||||
|
|
||||||
return self._message
|
return self.__message
|
||||||
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
if self.__signal < -65:
|
|
||||||
return "warning"
|
|
||||||
if self.__signal < -80:
|
if self.__signal < -80:
|
||||||
return "critical"
|
return "critical"
|
||||||
|
if self.__signal < -65:
|
||||||
|
return "warning"
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def __generate_wireless_message(self, ssid, strength):
|
def __generate_wireles_message(self, ssid, strength):
|
||||||
computed_strength = 100 * ((strength + 100) / 70.0)
|
computed_strength = 100 * ((strength + 100) / 70.0)
|
||||||
return " {} {}%".format(ssid, int(computed_strength))
|
return " {} {}%".format(ssid, int(computed_strength))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue