edited notifications

This commit is contained in:
arcan1s 2014-04-05 18:11:51 +04:00
parent 614e15d336
commit 329457955d
4 changed files with 128 additions and 184 deletions

View File

@ -8,13 +8,15 @@ pkgdesc="Minimalistic Plasmoid script written on Python2. It looks like widgets
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
url="http://arcanis.name/projects/pytextmonitor" url="http://arcanis.name/projects/pytextmonitor"
license=('GPLv3') license=('GPLv3')
depends=('kdebase-workspace' 'kdebindings-python2' 'lm_sensors' 'sysstat') depends=('kdebase-workspace' 'kdebindings-python2' 'lm_sensors')
optdepends=("hddtemp: for HDD temperature monitor" optdepends=("amarok: for music player monitor"
"catalyst: for GPU monitor" "catalyst: for GPU monitor"
"nvidia-utils: for GPU monitor" "hddtemp: for HDD temperature monitor"
"amarok: for music player monitor"
"mpd: for music player monitor" "mpd: for music player monitor"
"qmmp: for music player monitor") "net-tools for popup messages"
"nvidia-utils: for GPU monitor"
"qmmp: for music player monitor"
"sysstat: for popup messages")
makedepends=('automoc4' 'cmake') makedepends=('automoc4' 'cmake')
source=(https://github.com/arcan1s/pytextmonitor/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz) source=(https://github.com/arcan1s/pytextmonitor/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
install=${pkgname}.install install=${pkgname}.install

View File

@ -36,19 +36,19 @@ from util import *
class NewPlasmaLabel(Plasma.Label): class CustomPlasmaLabel(Plasma.Label):
"""new Label with defined clicked() event""" """new Label with defined clicked() event"""
def __init__(self, applet, parent): def __init__(self, applet, name):
"""class definition""" """class definition"""
Plasma.Label.__init__(self, applet) Plasma.Label.__init__(self, applet)
self.parent = parent self.name = name
self.notify = ptmnotify.PTMNotify(self) self.notify = ptmnotify.PTMNotify(self)
def mousePressEvent(self, event): def mousePressEvent(self, event):
"""mouse click event""" """mouse click event"""
if (event.button() == Qt.LeftButton): if (event.button() == Qt.LeftButton):
self.notify.init() self.notify.init(self.name)
@ -374,7 +374,7 @@ class pyTextWidget(plasmascript.Applet):
def addLabel(self, name=None, text=None, add=True): def addLabel(self, name=None, text=None, add=True):
"""function to add new label""" """function to add new label"""
if (add): if (add):
self.ptm['labels'][name] = NewPlasmaLabel(self.applet, self) self.ptm['labels'][name] = CustomPlasmaLabel(self.applet, name)
self.ptm['layout'].addItem(self.ptm['labels'][name]) self.ptm['layout'].addItem(self.ptm['labels'][name])
self.setText(name, text) self.setText(name, text)
else: else:

View File

@ -26,12 +26,11 @@ import commands
class PTMNotify: class PTMNotify:
def __init__(self, parent): def __init__(self, parent):
"""class definition""" """class definition"""
self.parent = parent
def init(self): def init(self, name=None):
"""function to init notification""" """function to init notification"""
content = self.initText(self.parent) content = self.initText(name)
self.createNotify(content) self.createNotify(content)
@ -47,27 +46,15 @@ class PTMNotify:
def createText(self, type): def createText(self, type):
"""function to create text""" """function to create text"""
text = "" text = ""
if (type == "system"): if (type == "battery"):
try: try:
text = text + "Kernel: %s\n" %(commands.getoutput("uname -rsm")) text = "%s" %(commands.getoutput("acpi -abi"))
text = text + "Hostname: %s\n" %(commands.getoutput("uname -n"))
text = text + "Whoami: %s\n" %(commands.getoutput("whoami"))
text = text + "Uptime: %s\n" %(commands.getoutput("uptime"))
except: except:
text = "Something wrong" text = "Something wrong"
elif (type == "processor"): elif (type == "disk"):
try: try:
output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1") for line in commands.getoutput("df -h --output='source,target,used,size,pcent' --exclude-type=fuseblk --exclude-type=tmpfs --exclude-type=devtmpfs").split("\n")[1:]:
text = text + "Model: %s\n" %(' '.join(output.split()[3:])) 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])
output = commands.getoutput("sar -u | tail -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]))))
output = commands.getoutput("sensors -u")
text = text + "Temps:"
for line in output.split("\n"):
if (line.find("_input") > -1):
text = text + " %s\xb0C" %(str(round(float(line.split()[-1]), 0)))
except: except:
text = "Something wrong" text = "Something wrong"
elif (type == "graphical"): elif (type == "graphical"):
@ -78,75 +65,63 @@ class PTMNotify:
elif (output.lower().find('radeon') > -1): elif (output.lower().find('radeon') > -1):
gpudev = "ati" gpudev = "ati"
for line in output.split("\n"): for line in output.split("\n"):
text = text + "%s %s\n" %(line.split('"')[0], line.split('"')[5]) text = text + "%s %s\n" % (line.split('"')[0], line.split('"')[5])
if (gpudev == 'nvidia'): if (gpudev == 'nvidia'):
output = commands.getoutput("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1") output = commands.getoutput("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1")
try: try:
value = "%5s" % (str(round(float(output.split()[2][:-1]), 1))) value = "%5.1f" % (round(float(output.split()[2]), 1))
except: except:
value = " N\A" value = " N\A"
elif (gpudev == 'ati'): elif (gpudev == 'ati'):
output = commands.getoutput("aticonfig --od-getclocks | grep load | tail -n1") output = commands.getoutput("aticonfig --od-getclocks | grep load | tail -n1")
try: try:
value = "%5s" % (str(round(float(output.split()[3][:-1]), 1))) value = "%5.1f" % (round(float(output.split()[3]), 1))
except: except:
value = " N\A" value = " N\A"
else: else:
value = " N\A" value = " N\A"
text = text + "Load: %s%%\n" %(value) text = text + "Load: %s%%\n" % (value)
if (gpudev == 'nvidia'): if (gpudev == 'nvidia'):
output = commands.getoutput("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1") output = commands.getoutput("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1")
try: try:
value = "%5s" % (str(round(float(output.split()[2][:-1]), 1))) value = "%5.1f" % (round(float(output.split()[2]), 1))
except: except:
value = " N\A" value = " N\A"
elif (gpudev == 'ati'): elif (gpudev == 'ati'):
output = commands.getoutput("aticonfig --od-gettemperature | grep Temperature | tail -n1") output = commands.getoutput("aticonfig --od-gettemperature | grep Temperature | tail -n1")
try: try:
value = "%5s" % (str(round(float(output.split()[3][:-1]), 1))) value = "%5.1f" % (round(float(output.split()[3]), 1))
except: except:
value = " N\A" value = " N\A"
else: else:
value = " N\A" value = " N\A"
text = text + "Temp: %s\xb0C\n" %(value) text = text + "Temp: %s\xb0C\n" % (value)
except: except:
text = "Something wrong" text = "Something wrong"
elif (type == "memory"): elif (type == "memory"):
try: try:
output = commands.getoutput("free -m -o").split("\n") output = commands.getoutput("free -m -o").split("\n")
memusage = int(output[1].split()[1]) - (int(output[1].split()[3]) + int(output[1].split()[5]) + int(output[1].split()[6])) memUsage = int(output[1].split()[1]) - (int(output[1].split()[3]) + int(output[1].split()[5]) + int(output[1].split()[6]))
text = text + "Memory: %s of %s (%s%%)\n" %(str(memusage), output[1].split()[1], str(int(100*memusage/int(output[1].split()[1])))) text = text + "Memory: %i of %s (%i%%)\n" % (memUsage, output[1].split()[1], int(100*memUsage/int(output[1].split()[1])))
text = text + "Swap: %s of %s (%s%%)\n" %(output[2].split()[2], output[2].split()[1], str(int(100*int(output[2].split()[2])/int(output[2].split()[1])))) text = text + "Swap: %s of %s (%i%%)\n" % (output[2].split()[2], output[2].split()[1], int(100*int(output[2].split()[2])/int(output[2].split()[1])))
output = commands.getoutput("swapon --show").split("\n") output = commands.getoutput("swapon --show").split("\n")
text = text + "Swap Device: %s (%s)" %(output[1].split()[0], output[1].split()[1]) text = text + "Swap Device: %s (%s)" % (output[1].split()[0], output[1].split()[1])
except:
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: except:
text = "Something wrong" text = "Something wrong"
elif (type == "network"): elif (type == "network"):
try: try:
output = commands.getoutput("ifconfig -a -s").split("\n")[1:] output = commands.getoutput("ifconfig -a -s").split("\n")[1:]
text = text + "Devices:" devices = [line.split()[0] for line in output]
for line in output: text = text + "Devices: %s\n" % (' '.join(devices))
text = text + " %s" %(line.split()[0]) for dev in devices:
output = commands.getoutput("ifconfig -a -s " + self.parent.parent.netdev + " && sleep 0.2 && ifconfig -a -s " + self.parent.parent.netdev).split("\n") output = commands.getoutput("ifconfig -a -s " + dev + " && sleep 0.2 && ifconfig -a -s " + dev).split("\n")
download = int((int(output[3].split()[2]) - int(output[1].split()[2])) / (0.2 * 1024)) download = int((int(output[3].split()[2]) - int(output[1].split()[2])) / (0.2 * 1024))
upload = int((int(output[3].split()[6]) - int(output[1].split()[6])) / (0.2 * 1024)) upload = int((int(output[3].split()[6]) - int(output[1].split()[6])) / (0.2 * 1024))
text = text + "\n%s: %s/%s KB/s\n" %(self.parent.parent.netdev, download, upload) text = text + "%s: %i/%i KB/s" % (dev, download, upload)
output = commands.getoutput("ifconfig " + self.parent.parent.netdev + " | grep 'inet '").split()[1] output = commands.getoutput("ifconfig " + dev + " | grep 'inet ' || echo ' inet Null'").split()[1]
text = text + "IP: %s\n" %(output[:-1]) text = text + " (IP: %s)\n" % (output)
output = commands.getoutput("wget http://checkip.dyndns.org/ -q -O - | awk '{print $6}' | sed 's/<.*>//g'") output = commands.getoutput("wget -qO- http://ifconfig.me/ip")
text = text + "External IP: %s" %(output[:-1]) text = text + "External IP: %s" % (output)
except:
text = "Something wrong"
elif (type == "battery"):
try:
text = text + "%s" %(commands.getoutput("acpi -abi"))
except: except:
text = "Something wrong" text = "Something wrong"
elif (type == "player"): elif (type == "player"):
@ -154,11 +129,19 @@ class PTMNotify:
artist = "N\\A" artist = "N\\A"
album = "N\\A" album = "N\\A"
title = "N\\A" title = "N\\A"
if (self.parent.parent.player_name == "amarok"): if (len(commands.getoutput("pgrep amarok")) > 0):
player = "amarok"
elif (len(commands.getoutput("pgrep mpd")) > 0):
player = "mpd"
elif (len(commands.getoutput("pgrep qmmp")) > 0):
player = "qmmp"
else:
player = ""
if (player == "amarok"):
artist = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-") artist = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-")
album = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep album: | cut -c8-") album = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep album: | cut -c8-")
title = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep title: | cut -c8-") title = commands.getoutput("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep title: | cut -c8-")
elif (self.parent.parent.player_name == "mpd"): elif (player == "mpd"):
output = commands.getoutput("echo 'currentsong\nclose' | curl --connect-timeout 1 -fsm 3 telnet://localhost:6600 2> /dev/null") output = commands.getoutput("echo 'currentsong\nclose' | curl --connect-timeout 1 -fsm 3 telnet://localhost:6600 2> /dev/null")
for line in output.split("\n"): for line in output.split("\n"):
if (line.split(": ")[0] == "Artist"): if (line.split(": ")[0] == "Artist"):
@ -167,107 +150,71 @@ class PTMNotify:
album = line.split(": ")[1] album = line.split(": ")[1]
elif (line.split(": ")[0] == "Title"): elif (line.split(": ")[0] == "Title"):
title = line.split(": ")[1] title = line.split(": ")[1]
elif (self.parent.parent.player_name == "qmmp"): elif (player == "qmmp"):
artist = commands.getoutput("qmmp --nowplaying '%if(%p,%p,Unknown)' 2> /dev/null") artist = commands.getoutput("qmmp --nowplaying '%if(%p,%p,Unknown)' 2> /dev/null")
album = commands.getoutput("qmmp --nowplaying '%if(%a,%a,Unknown)' 2> /dev/null") album = commands.getoutput("qmmp --nowplaying '%if(%a,%a,Unknown)' 2> /dev/null")
title = commands.getoutput("qmmp --nowplaying '%if(%t,%t,Unknown)' 2> /dev/null") title = commands.getoutput("qmmp --nowplaying '%if(%t,%t,Unknown)' 2> /dev/null")
text = text + "Artist: %s\nAlbum: %s\nTitle: %s" %(artist, album, title) text = text + "Artist: %s\nAlbum: %s\nTitle: %s" % (artist, album, title)
except:
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")
text = text + "CPU Usage: %5.1f%%\n" % (100-float(output.split()[-1]))
output = commands.getoutput("grep MHz /proc/cpuinfo | head -1")
text = text + "CPU Freq: %i MHz\n" % (int(float(output.split()[-1])))
output = commands.getoutput("sensors -u")
text = text + "Temps:"
for line in output.split("\n"):
if (line.find("_input") > -1):
text = text + " %3.0f\xb0C" % (round(float(line.split()[-1]), 0))
except:
text = "Something wrong"
elif (type == "system"):
try:
text = text + "Kernel: %s\n" % (commands.getoutput("uname -rsm"))
text = text + "Hostname: %s\n" % (commands.getoutput("uname -n"))
text = text + "Whoami: %s\n" % (commands.getoutput("whoami"))
text = text + "Uptime: %s\n" % (commands.getoutput("uptime"))
except: except:
text = "Something wrong" text = "Something wrong"
content = [type, text] content = [type, text]
return content return content
def initText(self, sender): def initText(self, name):
"""function to send text""" """function to send text"""
try: if (name == "bat"):
if (sender == self.parent.parent.label_time): return self.createText("battery")
content = self.createText("system") elif (name == "cpu"):
return content return self.createText("processor")
except: elif (name == "cpuclock"):
pass return self.createText("processor")
try: elif (name == "custom"):
if (sender == self.parent.parent.label_uptime): return self.createText("system")
content = self.createText("system") elif (name == "gpu"):
return content return self.createText("graphical")
except: elif (name == "gputemp"):
pass return self.createText("graphical")
try: elif (name == "hdd"):
if (sender == self.parent.parent.label_cpu): return self.createText("disk")
content = self.createText("processor") elif (name == "hddtemp"):
return content return self.createText("disk")
except: elif (name == "mem"):
pass return self.createText("memory")
try: elif (name == "net"):
if (sender == self.parent.parent.label_cpuclock): return self.createText("network")
content = self.createText("processor") elif (name == "player"):
return content return self.createText("player")
except: elif (name == "swap"):
pass return self.createText("memory")
try: elif (name == "temp"):
if (sender == self.parent.parent.label_temp): return self.createText("processor")
content = self.createText("processor") elif (name == "time"):
return content return self.createText("system")
except: elif (name == "uptime"):
pass return self.createText("system")
try: else:
if (sender == self.parent.parent.label_gpu): return None
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_hdd):
content = self.createText("disk")
return content
except:
pass
try:
if (sender == self.parent.parent.label_hddtemp):
content = self.createText("disk")
return content
except:
pass
try:
if (sender == self.parent.parent.label_net):
content = self.createText("network")
return content
except:
pass
try:
if (sender == self.parent.parent.label_bat):
content = self.createText("battery")
return content
except:
pass
try:
if (sender == self.parent.parent.label_player):
content = self.createText("player")
return content
except:
pass
try:
if (sender == self.parent.parent.label_custom):
content = self.createText("system")
return content
except:
pass

View File

@ -3,14 +3,14 @@ IconName=system
Name=PyTextMonitor Name=PyTextMonitor
Comment=PyTextMonitor information Comment=PyTextMonitor information
[Event/system] [Event/battery]
Name=System information Name=Battery information
Comment=System information Comment=Battery information
Action=Popup Action=Popup
[Event/processor] [Event/disk]
Name=Processor information Name=Disk information
Comment=Processor information Comment=Disk information
Action=Popup Action=Popup
[Event/graphical] [Event/graphical]
@ -23,27 +23,22 @@ Name=Memory information
Comment=Memory information Comment=Memory information
Action=Popup Action=Popup
[Event/disk]
Name=Disk information
Comment=Disk information
Action=Popup
[Event/network] [Event/network]
Name=Network information Name=Network information
Comment=Network information Comment=Network information
Action=Popup Action=Popup
[Event/battery] [Event/player]
Name=Battery information
Comment=Battery information
Action=Popup
[Event/graphinfo]
Name=Graphical Information
Comment=Graphical Information
Action=Popup
[Event/musicplayer]
Name=Now playing Name=Now playing
Comment=Now playing Comment=Now playing
Action=Popup Action=Popup
[Event/processor]
Name=Processor information
Comment=Processor information
Action=Popup
[Event/system]
Name=System information
Comment=System information
Action=Popup