diff options
author | Von Random <von@vdrandom.org> | 2018-04-28 19:40:10 +0300 |
---|---|---|
committer | Von Random <von@vdrandom.org> | 2018-04-28 19:40:10 +0300 |
commit | 9cd7b68967c2c105ba1ca5f8691f115c901132b0 (patch) | |
tree | 0f3277232dcc936ff76d8612dbf2aa7c97607758 | |
parent | 5e17aca8e2b31d14b75fb55d589b8e216dc4ab49 (diff) |
a bit of refactoring, now batt and pacman plugins have more options
-rw-r--r-- | plugins/batt.py | 32 | ||||
-rw-r--r-- | plugins/pacman.py | 13 |
2 files changed, 22 insertions, 23 deletions
diff --git a/plugins/batt.py b/plugins/batt.py index b0e53f6..90c52ea 100644 --- a/plugins/batt.py +++ b/plugins/batt.py @@ -6,24 +6,24 @@ BATTERY_DIR = '/sys/class/power_supply/BAT0/' class PluginThread(plugins.PluginThreadCommon): def __init__(self, config): - super(PluginThread, self).__init__(config) + defaults = { + 'problem': 15, + 'symbol_charging': '\u2191', + 'symbol_discharging': '\u2193' + } + super(PluginThread, self).__init__(config, defaults) def main(self): with \ - open(BATTERY_DIR + 'capacity', 'r') as capacity, \ - open(BATTERY_DIR + 'status', 'r') as status: - batt_stat = status.read().strip() - batt_capacity = capacity.read().strip() - if batt_stat != 'Discharging': - batt_stat = '\u2191' - if float(batt_capacity) < 15: - self.status['urgent'] = True - else: - self.status['urgent'] = False - else: - batt_stat = '\u2193' + open(BATTERY_DIR + 'capacity', 'r') as batt_capacity, \ + open(BATTERY_DIR + 'status', 'r') as batt_status: + status = batt_status.read().strip() + capacity = batt_capacity.read().strip() + if status != 'Discharging': + symbol = self.conf['symbol_charging'] self.status['urgent'] = False + else: + symbol = self.conf['symbol_discharging'] + self.status['urgent'] = float(capacity) <= self.conf['problem'] - batt = 'BAT: ' + batt_capacity + '% ' + batt_stat - - self.status['full_text'] = batt + self.status['full_text'] = 'BAT: ' + capacity + '% ' + symbol diff --git a/plugins/pacman.py b/plugins/pacman.py index e162f12..853bb6b 100644 --- a/plugins/pacman.py +++ b/plugins/pacman.py @@ -4,18 +4,17 @@ import subprocess class PluginThread(plugins.PluginThreadCommon): def __init__(self, config): - defaults = {'freq': 15} + defaults = { + 'freq': 15, + 'problem': 10 + } super(PluginThread, self).__init__(config, defaults) self.format_status(0) def format_status(self, count): self.status['full_text'] = 'UPD: ' + str(count) - if count > 0: - self.hide = False - self.status['urgent'] = True - else: - self.hide = True - self.status['urgent'] = False + self.hide = count == 0 + self.status['urgent'] = count >= self.conf['problem'] def main(self): # TODO: this is an ugly hack, fix it with subprocess.Popen asap |