From 25180fabda6e04c7feafa763b67282b920e1921e Mon Sep 17 00:00:00 2001 From: Eugeni Dodonov Date: Sun, 16 Jan 2011 19:51:17 -0200 Subject: Move applet into plasma/applet/ --- plasma/Makefile | 7 ---- plasma/applet/Makefile | 7 ++++ plasma/applet/contents/code/main.py | 70 +++++++++++++++++++++++++++++++++++++ plasma/applet/metadata.desktop | 17 +++++++++ plasma/contents/code/main.py | 70 ------------------------------------- plasma/metadata.desktop | 17 --------- 6 files changed, 94 insertions(+), 94 deletions(-) delete mode 100644 plasma/Makefile create mode 100644 plasma/applet/Makefile create mode 100644 plasma/applet/contents/code/main.py create mode 100644 plasma/applet/metadata.desktop delete mode 100644 plasma/contents/code/main.py delete mode 100644 plasma/metadata.desktop (limited to 'plasma') diff --git a/plasma/Makefile b/plasma/Makefile deleted file mode 100644 index ba9252b..0000000 --- a/plasma/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: plasmapkg - -plasmapkg: - zip -r ../net_monitor_plasma.zip contents/ metadata.desktop - -clean: - rm -f ../net_monitor_plasma.zip diff --git a/plasma/applet/Makefile b/plasma/applet/Makefile new file mode 100644 index 0000000..ba9252b --- /dev/null +++ b/plasma/applet/Makefile @@ -0,0 +1,7 @@ +all: plasmapkg + +plasmapkg: + zip -r ../net_monitor_plasma.zip contents/ metadata.desktop + +clean: + rm -f ../net_monitor_plasma.zip 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 , 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) diff --git a/plasma/applet/metadata.desktop b/plasma/applet/metadata.desktop new file mode 100644 index 0000000..87c2db8 --- /dev/null +++ b/plasma/applet/metadata.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Network Monitor +Type=Service +ServiceTypes=Plasma/Applet +Icon=chronometer +X-Plasma-API=python +X-Plasma-MainScript=code/main.py +X-KDE-PluginInfo-Author=Eugeni Dodonov +X-KDE-PluginInfo-Email=eugeni@mandriva.com +X-KDE-PluginInfo-Name=net_monitor +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://git.mandriva.com/ +X-KDE-PluginInfo-Category=Network +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plasma/contents/code/main.py b/plasma/contents/code/main.py deleted file mode 100644 index 45f7fec..0000000 --- a/plasma/contents/code/main.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- -# Net_monitor plasma interface -# -# Copyright, (C) Eugeni Dodonov , 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) diff --git a/plasma/metadata.desktop b/plasma/metadata.desktop deleted file mode 100644 index 87c2db8..0000000 --- a/plasma/metadata.desktop +++ /dev/null @@ -1,17 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Name=Network Monitor -Type=Service -ServiceTypes=Plasma/Applet -Icon=chronometer -X-Plasma-API=python -X-Plasma-MainScript=code/main.py -X-KDE-PluginInfo-Author=Eugeni Dodonov -X-KDE-PluginInfo-Email=eugeni@mandriva.com -X-KDE-PluginInfo-Name=net_monitor -X-KDE-PluginInfo-Version=1.0 -X-KDE-PluginInfo-Website=http://git.mandriva.com/ -X-KDE-PluginInfo-Category=Network -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=true -- cgit v1.2.1