New release 1.3.2:

* optimization and refactoring
  * gpu* and hddtemp now read from ext-sysmon DataEngine
Extended SystemMonitor DataEngine:
  initial release 1.0:
    + add gpu source
    + add gputemp source
    + add hddtemp source
    + add install script
This commit is contained in:
arcan1s
2013-05-24 19:48:10 +04:00
parent 9243220505
commit 4c59e7e892
18 changed files with 447 additions and 415 deletions

View File

@ -9,7 +9,7 @@ from PyKDE4 import plasmascript
from PyKDE4.plasma import Plasma
import commands, os, time
import configaccepted
import configdef
import configwindow
import dataengine
import reinit
@ -20,57 +20,42 @@ from util import *
class pyTextWidget(plasmascript.Applet):
def __init__(self, parent, args=None):
"""widget definition"""
plasmascript.Applet.__init__(self,parent)
plasmascript.Applet.__init__(self, parent)
def init(self):
"""function to initializate widget"""
self._name = str(self.package().metadata().pluginName())
self.initTooltip()
self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
self.configAccepted = configaccepted.ConfigAccepted(self)
self.dataengine = dataengine.DataEngine(self)
self.reinit = reinit.Reinit(self)
self.timer = QTimer()
QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel)
self.setupVar()
self.reinit.reinit()
self.setHasConfigurationInterface(True)
def createConfigurationInterface(self, parent):
"""function to setup configuration window"""
self.configpage = configwindow.ConfigWindow(self, self.settings)
font = QFont(str(self.settings.get('font_family', 'Terminus')), int(self.settings.get('font_size', 12)), 50)
self.configpage.ui.spinBox_interval.setValue(int(self.settings.get('interval', 2000)))
self.configpage.ui.fontComboBox.setCurrentFont(font)
self.configpage.ui.spinBox_fontSize.setValue(int(self.settings.get('font_size', 12)))
self.configpage.ui.kcolorcombo.setColor(QColor(str(self.settings.get('font_color', '#000000'))))
font = str(self.settings.get('font_style', 'normal'))
if (font == 'normal'):
self.configpage.ui.comboBox_style.setCurrentIndex(0)
else:
self.configpage.ui.comboBox_style.setCurrentIndex(1)
self.configpage.ui.spinBox_weight.setValue(int(self.settings.get('font_weight', 400)))
for label in self.dict_orders.keys():
exec ('bool = self.' + self.dict_orders[label] + 'Bool')
if (bool == 1):
self.configpage.checkboxes[self.dict_orders[label]].setCheckState(2)
self.configpage.sliders[self.dict_orders[label]].setValue(self.label_order.find(label)+1)
else:
self.configpage.checkboxes[self.dict_orders[label]].setCheckState(0)
if (self.dict_orders[label] == 'net'):
self.configpage.ui.comboBox_numNet.setCurrentIndex(int(self.settings.get('num_dev', 0)))
self.configpage.lineedits[self.dict_orders[label]].setText(str(self.settings.get(self.dict_orders[label] + 'NonFormat', self.dict_defFormat[self.dict_orders[label]])))
else:
self.configpage.lineedits[self.dict_orders[label]].setText(str(self.settings.get(self.dict_orders[label] + 'Format', self.dict_defFormat[self.dict_orders[label]])))
if (self.dict_orders[label] == 'bat'):
self.configpage.ui.lineEdit_batdev.setText(str(self.settings.get('battery_device', '/sys/class/power_supply/BAT0/capacity')))
self.configpage.ui.lineEdit_acdev.setText(str(self.settings.get('ac_device', '/sys/class/power_supply/AC/online')))
# add config page
page = parent.addPage(self.configpage, i18n(self.name()))
page.setIcon(KIcon(self.icon()))
parent.okClicked.connect(self.configAccepted.configAccepted)
self.configpage = configwindow.ConfigWindow(self)
self.configdef = configdef.ConfigDefinition(self, self.configpage)
self.configdef.createConfigurationInterface(parent)
def initTooltip(self):
"""function to create tooltip"""
self.tooltip = Plasma.ToolTipContent()
self.tooltip.setMainText("PyTetMonitor")
self.tooltip.setSubText('')
Plasma.ToolTipManager.self().registerWidget(self.applet)
# show tooltip
#Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
def setupNetdev(self):
@ -102,12 +87,6 @@ class pyTextWidget(plasmascript.Applet):
# setup temperature device
commandOut = commands.getoutput("sensors | grep Physical -B2")
self.tempdev = "lmsensors/"+commandOut.split("\n")[0]+"/"+'_'.join(commandOut.split("\n")[2].split(":")[0].split())
# setup gpu device
commandOut = commands.getoutput("lspci")
if (commandOut.lower().find('nvidia') > -1):
self.gpudev = 'nvidia'
elif (commandOut.lower().find('radeon') > -1):
self.gpudev = 'ati'
# create dictionaries
self.dict_orders = {'6':'bat', '1':'cpu', '7':'cpuclock', '9':'gpu', 'a':'gputemp',
@ -124,24 +103,13 @@ class pyTextWidget(plasmascript.Applet):
plasmascript.Applet.showConfigurationInterface(self)
def showTooltip(self, text):
"""function to create and set tooltip"""
tooltip = Plasma.ToolTipContent()
tooltip.setImage(KIcon(self.icon()))
tooltip.setSubText(text)
tooltip.setAutohide(False)
Plasma.ToolTipManager.self().setContent(self.applet, tooltip)
Plasma.ToolTipManager.self().registerWidget(self.applet)
def startPolling(self):
try:
self.timer.start()
QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel)
self.updateLabel()
self.showTooltip('')
self.tooltip.setSubText('')
except Exception as (strerror):
self.showTooltip(str(strerror))
self.tooltip.setSubText(str(strerror))
self.label_error = Plasma.Label(self.applet)
self.label_error.setText('<font color="red">ERROR</font>')
self.layout.addItem(self.label_error)
@ -149,19 +117,10 @@ class pyTextWidget(plasmascript.Applet):
def updateLabel(self):
"""function to update label"""
if (self.gpuBool == 1):
self.gpuText()
self.gpuChecker.label_exit = 2
if (self.gputempBool == 1):
self.gputempText()
self.gpuTempChecker.label_exit = 2
if ((self.memBool == 1) and (self.memInMb == False)):
self.memText()
if ((self.swapBool == 1) and (self.swapInMb == False)):
self.swapText()
if (self.hddtempBool == 1):
self.hddtempText()
self.hddTempChecker.label_exit = 2
if (self.batBool == 1):
self.batText()
@ -193,36 +152,6 @@ class pyTextWidget(plasmascript.Applet):
self.label_bat.setText(text)
def gpuText(self):
"""function to set gpu text"""
if (self.gpuFormat.split('$gpu')[0] != self.gpuFormat):
line = self.gpuFormat.split('$gpu')[0] + self.gpuChecker.gpu + self.gpuFormat.split('$gpu')[1]
else:
line = self.gpuFormat
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
self.label_gpu.setText(text)
def gputempText(self):
"""function to set gpu temperature text"""
if (self.gputempFormat.split('$gputemp')[0] != self.gputempFormat):
line = self.gputempFormat.split('$gputemp')[0] + self.gpuTempChecker.gputemp + self.gputempFormat.split('$gputemp')[1]
else:
line = self.gputempFormat
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
self.label_gputemp.setText(text)
def hddtempText(self):
"""function to set hdd temperature text"""
if (self.hddtempFormat.split('@@')[0] != self.hddtempFormat):
line = self.hddtempFormat.split('@@')[0] + self.hddTempChecker.hddtemp + self.hddtempFormat.split('@@')[2]
else:
line = self.hddtempFormat
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
self.label_hddtemp.setText(text)
def memText(self):
"""function to set mem text"""
full = self.mem_uf + self.mem_free