From 3e21f6d13c0a70db95fec8b5a71b758223ff4293 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 26 Jun 2021 13:18:37 +0200 Subject: Add xpybar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- xpybar/config/mytop.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 xpybar/config/mytop.py (limited to 'xpybar/config/mytop.py') 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 -- cgit v1.2.3-70-g09d2