1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
|