Added not_present_text and not_present_color parameters to the battery module

This commit also fixes i3pystatus crashing if the battery is removed while
running.
This commit is contained in:
Josef Gajdusek 2014-07-10 16:13:43 +02:00
parent 9524bf26a8
commit e38274b5ce

View File

@ -119,6 +119,7 @@ class BatteryChecker(IntervalModule):
settings = ( settings = (
("battery_ident", "The name of your battery, usually BAT0 or BAT1"), ("battery_ident", "The name of your battery, usually BAT0 or BAT1"),
"format", "format",
("not_present_text", "Text displayed if the battery is not present. No formatters are available"),
("alert", "Display a libnotify-notification on low battery"), ("alert", "Display a libnotify-notification on low battery"),
"alert_percentage", "alert_percentage",
("alert_format_title", "The title of the notification, all formatters can be used"), ("alert_format_title", "The title of the notification, all formatters can be used"),
@ -129,6 +130,7 @@ class BatteryChecker(IntervalModule):
("full_color", "The full color"), ("full_color", "The full color"),
("charging_color", "The charging color"), ("charging_color", "The charging color"),
("critical_color", "The critical color"), ("critical_color", "The critical color"),
("not_present_color", "The not present color."),
) )
battery_ident = "BAT0" battery_ident = "BAT0"
format = "{status} {remaining}" format = "{status} {remaining}"
@ -137,6 +139,7 @@ class BatteryChecker(IntervalModule):
"DIS": "DIS", "DIS": "DIS",
"FULL": "FULL", "FULL": "FULL",
} }
not_present_text = "Battery not present"
alert = False alert = False
alert_percentage = 10 alert_percentage = 10
@ -146,6 +149,7 @@ class BatteryChecker(IntervalModule):
full_color = "#11aa11" full_color = "#11aa11"
charging_color = "#00ff00" charging_color = "#00ff00"
critical_color = "#ff0000" critical_color = "#ff0000"
not_present_color = "#ffffff"
path = None path = None
@ -158,7 +162,14 @@ class BatteryChecker(IntervalModule):
urgent = False urgent = False
color = self.color color = self.color
try:
battery = Battery.create(self.path) battery = Battery.create(self.path)
except FileNotFoundError:
self.output = {
"full_text": self.not_present_text,
"color": self.not_present_color,
}
return
fdict = { fdict = {
"battery_ident": self.battery_ident, "battery_ident": self.battery_ident,