From d5a91f566ef04138b50ed87318318ba40ac0a4b7 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 8 Oct 2013 00:49:55 +0400 Subject: [PATCH] Added notification for cpu/cpuclock/temp + notification carcass --- sources/contents/code/configdef.py | 8 +- sources/contents/code/dataengine.py | 4 +- sources/contents/code/ptmnotify.py | 111 ++++++++++++++++++++++++++-- sources/contents/code/reinit.py | 32 ++++---- 4 files changed, 127 insertions(+), 28 deletions(-) diff --git a/sources/contents/code/configdef.py b/sources/contents/code/configdef.py index 1bbafd1..fef6d46 100644 --- a/sources/contents/code/configdef.py +++ b/sources/contents/code/configdef.py @@ -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): diff --git a/sources/contents/code/dataengine.py b/sources/contents/code/dataengine.py index 4055b4c..b4b4669 100644 --- a/sources/contents/code/dataengine.py +++ b/sources/contents/code/dataengine.py @@ -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: diff --git a/sources/contents/code/ptmnotify.py b/sources/contents/code/ptmnotify.py index dd862a4..5c598d9 100644 --- a/sources/contents/code/ptmnotify.py +++ b/sources/contents/code/ptmnotify.py @@ -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 diff --git a/sources/contents/code/reinit.py b/sources/contents/code/reinit.py index 349de78..a4b53ef 100644 --- a/sources/contents/code/reinit.py +++ b/sources/contents/code/reinit.py @@ -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', '