From d0a38e036c5ff0ead88de64c4aa6912474a404ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 9 Apr 2014 18:22:03 +0200 Subject: [PATCH 1/5] Open email client and refresh email with mouse click --- i3pystatus/mail/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/i3pystatus/mail/__init__.py b/i3pystatus/mail/__init__.py index 30d4500..52303d6 100644 --- a/i3pystatus/mail/__init__.py +++ b/i3pystatus/mail/__init__.py @@ -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() From 1f80fb4e1947b431269ab2b323da07595cfb6d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 9 Apr 2014 18:40:59 +0200 Subject: [PATCH 2/5] Add display and critical limit in the disk module --- i3pystatus/disk.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/i3pystatus/disk.py b/i3pystatus/disk.py index ddbe673..f053901 100644 --- a/i3pystatus/disk.py +++ b/i3pystatus/disk.py @@ -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 } From 5aef5f529a1e439385397a8adeea3a7d24341e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 16 Apr 2014 17:27:48 +0200 Subject: [PATCH 3/5] CURRENT_NOW isn't always present --- i3pystatus/battery.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 821404c..2a88bf5 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -57,15 +57,21 @@ class Battery: class BatteryCharge(Battery): def consumption(self): - return self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"] # V * A = W + 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": - # Ah / A = h * 60 min = min - return self.battery_info["CHARGE_NOW"] / self.battery_info["CURRENT_NOW"] * 60 + 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 From 6d8dba3468a4baca2c1201a1499bf88d846b7c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 16 Apr 2014 17:34:48 +0200 Subject: [PATCH 4/5] Make battery colors configurable --- i3pystatus/battery.py | 10 +++++++--- i3pystatus/load.py | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 2a88bf5..c62789b 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -115,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}" @@ -128,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 @@ -138,7 +142,7 @@ class BatteryChecker(IntervalModule): def run(self): urgent = False - color = "#ffffff" + color = self.color battery = Battery.create(self.path) @@ -158,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: @@ -179,5 +183,5 @@ class BatteryChecker(IntervalModule): "full_text": formatp(self.format, **fdict).strip(), "instance": self.battery_ident, "urgent": urgent, - "color": color + "color": color, } diff --git a/i3pystatus/load.py b/i3pystatus/load.py index 7fcf1c4..335bd92 100644 --- a/i3pystatus/load.py +++ b/i3pystatus/load.py @@ -11,6 +11,8 @@ 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)."), + ("critical_limit", "Limit under witch one the battery is critical"), + ("critical_color", "The critical color"), ) file = "/proc/loadavg" From 77b03bbc4435ec628c4de15380b5e26e0110a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 16 Apr 2014 17:40:53 +0200 Subject: [PATCH 5/5] Add alert on CPU load --- i3pystatus/load.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/i3pystatus/load.py b/i3pystatus/load.py index 335bd92..6454cb2 100644 --- a/i3pystatus/load.py +++ b/i3pystatus/load.py @@ -11,16 +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, }