Release 1.4.0

+ added notification
* small refactoring
This commit is contained in:
arcan1s
2013-10-22 16:22:39 +04:00
parent d55d478243
commit 6c9a167aa2
13 changed files with 106 additions and 37 deletions

View File

@ -7,7 +7,7 @@ from PyKDE4.kdeui import *
from PyKDE4.kio import *
from PyKDE4 import plasmascript
from PyKDE4.plasma import Plasma
import commands, os, time
import commands, os, shutil, time
import configdef
import configwindow
@ -21,8 +21,8 @@ class pyTextWidget(plasmascript.Applet):
def __init__(self, parent, args=None):
"""widget definition"""
plasmascript.Applet.__init__(self, parent)
def init(self):
"""function to initializate widget"""
self._name = str(self.package().metadata().pluginName())
@ -39,6 +39,11 @@ class pyTextWidget(plasmascript.Applet):
self.reinit.reinit(confAccept=False)
self.setHasConfigurationInterface(True)
# Create notifyrc file if required
kdehome = unicode(KGlobal.dirs().localkdedir())
if ((not os.path.exists(kdehome + "/share/apps/plasma_applet_pytextmonitor/plasma_applet_pytextmonitor.notifyrc")) or
(not os.path.exists("/usr" + "/share/apps/plasma_applet_pytextmonitor/plasma_applet_pytextmonitor.notifyrc"))):
self.createNotifyrc(kdehome)
def createConfigurationInterface(self, parent):
@ -48,6 +53,14 @@ class pyTextWidget(plasmascript.Applet):
self.configdef.createConfigurationInterface(parent)
def createNotifyrc(self, kdehome):
"""function to create *.notifyrc"""
if (not os.path.isdir(kdehome + "/share/apps/plasma_applet_pytextmonitor")):
os.mkdir(kdehome + "/share/apps/plasma_applet_pytextmonitor")
shutil.copy(kdehome + "/share/apps/plasma/plasmoids/py-text-monitor/contents/code/plasma_applet_pytextmonitor.notifyrc",
kdehome + "/share/apps/plasma_applet_pytextmonitor/")
def initTooltip(self):
"""function to create tooltip"""
self.tooltip = Plasma.ToolTipContent()
@ -57,12 +70,12 @@ class pyTextWidget(plasmascript.Applet):
# show tooltip
#Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
def mouseDoubleClickEvent(self, event):
"""function to doubleclick event"""
os.system("ksysguard &")
def setupNetdev(self):
"""function to setup network device"""
netdev = "lo"
@ -79,8 +92,8 @@ class pyTextWidget(plasmascript.Applet):
except:
pass
return netdev
def setupVar(self):
"""function to setup variables"""
self.netdev = ''
@ -101,8 +114,8 @@ class pyTextWidget(plasmascript.Applet):
def showConfigurationInterface(self):
"""function to show configuration window"""
plasmascript.Applet.showConfigurationInterface(self)
def startPolling(self):
try:
self.timer.start()
@ -114,7 +127,7 @@ class pyTextWidget(plasmascript.Applet):
self.label_error.setText('<font color="red">ERROR</font>')
self.layout.addItem(self.label_error)
return
def updateLabel(self):
"""function to update label"""
if ((self.memBool > 0) and (self.memInMb == False)):
@ -123,8 +136,8 @@ class pyTextWidget(plasmascript.Applet):
self.swapText()
if (self.batBool > 0):
self.batText()
def batText(self):
"""function to set battery text"""
line = self.batFormat
@ -150,8 +163,8 @@ class pyTextWidget(plasmascript.Applet):
line = line.split('$ac')[0] + bat + line.split('$ac')[1]
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
self.label_bat.setText(text)
def memText(self):
"""function to set mem text"""
full = self.mem_uf + self.mem_free
@ -163,8 +176,8 @@ class pyTextWidget(plasmascript.Applet):
line = self.memFormat
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
self.label_mem.setText(text)
def swapText(self):
"""function to set swap text"""
full = self.swap_used + self.swap_free
@ -186,4 +199,4 @@ class pyTextWidget(plasmascript.Applet):
def CreateApplet(parent):
return pyTextWidget(parent)
return pyTextWidget(parent)

View File

@ -37,3 +37,8 @@ Action=Popup
Name=Battery information
Comment=Battery information
Action=Popup
[Event/graphinfo]
Name=Graphical Information
Comment=Graphical Information
Action=Popup

View File

@ -37,12 +37,13 @@ class PTMNotify:
text = text + "Whoami: %s\n" %(commands.getoutput("whoami"))
text = text + "Uptime: %s\n" %(commands.getoutput("uptime"))
except:
pass
text = "Something wrong"
elif (type == "processor"):
try:
output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1")
text = text + "Model: %s\n" %(' '.join(output.split()[3:]))
output = commands.getoutput("sar -u | tail -1")
print "1"
text = text + "CPU Usage: %s%%\n" %(str(100-float(output.split()[-1])))
output = commands.getoutput("grep MHz /proc/cpuinfo | head -1")
text = text + "CPU Freq: %s MHz\n" %(str(int(float(output.split()[-1]))))
@ -52,7 +53,7 @@ class PTMNotify:
if (line.find("_input") > -1):
text = text + " %s\xb0C" %(str(round(float(line.split()[-1]), 0)))
except:
pass
text = "Something wrong"
elif (type == "graphical"):
try:
output = commands.getoutput("lspci -m | grep 'VGA\|3D'")
@ -93,7 +94,7 @@ class PTMNotify:
value = " N\A"
text = text + "Temp: %s\xb0C\n" %(value)
except:
pass
text = "Something wrong"
elif (type == "memory"):
try:
output = commands.getoutput("free -m -o").split("\n")
@ -103,14 +104,14 @@ class PTMNotify:
output = commands.getoutput("swapon --show").split("\n")
text = text + "Swap Device: %s (%s)" %(output[1].split()[0], output[1].split()[1])
except:
pass
text = "Something wrong"
elif (type == "disk"):
try:
output = commands.getoutput("df -h --output='source,target,used,size,pcent' --exclude-type=fuseblk --exclude-type=tmpfs --exclude-type=devtmpfs").split("\n")[1:]
for line in output:
text = text + "%s (to %s): %s of %s (%s)\n" %(line.split()[0], line.split()[1], line.split()[2], line.split()[3], line.split()[4])
except:
pass
text = "Something wrong"
elif (type == "network"):
try:
output = commands.getoutput("ifconfig -a -s").split("\n")[1:]
@ -126,12 +127,12 @@ class PTMNotify:
output = commands.getoutput("wget http://checkip.dyndns.org/ -q -O - | awk '{print $6}' | sed 's/<.*>//g'")
text = text + "External IP: %s" %(output[:-1])
except:
pass
text = "Something wrong"
elif (type == "battery"):
try:
text = text + "%s" %(commands.getoutput("acpi -abi"))
except:
pass
text = "Something wrong"
content = [type, text]
return content

View File

@ -16,7 +16,7 @@ class NewPlasmaLabel(Plasma.Label):
self.parent = parent
self.notify = ptmnotify.PTMNotify(self)
def mousePressEvent(self, event):
"""mouse click event"""
if (event.button() == Qt.LeftButton):
@ -49,6 +49,7 @@ class Reinit():
else:
exec ('self.parent.' + label + 'Bool = int(settings.get("' + label + 'Bool", 0))')
# labels
for order in self.parent.label_order:
if (order == "1"):
if (self.parent.cpuBool > 0):
@ -101,7 +102,7 @@ class Reinit():
self.parent.memFormat = str(settings.get('memFormat', '[mem: $mem%]'))
if (self.parent.memFormat.split('$memmb')[0] != self.parent.memFormat):
self.parent.memInMb = True
text = self.parent.formatLine.split('$LINE')[0] + self.parent.memFormat.split('$memmb')[0] + '-----' + self.parent.memFormat.split('$memmb')[1] + self.parent.formatLine.split('$LINE')[1]
line = self.parent.memFormat.split('$memmb')[0] + '-----' + self.parent.memFormat.split('$memmb')[1]
elif (self.parent.memFormat.split('$mem')[0] != self.parent.memFormat):
self.parent.memInMb = False
self.parent.mem_used = 0.0
@ -119,7 +120,7 @@ class Reinit():
self.parent.swapFormat = str(settings.get('swapFormat', '[swap: $swap%]'))
if (self.parent.swapFormat.split('$swapmb')[0] != self.parent.swapFormat):
self.parent.swapInMb = True
text = self.parent.formatLine.split('$LINE')[0] + self.parent.swapFormat.split('$swapmb')[0] + '-----' + self.parent.swapFormat.split('$swapmb')[1] + self.parent.formatLine.split('$LINE')[1]
line = self.parent.swapFormat.split('$swapmb')[0] + '-----' + self.parent.swapFormat.split('$swapmb')[1]
elif (self.parent.swapFormat.split('$swap')[0] != self.parent.swapFormat):
self.parent.swapInMb = False
self.parent.swap_free = 1.0
@ -281,7 +282,7 @@ class Reinit():
self.parent.theme = Plasma.Svg(self.parent)
self.parent.theme.setImagePath("widgets/background")
self.parent.setBackgroundHints(Plasma.Applet.DefaultBackground)
self.parent.resize(10,10)
self.parent.resize(10, 10)
# create dataengines
self.parent.thread().wait(60000)