blob: 6dc141562ca10f998f3404cabddeb1ca6f93536f (
plain) (
tree)
|
|
# -*- 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
|