Merge pull request #76 from atalax/master

Add shell module
This commit is contained in:
enkore 2014-07-17 19:45:00 +02:00
commit f7c8a352dc
3 changed files with 61 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import re
import configparser
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
@ -113,11 +113,13 @@ class BatteryChecker(IntervalModule):
* `{consumption (Watts)}` current power flowing into/out of the battery
* `{status}`
* `{battery_ident}` the same as the setting
* `{bar}` bar displaying the percentage graphically
"""
settings = (
("battery_ident", "The name of your battery, usually BAT0 or BAT1"),
"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_percentage",
("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"),
("status", "A dictionary mapping ('DIS', 'CHR', 'FULL') to alternative names"),
("color", "The text color"),
("full_color", "The full color"),
("charging_color", "The charging color"),
("critical_color", "The critical color"),
("not_present_color", "The not present color."),
)
battery_ident = "BAT0"
format = "{status} {remaining}"
@ -134,13 +139,17 @@ class BatteryChecker(IntervalModule):
"DIS": "DIS",
"FULL": "FULL",
}
not_present_text = "Battery not present"
alert = False
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"
full_color = "#11aa11"
charging_color = "#00ff00"
critical_color = "#ff0000"
not_present_color = "#ffffff"
path = None
@ -153,7 +162,14 @@ class BatteryChecker(IntervalModule):
urgent = False
color = self.color
try:
battery = Battery.create(self.path)
except FileNotFoundError:
self.output = {
"full_text": self.not_present_text,
"color": self.not_present_color,
}
return
fdict = {
"battery_ident": self.battery_ident,
@ -161,6 +177,7 @@ class BatteryChecker(IntervalModule):
"percentage_design": battery.percentage(design=True),
"consumption": battery.consumption(),
"remaining": TimeWrapper(0, "%E%h:%M"),
"bar": make_bar(battery.percentage()),
}
status = battery.status()
@ -174,8 +191,10 @@ class BatteryChecker(IntervalModule):
color = self.critical_color
else:
fdict["status"] = "CHR"
color = self.charging_color
else:
fdict["status"] = "FULL"
color = self.full_color
if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage:
DesktopNotification(
@ -189,7 +208,7 @@ class BatteryChecker(IntervalModule):
fdict["status"] = self.status[fdict["status"]]
self.output = {
"full_text": formatp(self.format, **fdict).strip(),
"full_text": formatp(self.format, **fdict),
"instance": self.battery_ident,
"urgent": urgent,
"color": color,

36
i3pystatus/shell.py Normal file
View 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
}

View File

@ -1,5 +1,6 @@
import basiciw
from i3pystatus.core.util import make_bar
from i3pystatus.network import Network
@ -15,6 +16,7 @@ class Wireless(Network):
* `{essid}` ESSID of currently connected wifi
* `{freq}` Current frequency
* `{quality}` Link quality in percent
* `{quality_bar}` Bar graphically representing link quality
"""
interface = "wlan0"
@ -32,6 +34,7 @@ class Wireless(Network):
else:
fdict["quality"] = quality["quality"]
fdict["quality"] *= 100
fdict["quality_bar"] = make_bar(fdict["quality"])
else:
fdict["essid"] = ""
fdict["freq"] = fdict["quality"] = 0.0