Advertisement
Guest User

Untitled

a guest
Jan 14th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from PyQt4.QtCore import *
  3. from PyQt4.QtGui import *
  4. from PyKDE4.plasma import Plasma
  5. from PyKDE4 import plasmascript
  6. from PyQt4 import QtCore
  7. import commands
  8.  
  9. class NVidiaInfo(plasmascript.Applet):
  10.  
  11. def __init__(self,parent,args=None):
  12. plasmascript.Applet.__init__(self,parent)
  13.  
  14. cudaCores=commands.getoutput("nvidia-settings -q CUDACores | grep -m 1 -i cudacores");
  15. self.cudaCores=cudaCores[cudaCores.find("):")+2:cudaCores.rfind(".")];
  16.  
  17. videoRAM=commands.getoutput("nvidia-settings -q VideoRam | grep -m 1 -i videoram");
  18. videoRAM=videoRAM[videoRAM.find("):")+2:videoRAM.rfind(".")];
  19. videoRAM=str(int(videoRAM)/1024);
  20. self.videoRAM=videoRAM;
  21.  
  22. self.cardModel=commands.getoutput("nvidia-settings -g | grep -i 'renderer string' | sed -e 's/^.*: //'");
  23.  
  24. openglVersion=commands.getoutput("nvidia-settings -g | grep -i 'opengl version string' | sed -e 's/^.*: //'");
  25. self.openglVersion=openglVersion.replace("NVIDIA","/");
  26.  
  27.  
  28. def _updatelabel(self):
  29. sensor=commands.getoutput("nvidia-settings -q [gpu:0]/GPUCoreTemp | grep gpu:0");
  30. if sensor.find(".") == -1:
  31. #Fallback to thermalsensor if GPUCoreTemp is nat available
  32. sensor=commands.getoutput("nvidia-settings -q [thermalsensor:0]/ThermalSensorReading | grep thermalsensor");
  33.  
  34. if sensor.find(".") == -1:
  35. #If nothing works, set a nice message for sensors string to avoid errors
  36. sensor="): N/A .";
  37.  
  38. sensor=sensor[sensor.find("):")+2:sensor.rfind(".")+1];
  39. sensor=sensor.replace(".",unichr(176).encode("latin-1"));
  40. sensor+="C";
  41.  
  42. temp = "<div style='align:center;background:transparent;text-size:12px'>\
  43. Card Model: " + self.cardModel + "<br />\
  44. OpenGL / Driver: " + self.openglVersion + "<br />\
  45. VideoRAM: " + self.videoRAM + "MB, CUDA Cores: " + self.cudaCores + "<br />\
  46. <b>\
  47. Temperature: " + sensor + "\
  48. </b>\
  49. </div>";
  50.  
  51. self.label.setText(temp)
  52.  
  53. def init(self):
  54. self.setHasConfigurationInterface(False)
  55. self.setAspectRatioMode(Plasma.IgnoreAspectRatio)
  56.  
  57. #self.theme = Plasma.Svg(self)
  58. #self.theme.setImagePath("widgets/background")
  59. #self.setBackgroundHints(Plasma.Applet.DefaultBackground)
  60. self.setBackgroundHints(Plasma.Applet.NoBackground)
  61.  
  62. self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
  63.  
  64. self.label = Plasma.Label(self.applet)
  65.  
  66. self._updatelabel();
  67.  
  68. self.timer = QtCore.QTimer();
  69. self.timer.setInterval(10000);
  70. self.timer.start(10000);
  71. QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self._updatelabel)
  72.  
  73. self.layout.addItem(self.label)
  74. self.applet.setLayout(self.layout)
  75. self.resize(300,100)
  76.  
  77.  
  78. def CreateApplet(parent):
  79. return NVidiaInfo(parent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement