commit
f7c8a352dc
@ -5,7 +5,7 @@ import re
|
|||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from i3pystatus import IntervalModule, formatp
|
from i3pystatus import IntervalModule, formatp
|
||||||
from i3pystatus.core.util import lchop, TimeWrapper
|
from i3pystatus.core.util import lchop, TimeWrapper, make_bar
|
||||||
from i3pystatus.core.desktop import DesktopNotification
|
from i3pystatus.core.desktop import DesktopNotification
|
||||||
|
|
||||||
|
|
||||||
@ -113,11 +113,13 @@ class BatteryChecker(IntervalModule):
|
|||||||
* `{consumption (Watts)}` — current power flowing into/out of the battery
|
* `{consumption (Watts)}` — current power flowing into/out of the battery
|
||||||
* `{status}`
|
* `{status}`
|
||||||
* `{battery_ident}` — the same as the setting
|
* `{battery_ident}` — the same as the setting
|
||||||
|
* `{bar}` —bar displaying the percentage graphically
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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"),
|
||||||
@ -125,7 +127,10 @@ class BatteryChecker(IntervalModule):
|
|||||||
("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"),
|
("color", "The text color"),
|
||||||
|
("full_color", "The full 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}"
|
||||||
@ -134,13 +139,17 @@ 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
|
||||||
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"
|
color = "#ffffff"
|
||||||
|
full_color = "#11aa11"
|
||||||
|
charging_color = "#00ff00"
|
||||||
critical_color = "#ff0000"
|
critical_color = "#ff0000"
|
||||||
|
not_present_color = "#ffffff"
|
||||||
|
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
@ -153,7 +162,14 @@ class BatteryChecker(IntervalModule):
|
|||||||
urgent = False
|
urgent = False
|
||||||
color = self.color
|
color = self.color
|
||||||
|
|
||||||
battery = Battery.create(self.path)
|
try:
|
||||||
|
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,
|
||||||
@ -161,6 +177,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
"percentage_design": battery.percentage(design=True),
|
"percentage_design": battery.percentage(design=True),
|
||||||
"consumption": battery.consumption(),
|
"consumption": battery.consumption(),
|
||||||
"remaining": TimeWrapper(0, "%E%h:%M"),
|
"remaining": TimeWrapper(0, "%E%h:%M"),
|
||||||
|
"bar": make_bar(battery.percentage()),
|
||||||
}
|
}
|
||||||
|
|
||||||
status = battery.status()
|
status = battery.status()
|
||||||
@ -174,8 +191,10 @@ class BatteryChecker(IntervalModule):
|
|||||||
color = self.critical_color
|
color = self.critical_color
|
||||||
else:
|
else:
|
||||||
fdict["status"] = "CHR"
|
fdict["status"] = "CHR"
|
||||||
|
color = self.charging_color
|
||||||
else:
|
else:
|
||||||
fdict["status"] = "FULL"
|
fdict["status"] = "FULL"
|
||||||
|
color = self.full_color
|
||||||
|
|
||||||
if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage:
|
if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage:
|
||||||
DesktopNotification(
|
DesktopNotification(
|
||||||
@ -189,7 +208,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
fdict["status"] = self.status[fdict["status"]]
|
fdict["status"] = self.status[fdict["status"]]
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": formatp(self.format, **fdict).strip(),
|
"full_text": formatp(self.format, **fdict),
|
||||||
"instance": self.battery_ident,
|
"instance": self.battery_ident,
|
||||||
"urgent": urgent,
|
"urgent": urgent,
|
||||||
"color": color,
|
"color": color,
|
||||||
|
36
i3pystatus/shell.py
Normal file
36
i3pystatus/shell.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from i3pystatus import IntervalModule
|
||||||
|
from subprocess import check_output, CalledProcessError
|
||||||
|
|
||||||
|
class Shell(IntervalModule):
|
||||||
|
"""
|
||||||
|
Shows output of shell command
|
||||||
|
"""
|
||||||
|
|
||||||
|
color = "#FFFFFF"
|
||||||
|
error_color = "#FF0000"
|
||||||
|
|
||||||
|
settings = (
|
||||||
|
("command", "command to be executed"),
|
||||||
|
("color", "standard color"),
|
||||||
|
("error_color", "color to use when non zero exit code is returned")
|
||||||
|
)
|
||||||
|
|
||||||
|
required = ("command",)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
out = check_output(self.command, shell=True)
|
||||||
|
color = self.color
|
||||||
|
except CalledProcessError as e:
|
||||||
|
out = e.output
|
||||||
|
color = self.error_color
|
||||||
|
|
||||||
|
out = out.decode("UTF-8").replace("\n", " ")
|
||||||
|
|
||||||
|
if out[-1] == " ":
|
||||||
|
out = out[:-1]
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": out,
|
||||||
|
"color": color
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import basiciw
|
import basiciw
|
||||||
|
|
||||||
|
from i3pystatus.core.util import make_bar
|
||||||
from i3pystatus.network import Network
|
from i3pystatus.network import Network
|
||||||
|
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ class Wireless(Network):
|
|||||||
* `{essid}` — ESSID of currently connected wifi
|
* `{essid}` — ESSID of currently connected wifi
|
||||||
* `{freq}` — Current frequency
|
* `{freq}` — Current frequency
|
||||||
* `{quality}` — Link quality in percent
|
* `{quality}` — Link quality in percent
|
||||||
|
* `{quality_bar}` —Bar graphically representing link quality
|
||||||
"""
|
"""
|
||||||
|
|
||||||
interface = "wlan0"
|
interface = "wlan0"
|
||||||
@ -32,6 +34,7 @@ class Wireless(Network):
|
|||||||
else:
|
else:
|
||||||
fdict["quality"] = quality["quality"]
|
fdict["quality"] = quality["quality"]
|
||||||
fdict["quality"] *= 100
|
fdict["quality"] *= 100
|
||||||
|
fdict["quality_bar"] = make_bar(fdict["quality"])
|
||||||
else:
|
else:
|
||||||
fdict["essid"] = ""
|
fdict["essid"] = ""
|
||||||
fdict["freq"] = fdict["quality"] = 0.0
|
fdict["freq"] = fdict["quality"] = 0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user