aboutsummaryrefslogtreecommitdiffstats
path: root/plasma/applet/contents
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2011-01-16 19:51:17 -0200
committerEugeni Dodonov <eugeni@mandriva.com>2011-01-16 19:51:17 -0200
commit25180fabda6e04c7feafa763b67282b920e1921e (patch)
tree39d1c4916c4a92404fb66cdca3b8d4ca686d3ac8 /plasma/applet/contents
parentac555d6b7644776b4351eb4981dab3aedc135883 (diff)
downloadnet_monitor-25180fabda6e04c7feafa763b67282b920e1921e.tar
net_monitor-25180fabda6e04c7feafa763b67282b920e1921e.tar.gz
net_monitor-25180fabda6e04c7feafa763b67282b920e1921e.tar.bz2
net_monitor-25180fabda6e04c7feafa763b67282b920e1921e.tar.xz
net_monitor-25180fabda6e04c7feafa763b67282b920e1921e.zip
Move applet into plasma/applet/
Diffstat (limited to 'plasma/applet/contents')
-rw-r--r--plasma/applet/contents/code/main.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/plasma/applet/contents/code/main.py b/plasma/applet/contents/code/main.py
new file mode 100644
index 0000000..45f7fec
--- /dev/null
+++ b/plasma/applet/contents/code/main.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+# Net_monitor plasma interface
+#
+# Copyright, (C) Eugeni Dodonov <eugeni@mandriva.com>, 2011
+#
+
+from PyQt4.QtCore import Qt
+from PyKDE4.plasma import Plasma
+from PyKDE4 import plasmascript
+
+# localization
+import gettext
+try:
+ gettext.install("net_monitor")
+except IOError:
+ _ = str
+
+from net_monitor import Monitor
+
+class NetMonitor(plasmascript.Applet):
+ def __init__(self,parent,args=None):
+ plasmascript.Applet.__init__(self,parent)
+
+ self.monitor = Monitor()
+ self.ifaces = self.monitor.readnet()
+
+ self.enabled_ifaces = []
+ self.wireless_ifaces = filter(self.monitor.has_wireless, self.ifaces.keys())
+
+ sorted_ifaces = self.ifaces.keys()
+ sorted_ifaces.sort()
+
+ net=self.monitor.readnet()
+
+ for iface in sorted_ifaces:
+ device_exists, data_in, data_out = self.monitor.get_traffic(iface,net)
+ self.ifaces[iface] = {'data_in': 0,
+ 'data_out': 0,
+ 'total_in': 0,
+ 'total_out': 0,
+ 'graph': None,
+ 'histogram': [],
+ 'address': "",
+ }
+ if self.monitor.has_network_accounting(iface):
+ self.enabled_ifaces.append(iface)
+
+ self.refresh_connections()
+
+ def refresh_connections(self):
+ """Updates connections"""
+ for proto in ["tcp", "udp"]:
+ connections = self.monitor.get_connections(proto=proto)
+ for loc_addr, loc_port, rem_addr, rem_port, status in connections:
+ print "%s - %s - %s - %s - %s - %s" % (proto, loc_addr, loc_port, rem_addr, rem_port, status)
+
+
+ def init(self):
+ self.setHasConfigurationInterface(False)
+ self.resize(125, 125)
+ self.setAspectRatioMode(Plasma.Square)
+
+ def paintInterface(self, painter, option, rect):
+ painter.save()
+ painter.setPen(Qt.black)
+ painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, "Hello net_monitor!")
+ painter.restore()
+
+def CreateApplet(parent):
+ return NetMonitor(parent)