Added notification for cpu/cpuclock/temp

+ notification carcass
This commit is contained in:
arcan1s 2013-10-08 00:49:55 +04:00
parent 3994652562
commit d5a91f566e
4 changed files with 127 additions and 28 deletions

View File

@ -44,8 +44,8 @@ class ConfigDefinition:
if (self.parent.cpuBool > 0):
self.parent.systemmonitor.disconnectSource("cpu/system/TotalLoad", self.parent)
if (self.parent.cpuFormat.split('$ccpu')[0] != self.parent.cpuFormat):
self.parent.label_cpu0.setText('')
self.parent.layout.removeItem(self.parent.label_cpu0)
self.parent.label_cpu.setText('')
self.parent.layout.removeItem(self.parent.label_cpu)
self.parent.label_cpu1.setText('')
self.parent.layout.removeItem(self.parent.label_cpu1)
for core in range(self.parent.numCores):
@ -58,8 +58,8 @@ class ConfigDefinition:
if (self.parent.cpuclockBool > 0):
self.parent.systemmonitor.disconnectSource("cpu/system/AverageClock", self.parent)
if (self.parent.cpuclockFormat.split('$ccpu')[0] != self.parent.cpuclockFormat):
self.parent.label_cpuclock0.setText('')
self.parent.layout.removeItem(self.parent.label_cpuclock0)
self.parent.label_cpuclock.setText('')
self.parent.layout.removeItem(self.parent.label_cpuclock)
self.parent.label_cpuclock1.setText('')
self.parent.layout.removeItem(self.parent.label_cpuclock1)
for core in range(self.parent.numCores):

View File

@ -81,7 +81,7 @@ class DataEngine:
else:
line = self.parent.cpuFormat.split('$ccpu')[0]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_cpu0.setText(text)
self.parent.label_cpu.setText(text)
if (self.parent.cpuFormat.split('$ccpu')[1].split('$cpu')[0] != self.parent.cpuFormat.split('$ccpu')[1]):
line = self.parent.cpuFormat.split('$ccpu')[1].split('$cpu')[0] + cpuText + self.parent.cpuFormat.split('$ccpu')[1].split('$cpu')[1]
else:
@ -109,7 +109,7 @@ class DataEngine:
else:
line = self.parent.cpuclockFormat.split('$ccpucl')[0]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_cpuclock0.setText(text)
self.parent.label_cpuclock.setText(text)
if (self.parent.cpuclockFormat.split('$ccpucl')[1].split('$cpucl')[0] != self.parent.cpuclockFormat.split('$ccpucl')[1]):
line = self.parent.cpuclockFormat.split('$ccpucl')[1].split('$cpucl')[0] + cpuclockText + self.parent.cpuclockFormat.split('$ccpucl')[1].split('$cpucl')[1]
else:

View File

@ -27,14 +27,113 @@ class PTMNotify:
notification.sendEvent();
def initText(self, sender):
def createText(self, type):
"""function to create text"""
content = []
if (sender == self.parent.parent.label_uptime):
if (type == "system"):
content.append("system")
text = "Kernel: " + commands.getoutput("uname -rsm") + "\n"
text = text + "Hostname: " + commands.getoutput("uname -n") + "\n"
text = text + "Whoami: " + commands.getoutput("whoami") + "\n"
text = text + "Uptime: " + commands.getoutput("uptime")
text = ""
try:
text = text + "Kernel: " + commands.getoutput("uname -rsm") + "\n"
text = text + "Hostname: " + commands.getoutput("uname -n") + "\n"
text = text + "Whoami: " + commands.getoutput("whoami") + "\n"
text = text + "Uptime: " + commands.getoutput("uptime")
except:
pass
content.append(text)
elif (type == "processor"):
content.append("processor")
text = ""
try:
output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1")
text = text + "Model: " + ' '.join(output.split()[3:]) + "\n"
output = commands.getoutput("sar -u | tail -1")
text = text + "CPU Usage: " + str(100-float(output[-1])) + "%\n"
output = commands.getoutput("grep MHz /proc/cpuinfo | head -1")
text = text + "CPU Freq: " + str(int(float(output.split()[-1]))) + " MHz\n"
output = commands.getoutput("sensors -u")
text = text + "Temps:"
for line in output.split("\n"):
if (line.find("_input") > -1):
text = text + " " + str(round(float(line.split()[-1]), 0)) + "\xb0C"
except:
pass
content.append(text)
return content
def initText(self, sender):
"""function to send text"""
try:
if (sender == self.parent.parent.label_uptime):
content = self.createText("system")
return content
except:
pass
try:
if (sender == self.parent.parent.label_cpu):
content = self.createText("processor")
return content
except:
pass
try:
if (sender == self.parent.parent.label_cpuclock):
content = self.createText("processor")
return content
except:
pass
try:
if (sender == self.parent.parent.label_temp):
content = self.createText("processor")
return content
except:
pass
try:
if (sender == self.parent.parent.label_gpu):
content = self.createText("graphical")
return content
except:
pass
try:
if (sender == self.parent.parent.label_gputemp):
content = self.createText("graphical")
return content
except:
pass
try:
if (sender == self.parent.parent.label_mem):
content = self.createText("memory")
return content
except:
pass
try:
if (sender == self.parent.parent.label_swap):
content = self.createText("memory")
return content
except:
pass
try:
if (sender == self.parent.parent.label_hdd0):
content = self.createText("hdd")
return content
except:
pass
try:
if (sender == self.parent.parent.label_hddtemp):
content = self.createText("hdd")
return content
except:
pass
try:
if (sender == self.parent.parent.label_netDown):
content = self.createText("network")
return content
except:
pass
try:
if (sender == self.parent.parent.label_bat):
content = self.createText("acpi")
return content
except:
pass

View File

@ -53,15 +53,15 @@ class Reinit():
if (self.parent.cpuBool > 0):
self.parent.cpuFormat = str(settings.get('cpuFormat', '[cpu: $cpu%]'))
if (self.parent.cpuFormat.split('$ccpu')[0] != self.parent.cpuFormat):
self.parent.label_cpu0 = Plasma.Label(self.parent.applet)
self.parent.label_cpu = NewPlasmaLabel(self.parent.applet, self.parent)
self.parent.label_cpu1 = Plasma.Label(self.parent.applet)
if (self.parent.cpuFormat.split('$ccpu')[0].split('$cpu')[0] != self.parent.cpuFormat.split('$ccpu')[0]):
line = self.parent.cpuFormat.split('$ccpu')[0].split('$cpu')[0] + '-----' + self.parent.cpuFormat.split('$ccpu')[0].split('$cpu')[1]
else:
line = self.parent.cpuFormat.split('$ccpu')[0]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_cpu0.setText(text)
self.parent.layout.addItem(self.parent.label_cpu0)
self.parent.label_cpu.setText(text)
self.parent.layout.addItem(self.parent.label_cpu)
text = self.parent.formatLine.split('$LINE')[0] + "-----" + self.parent.formatLine.split('$LINE')[1]
for core in range(self.parent.numCores):
exec ('self.parent.label_coreCpu' + str(core) + ' = Plasma.Label(self.parent.applet)')
@ -75,7 +75,7 @@ class Reinit():
self.parent.label_cpu1.setText(text)
self.parent.layout.addItem(self.parent.label_cpu1)
else:
self.parent.label_cpu = Plasma.Label(self.parent.applet)
self.parent.label_cpu = NewPlasmaLabel(self.parent.applet, self.parent)
if (self.parent.cpuFormat.split('$cpu')[0] != self.parent.cpuFormat):
line = self.parent.cpuFormat.split('$cpu')[0] + '-----' + self.parent.cpuFormat.split('$cpu')[1]
else:
@ -87,7 +87,7 @@ class Reinit():
if (self.parent.tempBool > 0):
self.parent.tempdev = str(settings.get('temp_device', '<select device>'))
self.parent.tempFormat = str(settings.get('tempFormat', '[temp: $temp&deg;C]'))
self.parent.label_temp = Plasma.Label(self.parent.applet)
self.parent.label_temp = NewPlasmaLabel(self.parent.applet, self.parent)
if (self.parent.tempFormat.split('$temp')[0] != self.parent.tempFormat):
line = self.parent.tempFormat.split('$temp')[0] + '----' + self.parent.tempFormat.split('$temp')[1]
else:
@ -110,7 +110,7 @@ class Reinit():
else:
line = self.parent.memFormat
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_mem = Plasma.Label(self.parent.applet)
self.parent.label_mem = NewPlasmaLabel(self.parent.applet, self.parent)
self.parent.label_mem.setText(text)
self.parent.layout.addItem(self.parent.label_mem)
elif (order == "4"):
@ -127,7 +127,7 @@ class Reinit():
else:
line = self.parent.swapFormat
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_swap = Plasma.Label(self.parent.applet)
self.parent.label_swap = NewPlasmaLabel(self.parent.applet, self.parent)
self.parent.label_swap.setText(text)
self.parent.layout.addItem(self.parent.label_swap)
elif (order == "5"):
@ -142,7 +142,7 @@ class Reinit():
self.parent.netFormat = self.parent.netNonFormat.split('$netdev')[0] + self.parent.netdev + self.parent.netNonFormat.split('$netdev')[1]
else:
self.parent.netFormat = self.parent.netNonFormat
self.parent.label_netDown = Plasma.Label(self.parent.applet)
self.parent.label_netDown = NewPlasmaLabel(self.parent.applet, self.parent)
if (self.parent.netFormat.split('$net')[0] != self.parent.netFormat):
line = self.parent.netFormat.split('$net')[0] + '----'
else:
@ -163,7 +163,7 @@ class Reinit():
self.parent.batFormat = str(settings.get('batFormat', '[bat: $bat%$ac]'))
self.parent.battery_device= str(settings.get('battery_device', '/sys/class/power_supply/BAT0/capacity'))
self.parent.ac_device = str(settings.get('ac_device', '/sys/class/power_supply/AC/online'))
self.parent.label_bat = Plasma.Label(self.parent.applet)
self.parent.label_bat = NewPlasmaLabel(self.parent.applet, self.parent)
line = self.parent.batFormat
if (line.split('$ac')[0] != line):
line = line.split('$ac')[0] + '(-)' + line.split('$ac')[1]
@ -173,18 +173,18 @@ class Reinit():
self.parent.label_bat.setText(text)
self.parent.layout.addItem(self.parent.label_bat)
elif (order == "7"):
if (self.parent.cpuclockBoo> 0):
if (self.parent.cpuclockBool > 0):
self.parent.cpuclockFormat = str(settings.get('cpuclockFormat', '[mhz: $cpucl]'))
if (self.parent.cpuclockFormat.split('$ccpucl')[0] != self.parent.cpuclockFormat):
self.parent.label_cpuclock0 = Plasma.Label(self.parent.applet)
self.parent.label_cpuclock = NewPlasmaLabel(self.parent.applet, self.parent)
self.parent.label_cpuclock1 = Plasma.Label(self.parent.applet)
if (self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] != self.parent.cpuclockFormat.split('$ccpucl')[0]):
line = self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] + '----' + self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[1]
else:
line = self.parent.cpuclockFormat.split('$ccpucl')[0]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_cpuclock0.setText(text)
self.parent.layout.addItem(self.parent.label_cpuclock0)
self.parent.label_cpuclock.setText(text)
self.parent.layout.addItem(self.parent.label_cpuclock)
text = self.parent.formatLine.split('$LINE')[0] + "----" + self.parent.formatLine.split('$LINE')[1]
for core in range(self.parent.numCores):
exec ('self.parent.label_coreCpuclock' + str(core) + ' = Plasma.Label(self.parent.applet)')
@ -198,7 +198,7 @@ class Reinit():
self.parent.label_cpuclock1.setText(text)
self.parent.layout.addItem(self.parent.label_cpuclock1)
else:
self.parent.label_cpuclock = Plasma.Label(self.parent.applet)
self.parent.label_cpuclock = NewPlasmaLabel(self.parent.applet, self.parent)
if (self.parent.cpuclockFormat.split('$cpucl')[0] != self.parent.cpuclockFormat):
line = self.parent.cpuclockFormat.split('$cpucl')[0] + '----' + self.parent.cpuclockFormat.split('$cpucl')[1]
else:
@ -246,7 +246,7 @@ class Reinit():
self.parent.mountPoints = self.parent.hddFormat.split('@@')[1].split(';')
line = self.parent.hddFormat.split('@@')[0]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_hdd0 = Plasma.Label(self.parent.applet)
self.parent.label_hdd0 = NewPlasmaLabel(self.parent.applet, self.parent)
self.parent.label_hdd0.setText(text)
self.parent.layout.addItem(self.parent.label_hdd0)
text = self.parent.formatLine.split('$LINE')[0] + "-----" + self.parent.formatLine.split('$LINE')[1]
@ -267,7 +267,7 @@ class Reinit():
elif (order == "c"):
if (self.parent.hddtempBool > 0):
self.parent.hddtempFormat = str(settings.get('hddtempFormat', '[hdd temp: @@/dev/sda@@&deg;C]'))
self.parent.label_hddtemp = Plasma.Label(self.parent.applet)
self.parent.label_hddtemp = NewPlasmaLabel(self.parent.applet, self.parent)
if (self.parent.hddtempFormat.split('@@')[0] != self.parent.hddtempFormat):
line = self.parent.hddtempFormat.split('@@')[0] + '----' + self.parent.hddtempFormat.split('@@')[2]
else: