aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/mytop.py
diff options
context:
space:
mode:
Diffstat (limited to 'xpybar/config/mytop.py')
-rw-r--r--xpybar/config/mytop.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/xpybar/config/mytop.py b/xpybar/config/mytop.py
new file mode 100644
index 0000000..6dc1415
--- /dev/null
+++ b/xpybar/config/mytop.py
@@ -0,0 +1,40 @@
+# -*- python -*-
+from common import *
+
+class MyTop(Entry):
+ def __init__(self, *args, **kwargs):
+ self.show_pid = True
+ self.show_cpu = True
+ self.show_label = True
+ self.show_nic = None
+ self.top_cmd = pdeath('HUP', 'top', '-b', '-n', '1', '-o', '%CPU', '-w', '10000')
+ self.refresh()
+ Entry.__init__(self, *args, **kwargs)
+ xasync(lambda : watch(5, t(self.refresh)), name = 'top')
+
+ def action(self, col, button, x, y):
+ if button == LEFT_BUTTON:
+ self.show_pid = not self.show_pid
+ elif button == MIDDLE_BUTTON:
+ self.show_label = not self.show_label
+ elif button == RIGHT_BUTTON:
+ self.show_cpu = not self.show_cpu
+ else:
+ return
+ self.refresh()
+ self.invalidate()
+
+ def refresh(self):
+ top = spawn_read(*self.top_cmd).split('\n')
+ top = [line for line in top if not line.startswith('%')][6]
+ top = [col for col in top.replace('\t', ' ').split(' ') if not col == '']
+ text = 'Top: ' if self.show_label else ''
+ if self.show_pid:
+ text += top[0] + ' '
+ if self.show_cpu:
+ text += top[6] + ' '
+ text += ' '.join(top[10:])
+ self.text = text
+
+ def function(self):
+ return self.text