diff options
author | Mattias Andrée <maandree@kth.se> | 2021-06-26 13:18:37 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-06-26 13:18:37 +0200 |
commit | 3e21f6d13c0a70db95fec8b5a71b758223ff4293 (patch) | |
tree | 6d6d2eddb243935007ce1e316c61470224f93df0 /xpybar/config/mytop.py | |
parent | Add inputrc for readline + m (diff) | |
download | dotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.gz dotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.bz2 dotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.xz |
Add xpybar
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | xpybar/config/mytop.py | 40 |
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 |