commit
6b2bafa35f
@ -57,15 +57,21 @@ class Battery:
|
|||||||
|
|
||||||
class BatteryCharge(Battery):
|
class BatteryCharge(Battery):
|
||||||
def consumption(self):
|
def consumption(self):
|
||||||
|
if "VOLTAGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
|
||||||
return self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"] # V * A = W
|
return self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"] # V * A = W
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
def _percentage(self, design):
|
def _percentage(self, design):
|
||||||
return self.battery_info["CHARGE_NOW"] / self.battery_info["CHARGE_FULL" + design]
|
return self.battery_info["CHARGE_NOW"] / self.battery_info["CHARGE_FULL" + design]
|
||||||
|
|
||||||
def remaining(self):
|
def remaining(self):
|
||||||
if self.status() == "Discharging":
|
if self.status() == "Discharging":
|
||||||
|
if "CHARGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
|
||||||
# Ah / A = h * 60 min = min
|
# Ah / A = h * 60 min = min
|
||||||
return self.battery_info["CHARGE_NOW"] / self.battery_info["CURRENT_NOW"] * 60
|
return self.battery_info["CHARGE_NOW"] / self.battery_info["CURRENT_NOW"] * 60
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
else:
|
else:
|
||||||
return (self.battery_info["CHARGE_FULL"] - self.battery_info["CHARGE_NOW"]) / self.battery_info["CURRENT_NOW"] * 60
|
return (self.battery_info["CHARGE_FULL"] - self.battery_info["CHARGE_NOW"]) / self.battery_info["CURRENT_NOW"] * 60
|
||||||
|
|
||||||
@ -109,6 +115,8 @@ class BatteryChecker(IntervalModule):
|
|||||||
("alert_format_body", "The body text of the notification, all formatters can be used"),
|
("alert_format_body", "The body text of the notification, all formatters can be used"),
|
||||||
("path", "Override the default-generated path"),
|
("path", "Override the default-generated path"),
|
||||||
("status", "A dictionary mapping ('DIS', 'CHR', 'FULL') to alternative names"),
|
("status", "A dictionary mapping ('DIS', 'CHR', 'FULL') to alternative names"),
|
||||||
|
("color", "The text color"),
|
||||||
|
("critical_color", "The critical color"),
|
||||||
)
|
)
|
||||||
battery_ident = "BAT0"
|
battery_ident = "BAT0"
|
||||||
format = "{status} {remaining}"
|
format = "{status} {remaining}"
|
||||||
@ -122,6 +130,8 @@ class BatteryChecker(IntervalModule):
|
|||||||
alert_percentage = 10
|
alert_percentage = 10
|
||||||
alert_format_title = "Low battery"
|
alert_format_title = "Low battery"
|
||||||
alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!"
|
alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!"
|
||||||
|
color = "#ffffff"
|
||||||
|
critical_color = "#ff0000"
|
||||||
|
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
@ -132,7 +142,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
urgent = False
|
urgent = False
|
||||||
color = "#ffffff"
|
color = self.color
|
||||||
|
|
||||||
battery = Battery.create(self.path)
|
battery = Battery.create(self.path)
|
||||||
|
|
||||||
@ -152,7 +162,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
fdict["status"] = "DIS"
|
fdict["status"] = "DIS"
|
||||||
if battery.percentage() <= self.alert_percentage:
|
if battery.percentage() <= self.alert_percentage:
|
||||||
urgent = True
|
urgent = True
|
||||||
color = "#ff0000"
|
color = self.critical_color
|
||||||
else:
|
else:
|
||||||
fdict["status"] = "CHR"
|
fdict["status"] = "CHR"
|
||||||
else:
|
else:
|
||||||
@ -173,5 +183,5 @@ class BatteryChecker(IntervalModule):
|
|||||||
"full_text": formatp(self.format, **fdict).strip(),
|
"full_text": formatp(self.format, **fdict).strip(),
|
||||||
"instance": self.battery_ident,
|
"instance": self.battery_ident,
|
||||||
"urgent": urgent,
|
"urgent": urgent,
|
||||||
"color": color
|
"color": color,
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,30 @@ class Disk(IntervalModule):
|
|||||||
settings = (
|
settings = (
|
||||||
"format", "path",
|
"format", "path",
|
||||||
("divisor", "divide all byte values by this value, commonly 1024**3 (gigabyte)"),
|
("divisor", "divide all byte values by this value, commonly 1024**3 (gigabyte)"),
|
||||||
|
("display_limit", "limit upper witch one the module isn't display"),
|
||||||
|
("critical_limit", "limit under witch one the disk space is critical"),
|
||||||
|
("critical_color", "the critical color"),
|
||||||
)
|
)
|
||||||
required = ("path",)
|
required = ("path",)
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
|
critical_color = "#FF0000"
|
||||||
format = "{free}/{avail}"
|
format = "{free}/{avail}"
|
||||||
divisor = 1024 ** 3
|
divisor = 1024 ** 3
|
||||||
|
display_limit = float('Inf')
|
||||||
|
critical_limit = 0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
stat = os.statvfs(self.path)
|
stat = os.statvfs(self.path)
|
||||||
|
available = (stat.f_bsize * stat.f_bavail) / self.divisor
|
||||||
|
|
||||||
|
if available > self.display_limit:
|
||||||
|
self.output = {}
|
||||||
|
return
|
||||||
|
|
||||||
cdict = {
|
cdict = {
|
||||||
"total": (stat.f_bsize * stat.f_blocks) / self.divisor,
|
"total": (stat.f_bsize * stat.f_blocks) / self.divisor,
|
||||||
"free": (stat.f_bsize * stat.f_bfree) / self.divisor,
|
"free": (stat.f_bsize * stat.f_bfree) / self.divisor,
|
||||||
"avail": (stat.f_bsize * stat.f_bavail) / self.divisor,
|
"avail": available,
|
||||||
"used": (stat.f_bsize * (stat.f_blocks - stat.f_bfree)) / self.divisor,
|
"used": (stat.f_bsize * (stat.f_blocks - stat.f_bfree)) / self.divisor,
|
||||||
"percentage_free": stat.f_bfree / stat.f_blocks * 100,
|
"percentage_free": stat.f_bfree / stat.f_blocks * 100,
|
||||||
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
|
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
|
||||||
@ -37,5 +49,6 @@ class Disk(IntervalModule):
|
|||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(**cdict),
|
"full_text": self.format.format(**cdict),
|
||||||
"color": self.color
|
"color": self.color if available > self.critical_limit else self.critical_color,
|
||||||
|
"urgent": available > self.critical_limit
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,24 @@ class Load(IntervalModule):
|
|||||||
settings = (
|
settings = (
|
||||||
("format",
|
("format",
|
||||||
"format string used for output. {avg1}, {avg5} and {avg15} are the load average of the last one, five and fifteen minutes, respectively. {tasks} is the number of tasks (i.e. 1/285, which indiciates that one out of 285 total tasks is runnable)."),
|
"format string used for output. {avg1}, {avg5} and {avg15} are the load average of the last one, five and fifteen minutes, respectively. {tasks} is the number of tasks (i.e. 1/285, which indiciates that one out of 285 total tasks is runnable)."),
|
||||||
|
("color", "The text color"),
|
||||||
|
("critical_limit", "Limit under witch one the battery is critical"),
|
||||||
|
("critical_color", "The critical color"),
|
||||||
)
|
)
|
||||||
|
|
||||||
file = "/proc/loadavg"
|
file = "/proc/loadavg"
|
||||||
|
color = "#ffffff"
|
||||||
|
critical_limit = 1
|
||||||
|
critical_color = "#ff0000"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with open(self.file, "r") as f:
|
with open(self.file, "r") as f:
|
||||||
avg1, avg5, avg15, tasks, lastpid = f.read().split(" ", 5)
|
avg1, avg5, avg15, tasks, lastpid = f.read().split(" ", 5)
|
||||||
|
|
||||||
|
urgent = float(avg1) > self.critical_limit
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(avg1=avg1, avg5=avg5, avg15=avg15, tasks=tasks),
|
"full_text": self.format.format(avg1=avg1, avg5=avg5, avg15=avg15, tasks=tasks),
|
||||||
|
"urgent": urgent,
|
||||||
|
"color": self.critical_color if urgent else self.color,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from i3pystatus import SettingsBase, IntervalModule
|
from i3pystatus import SettingsBase, IntervalModule
|
||||||
|
|
||||||
|
|
||||||
@ -26,6 +28,7 @@ class Mail(IntervalModule):
|
|||||||
("backends", "List of backends (instances of `i3pystatus.mail.xxx.zzz`)"),
|
("backends", "List of backends (instances of `i3pystatus.mail.xxx.zzz`)"),
|
||||||
"color", "color_unread", "format", "format_plural",
|
"color", "color_unread", "format", "format_plural",
|
||||||
("hide_if_null", "Don't output anything if there are no new mails"),
|
("hide_if_null", "Don't output anything if there are no new mails"),
|
||||||
|
("email_client", "The email client to open on left click"),
|
||||||
)
|
)
|
||||||
required = ("backends",)
|
required = ("backends",)
|
||||||
|
|
||||||
@ -34,6 +37,7 @@ class Mail(IntervalModule):
|
|||||||
format = "{unread} new email"
|
format = "{unread} new email"
|
||||||
format_plural = "{unread} new emails"
|
format_plural = "{unread} new emails"
|
||||||
hide_if_null = True
|
hide_if_null = True
|
||||||
|
email_client = None
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
for backend in self.backends:
|
for backend in self.backends:
|
||||||
@ -61,3 +65,10 @@ class Mail(IntervalModule):
|
|||||||
"urgent": urgent,
|
"urgent": urgent,
|
||||||
"color": color,
|
"color": color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def on_leftclick(self):
|
||||||
|
if self.email_client:
|
||||||
|
subprocess.Popen(self.email_client.split())
|
||||||
|
|
||||||
|
def on_rightclick(self):
|
||||||
|
self.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user