Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from PyKDE4.plasma import Plasma
- from PyKDE4 import plasmascript
- from PyQt4 import QtCore
- import commands
- class NVidiaInfo(plasmascript.Applet):
- def __init__(self,parent,args=None):
- plasmascript.Applet.__init__(self,parent)
- cudaCores=commands.getoutput("nvidia-settings -q CUDACores | grep -m 1 -i cudacores");
- self.cudaCores=cudaCores[cudaCores.find("):")+2:cudaCores.rfind(".")];
- videoRAM=commands.getoutput("nvidia-settings -q VideoRam | grep -m 1 -i videoram");
- videoRAM=videoRAM[videoRAM.find("):")+2:videoRAM.rfind(".")];
- videoRAM=str(int(videoRAM)/1024);
- self.videoRAM=videoRAM;
- self.cardModel=commands.getoutput("nvidia-settings -g | grep -i 'renderer string' | sed -e 's/^.*: //'");
- openglVersion=commands.getoutput("nvidia-settings -g | grep -i 'opengl version string' | sed -e 's/^.*: //'");
- self.openglVersion=openglVersion.replace("NVIDIA","/");
- def _updatelabel(self):
- sensor=commands.getoutput("nvidia-settings -q [gpu:0]/GPUCoreTemp | grep gpu:0");
- if sensor.find(".") == -1:
- #Fallback to thermalsensor if GPUCoreTemp is nat available
- sensor=commands.getoutput("nvidia-settings -q [thermalsensor:0]/ThermalSensorReading | grep thermalsensor");
- if sensor.find(".") == -1:
- #If nothing works, set a nice message for sensors string to avoid errors
- sensor="): N/A .";
- sensor=sensor[sensor.find("):")+2:sensor.rfind(".")+1];
- sensor=sensor.replace(".",unichr(176).encode("latin-1"));
- sensor+="C";
- temp = "<div style='align:center;background:transparent;text-size:12px'>\
- Card Model: " + self.cardModel + "<br />\
- OpenGL / Driver: " + self.openglVersion + "<br />\
- VideoRAM: " + self.videoRAM + "MB, CUDA Cores: " + self.cudaCores + "<br />\
- <b>\
- Temperature: " + sensor + "\
- </b>\
- </div>";
- self.label.setText(temp)
- def init(self):
- self.setHasConfigurationInterface(False)
- self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
- #self.theme = Plasma.Svg(self)
- #self.theme.setImagePath("widgets/background")
- #self.setBackgroundHints(Plasma.Applet.DefaultBackground)
- self.setBackgroundHints(Plasma.Applet.NoBackground)
- self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
- self.label = Plasma.Label(self.applet)
- self._updatelabel();
- self.timer = QtCore.QTimer();
- self.timer.setInterval(10000);
- self.timer.start(10000);
- QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self._updatelabel)
- self.layout.addItem(self.label)
- self.applet.setLayout(self.layout)
- self.resize(300,100)
- def CreateApplet(parent):
- return NVidiaInfo(parent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement