Merge pull request #51 from sbrunner/dev

Some litile improvments
This commit is contained in:
enkore 2014-04-16 18:58:44 +02:00
commit 6b2bafa35f
4 changed files with 52 additions and 8 deletions

View File

@ -57,15 +57,21 @@ class Battery:
class BatteryCharge(Battery):
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
else:
return -1
def _percentage(self, design):
return self.battery_info["CHARGE_NOW"] / self.battery_info["CHARGE_FULL" + design]
def remaining(self):
if self.status() == "Discharging":
if "CHARGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
# Ah / A = h * 60 min = min
return self.battery_info["CHARGE_NOW"] / self.battery_info["CURRENT_NOW"] * 60
else:
return -1
else:
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"),
("path", "Override the default-generated path"),
("status", "A dictionary mapping ('DIS', 'CHR', 'FULL') to alternative names"),
("color", "The text color"),
("critical_color", "The critical color"),
)
battery_ident = "BAT0"
format = "{status} {remaining}"
@ -122,6 +130,8 @@ class BatteryChecker(IntervalModule):
alert_percentage = 10
alert_format_title = "Low battery"
alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!"
color = "#ffffff"
critical_color = "#ff0000"
path = None
@ -132,7 +142,7 @@ class BatteryChecker(IntervalModule):
def run(self):
urgent = False
color = "#ffffff"
color = self.color
battery = Battery.create(self.path)
@ -152,7 +162,7 @@ class BatteryChecker(IntervalModule):
fdict["status"] = "DIS"
if battery.percentage() <= self.alert_percentage:
urgent = True
color = "#ff0000"
color = self.critical_color
else:
fdict["status"] = "CHR"
else:
@ -173,5 +183,5 @@ class BatteryChecker(IntervalModule):
"full_text": formatp(self.format, **fdict).strip(),
"instance": self.battery_ident,
"urgent": urgent,
"color": color
"color": color,
}

View File

@ -16,18 +16,30 @@ class Disk(IntervalModule):
settings = (
"format", "path",
("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",)
color = "#FFFFFF"
critical_color = "#FF0000"
format = "{free}/{avail}"
divisor = 1024 ** 3
display_limit = float('Inf')
critical_limit = 0
def run(self):
stat = os.statvfs(self.path)
available = (stat.f_bsize * stat.f_bavail) / self.divisor
if available > self.display_limit:
self.output = {}
return
cdict = {
"total": (stat.f_bsize * stat.f_blocks) / 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,
"percentage_free": stat.f_bfree / stat.f_blocks * 100,
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
@ -37,5 +49,6 @@ class Disk(IntervalModule):
self.output = {
"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
}

View File

@ -11,14 +11,24 @@ class Load(IntervalModule):
settings = (
("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)."),
("color", "The text color"),
("critical_limit", "Limit under witch one the battery is critical"),
("critical_color", "The critical color"),
)
file = "/proc/loadavg"
color = "#ffffff"
critical_limit = 1
critical_color = "#ff0000"
def run(self):
with open(self.file, "r") as f:
avg1, avg5, avg15, tasks, lastpid = f.read().split(" ", 5)
urgent = float(avg1) > self.critical_limit
self.output = {
"full_text": self.format.format(avg1=avg1, avg5=avg5, avg15=avg15, tasks=tasks),
"urgent": urgent,
"color": self.critical_color if urgent else self.color,
}

View File

@ -1,4 +1,6 @@
import subprocess
from i3pystatus import SettingsBase, IntervalModule
@ -26,6 +28,7 @@ class Mail(IntervalModule):
("backends", "List of backends (instances of `i3pystatus.mail.xxx.zzz`)"),
"color", "color_unread", "format", "format_plural",
("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",)
@ -34,6 +37,7 @@ class Mail(IntervalModule):
format = "{unread} new email"
format_plural = "{unread} new emails"
hide_if_null = True
email_client = None
def init(self):
for backend in self.backends:
@ -61,3 +65,10 @@ class Mail(IntervalModule):
"urgent": urgent,
"color": color,
}
def on_leftclick(self):
if self.email_client:
subprocess.Popen(self.email_client.split())
def on_rightclick(self):
self.run()