diff options
Diffstat (limited to 'xpybar/config/mynews.py')
-rw-r--r-- | xpybar/config/mynews.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/xpybar/config/mynews.py b/xpybar/config/mynews.py new file mode 100644 index 0000000..a65396e --- /dev/null +++ b/xpybar/config/mynews.py @@ -0,0 +1,45 @@ +# -*- python -*- +import os +from common import * + +class MyNews(Entry): + def __init__(self, *args, status_path = None, **kwargs): + if status_path is not None: + self.status_path = status_path + else: + self.status_path = HOME + '/.var/lib/featherweight/status' + self.get_news() + Entry.__init__(self, *args, **kwargs) + xasync(self.refresh, name = 'news') + + def action(self, col, button, x, y): + if button == LEFT_BUTTON: + xasync(lambda : subprocess.Popen([G.TERMINAL, '-e', 'featherweight']).wait()) + elif button == RIGHT_BUTTON: + xasync(lambda : subprocess.Popen(['featherweight', '--update', '--system']).wait()) + + def get_news(self): + try: + with open(self.status_path, 'rb') as file: + status = int(file.read().decode('utf-8', 'replace').replace('\n', '')) + except: + status = 0 + colour = '31' + if status <= 0: colour = '39' + elif status <= 5: colour = '32' + elif status <= 10: colour = '33' + self.text = 'News: \033[%sm%i\033[0m' % (colour, status) + + def refresh(self): + while True: + if os.path.exists(self.status_path): + try: + spawn_read(*pdeath('HUP', 'inotifywait', self.status_path, '-e', 'close_write')) + self.get_news() + except: + time.sleep(1) + else: + time.sleep(1) + + def function(self): + return self.text |