aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/mystat.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-06-26 13:18:37 +0200
committerMattias Andrée <maandree@kth.se>2021-06-26 13:18:37 +0200
commit3e21f6d13c0a70db95fec8b5a71b758223ff4293 (patch)
tree6d6d2eddb243935007ce1e316c61470224f93df0 /xpybar/config/mystat.py
parentAdd inputrc for readline + m (diff)
downloaddotfiles-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/mystat.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/xpybar/config/mystat.py b/xpybar/config/mystat.py
new file mode 100644
index 0000000..d358d15
--- /dev/null
+++ b/xpybar/config/mystat.py
@@ -0,0 +1,91 @@
+# -*- python -*-
+from plugins.snmp import SNMP
+from plugins.snmp6 import SNMP6
+from plugins.uptime import Uptime
+from plugins.vmstat import VMStat
+
+from common import *
+
+class MyStat(Entry):
+ def __init__(self, *args, **kwargs):
+ self.keys_4 = SNMP().keys
+ self.keys_6 = SNMP6().keys
+ self.keys_vm = VMStat().keys
+ self.show_group = 0
+ self.show_value_4 = 0
+ self.show_value_6 = 0
+ self.show_value_vm = 0
+ Entry.__init__(self, *args, **kwargs)
+
+ def action(self, col, button, x, y):
+ if button == LEFT_BUTTON:
+ n = self.show_group + 1
+ if n < 4:
+ self.show_group = n
+ self.invalidate()
+ elif button == MIDDLE_BUTTON:
+ self.invalidate()
+ elif button == RIGHT_BUTTON:
+ n = self.show_group
+ if n > 0:
+ self.show_group = n - 1
+ self.invalidate()
+ elif button == SCROLL_UP:
+ if self.show_group == 0:
+ n = self.show_value_4
+ if n + 1 < len(self.keys_4):
+ self.show_value_4 = n + 1
+ self.invalidate()
+ elif self.show_group == 1:
+ n = self.show_value_6
+ if n + 1 < len(self.keys_6):
+ self.show_value_6 = n + 1
+ self.invalidate()
+ elif self.show_group == 2:
+ n = self.show_value_vm
+ if n + 1 < len(self.keys_vm):
+ self.show_value_vm = n + 1
+ self.invalidate()
+ elif self.show_group == 3:
+ pass
+ elif button == SCROLL_DOWN:
+ if self.show_group == 0:
+ n = self.show_value_4
+ if n > 0:
+ self.show_value_4 = n - 1
+ self.invalidate()
+ elif self.show_group == 1:
+ n = self.show_value_6
+ if n > 0:
+ self.show_value_6 = n - 1
+ self.invalidate()
+ elif self.show_group == 2:
+ n = self.show_value_vm
+ if n > 0:
+ self.show_value_vm = n - 1
+ self.invalidate()
+ elif self.show_group == 3:
+ pass
+
+ def function(self):
+ try:
+ if self.show_group == 0:
+ label = self.keys_4[self.show_value_4]
+ value = SNMP()[label]
+ elif self.show_group == 1:
+ label = self.keys_6[self.show_value_6]
+ value = SNMP6()[label]
+ elif self.show_group == 2:
+ label = self.keys_vm[self.show_value_vm]
+ value = VMStat()[label]
+ label = ''.join(w[:1].upper() + w[1:] for w in label.split('_'))
+ elif self.show_group == 3:
+ uptime = Uptime()
+ avg = uptime.uptime_seconds - uptime.average_idle_seconds
+ wrk = (avg) * 100 / uptime.uptime_seconds
+ up = '%id%i:%02i' % uptime.uptime[:3]
+ avg = '%id%i:%02i' % Uptime.split_time(avg)[:3]
+ return 'Uptime: %.0f%% %s / %s' % (wrk, avg, up)
+ return '%s: %i' % (label, value)
+ except Exception as e:
+ return str(e)