mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-06-28 14:51:39 +00:00
Small fixes in dataengine
This commit is contained in:
16
sources/contents/code/config.py
Normal file
16
sources/contents/code/config.py
Normal file
@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from util import *
|
||||
|
||||
|
||||
|
||||
class Config():
|
||||
def __init__(self, applet):
|
||||
self.applet = applet
|
||||
self.config = self.applet.config()
|
||||
|
||||
def get(self, key, default = ''):
|
||||
return self.config.readEntry(key, default).toString()
|
||||
|
||||
def set(self, key, value):
|
||||
self.config.writeEntry(key, value)
|
198
sources/contents/code/configdef.py
Normal file
198
sources/contents/code/configdef.py
Normal file
@ -0,0 +1,198 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtGui import *
|
||||
from PyKDE4.kdecore import *
|
||||
from PyKDE4.kdeui import *
|
||||
import commands
|
||||
import config
|
||||
|
||||
|
||||
|
||||
class ConfigDefinition:
|
||||
def __init__(self, parent, configpage):
|
||||
"""class definition"""
|
||||
self.parent = parent
|
||||
self.configpage = configpage
|
||||
|
||||
|
||||
def configAccepted(self):
|
||||
"""function to accept settings"""
|
||||
settings = config.Config(self.parent)
|
||||
|
||||
# update local variables
|
||||
self.parent.interval = self.configpage.ui.spinBox_interval.value()
|
||||
settings.set('interval', self.parent.interval)
|
||||
self.parent.font_family = str(self.configpage.ui.fontComboBox.currentFont().family())
|
||||
settings.set('font_family', self.parent.font_family)
|
||||
self.parent.font_size = self.configpage.ui.spinBox_fontSize.value()
|
||||
settings.set('font_size', self.parent.font_size)
|
||||
self.parent.font_color = str(self.configpage.ui.kcolorcombo.color().name())
|
||||
settings.set('font_color', self.parent.font_color)
|
||||
if (self.configpage.ui.comboBox_style.currentIndex() == 0):
|
||||
self.parent.font_style = 'normal'
|
||||
else:
|
||||
self.parent.font_style = 'italic'
|
||||
settings.set('font_style', self.parent.font_style)
|
||||
self.parent.font_weight = self.configpage.ui.spinBox_weight.value()
|
||||
settings.set('font_weight', self.parent.font_weight)
|
||||
|
||||
# disconnecting from source and clear layout
|
||||
if (self.parent.uptimeBool == 1):
|
||||
self.parent.systemmonitor.disconnectSource("system/uptime", self.parent)
|
||||
self.parent.label_uptime.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_uptime)
|
||||
if (self.parent.cpuBool == 1):
|
||||
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_cpu1.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_cpu1)
|
||||
for core in range(self.parent.numCores):
|
||||
self.parent.systemmonitor.disconnectSource("cpu/cpu"+str(core)+"/TotalLoad", self.parent)
|
||||
exec ("self.parent.label_coreCpu" + str(core) + ".setText('')")
|
||||
exec ("self.parent.layout.removeItem(self.parent.label_coreCpu" + str(core) + ")")
|
||||
else:
|
||||
self.parent.label_cpu.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_cpu)
|
||||
if (self.parent.cpuclockBool == 1):
|
||||
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_cpuclock1.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_cpuclock1)
|
||||
for core in range(self.parent.numCores):
|
||||
self.parent.systemmonitor.disconnectSource("cpu/cpu"+str(core)+"/clock", self.parent)
|
||||
exec ("self.parent.label_coreCpuclock" + str(core) + ".setText('')")
|
||||
exec ("self.parent.layout.removeItem(self.parent.label_coreCpuclock" + str(core) + ")")
|
||||
else:
|
||||
self.parent.label_cpuclock.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_cpuclock)
|
||||
if (self.parent.tempBool == 1):
|
||||
self.parent.systemmonitor.disconnectSource(self.parent.tempdev, self.parent)
|
||||
self.parent.label_temp.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_temp)
|
||||
if (self.parent.gpuBool == 1):
|
||||
self.parent.extsysmon.disconnectSource("gpu", self.parent)
|
||||
self.parent.label_gpu.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_gpu)
|
||||
if (self.parent.gputempBool == 1):
|
||||
self.parent.extsysmon.disconnectSource("gputemp", self.parent)
|
||||
self.parent.label_gputemp.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_gputemp)
|
||||
if (self.parent.memBool == 1):
|
||||
self.parent.systemmonitor.disconnectSource("mem/physical/application", self.parent)
|
||||
if (self.parent.memInMb == False):
|
||||
self.parent.systemmonitor.disconnectSource("mem/physical/free", self.parent)
|
||||
self.parent.systemmonitor.disconnectSource("mem/physical/used", self.parent)
|
||||
self.parent.label_mem.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_mem)
|
||||
if (self.parent.swapBool == 1):
|
||||
self.parent.systemmonitor.disconnectSource("mem/swap/used", self.parent)
|
||||
if (self.parent.swapInMb == False):
|
||||
self.parent.systemmonitor.disconnectSource("mem/swap/free", self.parent)
|
||||
self.parent.label_swap.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_swap)
|
||||
if (self.parent.hddBool == 1):
|
||||
for mount in self.parent.mountPoints:
|
||||
self.parent.systemmonitor.disconnectSource("partitions" + mount + "/filllevel", self.parent)
|
||||
exec ('self.parent.label_hdd_' + ''.join(mount.split('/')) + '.setText("")')
|
||||
exec ("self.parent.layout.removeItem(self.parent.label_hdd_" + ''.join(mount.split('/')) + ")")
|
||||
self.parent.label_hdd0.setText('')
|
||||
self.parent.label_hdd1.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_hdd0)
|
||||
self.parent.layout.removeItem(self.parent.label_hdd1)
|
||||
if (self.parent.hddtempBool == 1):
|
||||
self.parent.extsysmon.disconnectSource("hddtemp", self.parent)
|
||||
self.parent.label_hddtemp.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_hddtemp)
|
||||
if (self.parent.netBool == 1):
|
||||
self.parent.systemmonitor.disconnectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent)
|
||||
self.parent.systemmonitor.disconnectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent)
|
||||
self.parent.label_netDown.setText('')
|
||||
self.parent.label_netUp.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_netUp)
|
||||
self.parent.layout.removeItem(self.parent.label_netDown)
|
||||
if (self.parent.batBool == 1):
|
||||
self.parent.label_bat.setText('')
|
||||
self.parent.layout.removeItem(self.parent.label_bat)
|
||||
|
||||
self.parent.label_order = "------------"
|
||||
|
||||
for label in self.parent.dict_orders.keys():
|
||||
if (self.configpage.checkboxes[self.parent.dict_orders[label]].checkState() == 2):
|
||||
exec ('self.parent.' + self.parent.dict_orders[label] + 'Bool = 1')
|
||||
pos = self.configpage.sliders[self.parent.dict_orders[label]].value() - 1
|
||||
self.parent.label_order = self.parent.label_order[:pos] + label + self.parent.label_order[pos+1:]
|
||||
else:
|
||||
exec ('self.parent.' + self.parent.dict_orders[label] + 'Bool = 0')
|
||||
if (self.parent.dict_orders[label] == 'net'):
|
||||
exec ('self.parent.' + self.parent.dict_orders[label] + 'NonFormat = str(self.configpage.lineedits[self.parent.dict_orders[label]].text())')
|
||||
exec ('settings.set("' + self.parent.dict_orders[label] + 'NonFormat", self.parent.' + self.parent.dict_orders[label] + 'NonFormat)')
|
||||
else:
|
||||
exec ('self.parent.' + self.parent.dict_orders[label] + 'Format = str(self.configpage.lineedits[self.parent.dict_orders[label]].text())')
|
||||
exec ('settings.set("' + self.parent.dict_orders[label] + 'Format", self.parent.' + self.parent.dict_orders[label] + 'Format)')
|
||||
exec ('settings.set("' + self.parent.dict_orders[label] + 'Bool", self.parent.' + self.parent.dict_orders[label] + 'Bool)')
|
||||
if (self.parent.dict_orders[label] == 'bat'):
|
||||
self.parent.battery_device = str(self.configpage.ui.lineEdit_batdev.text())
|
||||
self.parent.ac_device = str(self.configpage.ui.lineEdit_acdev.text())
|
||||
settings.set('battery_device', self.parent.battery_device)
|
||||
settings.set('ac_device', self.parent.ac_device)
|
||||
elif (self.parent.dict_orders[label] == 'temp'):
|
||||
self.parent.tempdev = str(self.configpage.ui.comboBox_temp.currentText())
|
||||
settings.set('temp_device', self.parent.tempdev)
|
||||
|
||||
self.parent.label_order = ''.join(self.parent.label_order.split('-'))
|
||||
settings.set('label_order', self.parent.label_order)
|
||||
|
||||
# reinitializate
|
||||
self.parent.reinit.reinit()
|
||||
|
||||
|
||||
def createConfigurationInterface(self, parent):
|
||||
"""function to setup configuration window"""
|
||||
settings = config.Config(self.parent)
|
||||
|
||||
font = QFont(str(settings.get('font_family', 'Terminus')), settings.get('font_size', 12).toInt()[0], 400, False)
|
||||
self.configpage.ui.spinBox_interval.setValue(settings.get('interval', 2000).toInt()[0])
|
||||
self.configpage.ui.fontComboBox.setCurrentFont(font)
|
||||
self.configpage.ui.spinBox_fontSize.setValue(settings.get('font_size', 12).toInt()[0])
|
||||
self.configpage.ui.kcolorcombo.setColor(QColor(str(settings.get('font_color', '#000000'))))
|
||||
font = str(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(settings.get('font_weight', 400).toInt()[0])
|
||||
for label in self.parent.dict_orders.keys():
|
||||
exec ('bool = self.parent.' + self.parent.dict_orders[label] + 'Bool')
|
||||
if (bool == 1):
|
||||
self.configpage.checkboxes[self.parent.dict_orders[label]].setCheckState(2)
|
||||
self.configpage.sliders[self.parent.dict_orders[label]].setValue(self.parent.label_order.find(label)+1)
|
||||
else:
|
||||
self.configpage.checkboxes[self.parent.dict_orders[label]].setCheckState(0)
|
||||
if (self.parent.dict_orders[label] == 'net'):
|
||||
self.configpage.lineedits[self.parent.dict_orders[label]].setText(str(settings.get(self.parent.dict_orders[label] + 'NonFormat', self.parent.dict_defFormat[self.parent.dict_orders[label]])))
|
||||
else:
|
||||
self.configpage.lineedits[self.parent.dict_orders[label]].setText(str(settings.get(self.parent.dict_orders[label] + 'Format', self.parent.dict_defFormat[self.parent.dict_orders[label]])))
|
||||
if (self.parent.dict_orders[label] == 'bat'):
|
||||
self.configpage.ui.lineEdit_batdev.setText(str(settings.get('battery_device', '/sys/class/power_supply/BAT0/capacity')))
|
||||
self.configpage.ui.lineEdit_acdev.setText(str(settings.get('ac_device', '/sys/class/power_supply/AC/online')))
|
||||
elif (self.parent.dict_orders[label] == 'temp'):
|
||||
self.configpage.ui.comboBox_temp.addItem(str(settings.get('temp_device', '<select device>')))
|
||||
commandOut = commands.getoutput("sensors")
|
||||
for adapter in commandOut.split("\n\n"):
|
||||
for device in adapter.split("\n"):
|
||||
if (device.find('\xc2\xb0C') > -1):
|
||||
try:
|
||||
tempdev = 'lmsensors/' + adapter.split('\n')[0] + '/' + '_'.join(device.split(":")[0].split())
|
||||
self.configpage.ui.comboBox_temp.addItem(tempdev)
|
||||
except:
|
||||
pass
|
||||
|
||||
# add config page
|
||||
page = parent.addPage(self.configpage, i18n(self.parent.name()))
|
||||
page.setIcon(KIcon(self.parent.icon()))
|
||||
|
||||
parent.okClicked.connect(self.configAccepted)
|
104
sources/contents/code/configwindow.py
Normal file
104
sources/contents/code/configwindow.py
Normal file
@ -0,0 +1,104 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyKDE4.plasma import *
|
||||
from PyQt4 import uic
|
||||
from PyKDE4 import plasmascript
|
||||
|
||||
|
||||
|
||||
class ConfigWindow(QWidget):
|
||||
def __init__(self, parent):
|
||||
"""settings window definition"""
|
||||
QWidget.__init__(self)
|
||||
self.ui = uic.loadUi(parent.package().filePath('ui', 'configwindow.ui'), self)
|
||||
self.parent = parent
|
||||
self.checkboxes = {'bat':self.ui.checkBox_bat, 'cpu':self.ui.checkBox_cpu,
|
||||
'cpuclock':self.ui.checkBox_cpuclock, 'gpu':self.ui.checkBox_gpu,
|
||||
'gputemp':self.ui.checkBox_gpuTemp, 'hdd':self.ui.checkBox_hdd,
|
||||
'hddtemp':self.ui.checkBox_hddTemp, 'mem':self.ui.checkBox_mem,
|
||||
'net':self.ui.checkBox_net, 'swap':self.ui.checkBox_swap,
|
||||
'temp':self.ui.checkBox_temp, 'uptime':self.ui.checkBox_uptime}
|
||||
self.sliders = {'bat':self.ui.slider_bat, 'cpu':self.ui.slider_cpu,
|
||||
'cpuclock':self.ui.slider_cpuclock, 'gpu':self.ui.slider_gpu,
|
||||
'gputemp':self.ui.slider_gpuTemp, 'hdd':self.ui.slider_hdd,
|
||||
'hddtemp':self.ui.slider_hddTemp, 'mem':self.ui.slider_mem,
|
||||
'net':self.ui.slider_net, 'swap':self.ui.slider_swap,
|
||||
'temp':self.ui.slider_temp, 'uptime':self.ui.slider_uptime}
|
||||
self.lineedits = {'bat':self.ui.lineEdit_bat, 'cpu':self.ui.lineEdit_cpu,
|
||||
'cpuclock':self.ui.lineEdit_cpuclock, 'gpu':self.ui.lineEdit_gpu,
|
||||
'gputemp':self.ui.lineEdit_gpuTemp, 'hdd':self.ui.lineEdit_hdd,
|
||||
'hddtemp':self.ui.lineEdit_hddTemp, 'mem':self.ui.lineEdit_mem,
|
||||
'net':self.ui.lineEdit_net, 'swap':self.ui.lineEdit_swap,
|
||||
'temp':self.ui.lineEdit_temp, 'uptime':self.ui.lineEdit_uptime}
|
||||
|
||||
for item in self.checkboxes.values():
|
||||
QObject.connect(item, SIGNAL("stateChanged(int)"), self.setStatus)
|
||||
for item in self.sliders.values():
|
||||
QObject.connect(item, SIGNAL("valueChanged(int)"), self.setSlider)
|
||||
|
||||
|
||||
def setStatus(self):
|
||||
"""function to enable label"""
|
||||
count = self.sliders['bat'].maximum()
|
||||
for label in self.checkboxes.keys():
|
||||
if ((self.checkboxes[label].checkState() == 2) and (self.sliders[label].isEnabled() == False)):
|
||||
self.lineedits[label].setEnabled(True)
|
||||
self.sliders[label].setEnabled(True)
|
||||
if (label == 'bat'):
|
||||
self.ui.lineEdit_acdev.setEnabled(True)
|
||||
self.ui.lineEdit_batdev.setEnabled(True)
|
||||
elif (label == 'temp'):
|
||||
self.ui.comboBox_temp.setEnabled(True)
|
||||
slider_label = 0
|
||||
for slider in self.sliders.values():
|
||||
if (slider.isEnabled() == True):
|
||||
slider_label += 1
|
||||
for slider in self.sliders.values():
|
||||
if (slider_label > 1):
|
||||
slider.setMaximum(slider.maximum()+1)
|
||||
elif (slider_label == 1):
|
||||
slider.setMaximum(1)
|
||||
self.sliders[label].setValue(self.sliders[label].maximum())
|
||||
elif ((self.checkboxes[label].checkState() == 0) and (self.sliders[label].isEnabled() == True)):
|
||||
self.lineedits[label].setDisabled(True)
|
||||
self.sliders[label].setDisabled(True)
|
||||
if (label == 'bat'):
|
||||
self.ui.lineEdit_acdev.setDisabled(True)
|
||||
self.ui.lineEdit_batdev.setDisabled(True)
|
||||
elif (label == 'temp'):
|
||||
self.ui.comboBox_temp.setDisabled(True)
|
||||
for slider in self.sliders.values():
|
||||
if ((slider.value() == slider.maximum()) and (slider != self.sliders[label])):
|
||||
slider.setValue(self.sliders[label].value())
|
||||
slider_label = 0
|
||||
for slider in self.sliders.values():
|
||||
if (slider.isEnabled() == True):
|
||||
slider_label += 1
|
||||
for slider in self.sliders.values():
|
||||
if (slider_label > 0):
|
||||
slider.setMaximum(slider.maximum()-1)
|
||||
else:
|
||||
slider.setMaximum(1)
|
||||
self.sliders[label].setValue(1)
|
||||
|
||||
def setSlider(self):
|
||||
"""function to set sliders"""
|
||||
if (self.sender().isEnabled() == True):
|
||||
second_slider = self.sender()
|
||||
order = []
|
||||
for slider in self.sliders.values():
|
||||
if (slider.isEnabled() == True):
|
||||
order.append(slider.value())
|
||||
if ((slider.value() == self.sender().value()) and (slider != self.sender())):
|
||||
second_slider = slider
|
||||
|
||||
if (second_slider == self.sender()):
|
||||
return
|
||||
|
||||
for value in range(len(order)):
|
||||
if (order.count(value+1) == 0):
|
||||
new_value = value + 1
|
||||
|
||||
second_slider.setValue(new_value)
|
237
sources/contents/code/dataengine.py
Normal file
237
sources/contents/code/dataengine.py
Normal file
@ -0,0 +1,237 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyKDE4.plasma import Plasma
|
||||
from PyKDE4 import plasmascript
|
||||
|
||||
|
||||
|
||||
class DataEngine:
|
||||
def __init__(self, parent):
|
||||
"""class definition"""
|
||||
self.parent = parent
|
||||
|
||||
|
||||
def connectToEngine(self):
|
||||
"""function to initializate engine"""
|
||||
self.parent.systemmonitor = self.parent.dataEngine("systemmonitor")
|
||||
if ((self.parent.gputempBool == 1) or (self.parent.gpuBool == 1) or (self.parent.hddtempBool == 1)):
|
||||
self.parent.extsysmon = self.parent.dataEngine("ext-sysmon")
|
||||
|
||||
if (self.parent.uptimeBool == 1):
|
||||
self.parent.systemmonitor.connectSource("system/uptime", self.parent, self.parent.interval)
|
||||
if (self.parent.cpuBool == 1):
|
||||
self.parent.systemmonitor.connectSource("cpu/system/TotalLoad", self.parent, self.parent.interval)
|
||||
if (self.parent.cpuFormat.split('$ccpu')[0] != self.parent.cpuFormat):
|
||||
for core in range(self.parent.numCores):
|
||||
self.parent.systemmonitor.connectSource("cpu/cpu"+str(core)+"/TotalLoad", self.parent, self.parent.interval)
|
||||
if (self.parent.cpuclockBool == 1):
|
||||
self.parent.systemmonitor.connectSource("cpu/system/AverageClock", self.parent, self.parent.interval)
|
||||
if (self.parent.cpuclockFormat.split('$ccpucl')[0] != self.parent.cpuclockFormat):
|
||||
for core in range(self.parent.numCores):
|
||||
self.parent.systemmonitor.connectSource("cpu/cpu"+str(core)+"/clock", self.parent, self.parent.interval)
|
||||
if (self.parent.tempBool == 1):
|
||||
self.parent.systemmonitor.connectSource(self.parent.tempdev, self.parent, self.parent.interval)
|
||||
if (self.parent.gpuBool == 1):
|
||||
self.parent.extsysmon.connectSource("gpu", self.parent, self.parent.interval)
|
||||
if (self.parent.gputempBool == 1):
|
||||
self.parent.extsysmon.connectSource("gputemp", self.parent, self.parent.interval)
|
||||
if (self.parent.memBool == 1):
|
||||
if (self.parent.memInMb):
|
||||
self.parent.systemmonitor.connectSource("mem/physical/application", self.parent, self.parent.interval)
|
||||
else:
|
||||
self.parent.systemmonitor.connectSource("mem/physical/free", self.parent, int(self.parent.interval*0.5))
|
||||
self.parent.systemmonitor.connectSource("mem/physical/used", self.parent, int(self.parent.interval*0.5))
|
||||
self.parent.systemmonitor.connectSource("mem/physical/application", self.parent, int(self.parent.interval*0.5))
|
||||
if (self.parent.swapBool == 1):
|
||||
if (self.parent.swapInMb):
|
||||
self.parent.systemmonitor.connectSource("mem/swap/used", self.parent, self.parent.interval)
|
||||
else:
|
||||
self.parent.systemmonitor.connectSource("mem/swap/free", self.parent, int(self.parent.interval*0.5))
|
||||
self.parent.systemmonitor.connectSource("mem/swap/used", self.parent, int(self.parent.interval*0.5))
|
||||
if (self.parent.hddBool == 1):
|
||||
for mount in self.parent.mountPoints:
|
||||
self.parent.systemmonitor.connectSource("partitions" + mount + "/filllevel", self.parent, self.parent.interval)
|
||||
if (self.parent.hddtempBool == 1):
|
||||
self.parent.extsysmon.connectSource("hddtemp", self.parent, self.parent.interval)
|
||||
if (self.parent.netBool == 1):
|
||||
self.parent.updateNetdev = 0
|
||||
self.parent.systemmonitor.connectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent, self.parent.interval)
|
||||
self.parent.systemmonitor.connectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent, self.parent.interval)
|
||||
|
||||
def dataUpdated(self, sourceName, data):
|
||||
"""function to update data"""
|
||||
try:
|
||||
if (sourceName == "system/uptime"):
|
||||
value = int(round(float(data[QString(u'value')]), 1))
|
||||
uptimeText = '%3sd%2sh%2sm' % (str(int(value/(24*60*60))), int(value/60/60)-int(value/24/60/60)*24, (value-value%60)/60%60)
|
||||
if (self.parent.uptimeFormat.split('$uptime')[0] != self.parent.uptimeFormat):
|
||||
line = self.parent.uptimeFormat.split('$uptime')[0] + uptimeText + self.parent.uptimeFormat.split('$uptime')[1]
|
||||
else:
|
||||
line = self.parent.uptimeFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_uptime.setText(text)
|
||||
elif (sourceName == "cpu/system/TotalLoad"):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
cpuText = "%5s" % (value)
|
||||
if (self.parent.cpuFormat.split('$ccpu')[0] != self.parent.cpuFormat):
|
||||
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] + cpuText + 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)
|
||||
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:
|
||||
line = self.parent.cpuFormat.split('$ccpu')[1]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpu1.setText(text)
|
||||
else:
|
||||
if (self.parent.cpuFormat.split('$cpu')[0] != self.parent.cpuFormat):
|
||||
line = self.parent.cpuFormat.split('$cpu')[0] + cpuText + self.parent.cpuFormat.split('$cpu')[1]
|
||||
else:
|
||||
line = self.parent.cpuFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpu.setText(text)
|
||||
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "TotalLoad")):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
cpuText = "%5s" % (value)
|
||||
text = self.parent.formatLine.split('$LINE')[0] + cpuText + self.parent.formatLine.split('$LINE')[1]
|
||||
exec ('self.parent.label_coreCpu' + str(sourceName)[7] + '.setText(text)')
|
||||
elif (sourceName == "cpu/system/AverageClock"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
cpuclockText = "%4s" % (value)
|
||||
if (self.parent.cpuclockFormat.split('$ccpucl')[0] != self.parent.cpuclockFormat):
|
||||
if (self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] != self.parent.cpuclockFormat.split('$ccpucl')[0]):
|
||||
line = self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] + cpuclockText + self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[1]
|
||||
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)
|
||||
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:
|
||||
line = self.parent.cpuclockFormat.split('$ccpucl')[1]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpuclock1.setText(text)
|
||||
else:
|
||||
if (self.parent.cpuclockFormat.split('$cpucl')[0] != self.parent.cpuclockFormat):
|
||||
line = self.parent.cpuclockFormat.split('$cpucl')[0] + cpuclockText + self.parent.cpuclockFormat.split('$cpucl')[1]
|
||||
else:
|
||||
line = self.parent.cpuclockFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpuclock.setText(text)
|
||||
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "clock")):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
cpuclockText = "%4s" % (value)
|
||||
text = self.parent.formatLine.split('$LINE')[0] + cpuclockText + self.parent.formatLine.split('$LINE')[1]
|
||||
exec ('self.parent.label_coreCpuclock' + str(sourceName)[7] + '.setText(text)')
|
||||
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/transmitter/data"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
up_speed = "%4s" % (value)
|
||||
if (self.parent.netFormat.split('$net')[0] != self.parent.netFormat):
|
||||
line = '/' + up_speed + self.parent.netFormat.split('$net')[1]
|
||||
else:
|
||||
line = ''
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_netUp.setText(text)
|
||||
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/receiver/data"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
down_speed = "%4s" % (value)
|
||||
if (self.parent.netFormat.split('$net')[0] != self.parent.netFormat):
|
||||
line = self.parent.netFormat.split('$net')[0] + down_speed
|
||||
else:
|
||||
line = self.parent.netFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_netDown.setText(text)
|
||||
# update network device
|
||||
self.parent.updateNetdev = self.parent.updateNetdev + 1
|
||||
if (self.parent.updateNetdev == 100):
|
||||
self.parent.updateNetdev = 0
|
||||
if (self.parent.netNonFormat.split('@@')[0] == self.parent.netNonFormat):
|
||||
self.parent.systemmonitor.disconnectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent)
|
||||
self.parent.systemmonitor.disconnectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent)
|
||||
self.parent.setupNetdev()
|
||||
self.parent.systemmonitor.connectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent, self.parent.interval)
|
||||
self.parent.systemmonitor.connectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent, self.parent.interval)
|
||||
if (self.parent.netNonFormat.split('$netdev')[0] != self.parent.netNonFormat):
|
||||
self.parent.netFormat = self.parent.netNonFormat.split('$netdev')[0] + self.parent.netdev + self.parent.netNonFormat.split('$netdev')[1]
|
||||
else:
|
||||
self.parent.netFormat = self.parent.netNonFormat
|
||||
elif (sourceName == self.parent.tempdev):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
tempText = "%4s" % (value)
|
||||
if (self.parent.tempFormat.split('$temp')[0] != self.parent.tempFormat):
|
||||
line = self.parent.tempFormat.split('$temp')[0] + tempText + self.parent.tempFormat.split('$temp')[1]
|
||||
else:
|
||||
line = self.parent.tempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_temp.setText(text)
|
||||
elif (str(sourceName).split('/')[0] == "partitions"):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
hddText = "%5s" % (value)
|
||||
text = self.parent.formatLine.split('$LINE')[0] + hddText + self.parent.formatLine.split('$LINE')[1]
|
||||
exec ('self.parent.label_hdd_' + ''.join(str(sourceName).split('/')[1:-1]) + '.setText(text)')
|
||||
elif (sourceName == "mem/physical/free"):
|
||||
self.parent.mem_free = float(data[QString(u'value')])
|
||||
elif (sourceName == "mem/physical/used"):
|
||||
self.parent.mem_uf = float(data[QString(u'value')])
|
||||
elif (sourceName == "mem/physical/application"):
|
||||
if (self.parent.memInMb):
|
||||
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0]
|
||||
mem = "%5s" % (mem)
|
||||
if (self.parent.memFormat.split('$memmb')[0] != self.parent.memFormat):
|
||||
line = self.parent.memFormat.split('$memmb')[0] + mem + self.parent.memFormat.split('$memmb')[1]
|
||||
else:
|
||||
line = self.parent.memFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_mem.setText(text)
|
||||
else:
|
||||
self.parent.mem_used = float(data[QString(u'value')])
|
||||
elif (sourceName == "mem/swap/free"):
|
||||
self.parent.swap_free = float(data[QString(u'value')])
|
||||
elif (sourceName == "mem/swap/used"):
|
||||
if (self.parent.swapInMb):
|
||||
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0]
|
||||
mem = "%5s" % (mem)
|
||||
if (self.parent.swapFormat.split('$swapmb')[0] != self.parent.swapFormat):
|
||||
line = self.parent.swapFormat.split('$swapmb')[0] + mem + self.parent.swapFormat.split('$swapmb')[1]
|
||||
else:
|
||||
line = self.parent.swapFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_swap.setText(text)
|
||||
else:
|
||||
self.parent.swap_used = float(data[QString(u'value')])
|
||||
elif (sourceName == "gpu"):
|
||||
value = str(data[QString(u'GPU')])
|
||||
gpuText = "%4s" % (value)
|
||||
if (self.parent.gpuFormat.split('$gpu')[0] != self.parent.gpuFormat):
|
||||
line = self.parent.gpuFormat.split('$gpu')[0] + gpuText + self.parent.gpuFormat.split('$gpu')[1]
|
||||
else:
|
||||
line = self.parent.gpuFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_gpu.setText(text)
|
||||
elif (sourceName == "gputemp"):
|
||||
value = str(data[QString(u'GPUTemp')])
|
||||
gputempText = "%4s" % (value)
|
||||
if (self.parent.gputempFormat.split('$gputemp')[0] != self.parent.gputempFormat):
|
||||
line = self.parent.gputempFormat.split('$gputemp')[0] + gputempText + self.parent.gputempFormat.split('$gputemp')[1]
|
||||
else:
|
||||
line = self.parent.gputempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_gputemp.setText(text)
|
||||
elif (sourceName == "hddtemp"):
|
||||
value = str(data[QString(self.parent.hddtempFormat.split('@@')[1])])
|
||||
hddtempText = "%4s" % (value)
|
||||
if (self.parent.hddtempFormat.split('@@')[0] != self.parent.hddtempFormat):
|
||||
line = self.parent.hddtempFormat.split('@@')[0] + hddtempText + self.parent.hddtempFormat.split('@@')[2]
|
||||
else:
|
||||
line = self.parent.hddtempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_hddtemp.setText(text)
|
||||
|
||||
self.parent.update()
|
||||
except:
|
||||
pass
|
188
sources/contents/code/main.py
Normal file
188
sources/contents/code/main.py
Normal file
@ -0,0 +1,188 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from PyKDE4.kdecore import *
|
||||
from PyKDE4.kdeui import *
|
||||
from PyKDE4.kio import *
|
||||
from PyKDE4 import plasmascript
|
||||
from PyKDE4.plasma import Plasma
|
||||
import commands, os, time
|
||||
|
||||
import configdef
|
||||
import configwindow
|
||||
import dataengine
|
||||
import reinit
|
||||
from util import *
|
||||
|
||||
|
||||
|
||||
class pyTextWidget(plasmascript.Applet):
|
||||
def __init__(self, parent, args=None):
|
||||
"""widget definition"""
|
||||
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.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.configdef = configdef.ConfigDefinition(self, self.configpage)
|
||||
self.configdef.createConfigurationInterface(parent)
|
||||
|
||||
|
||||
def initTooltip(self):
|
||||
"""function to create tooltip"""
|
||||
self.tooltip = Plasma.ToolTipContent()
|
||||
self.tooltip.setMainText("PyTextMonitor")
|
||||
self.tooltip.setSubText('')
|
||||
Plasma.ToolTipManager.self().registerWidget(self.applet)
|
||||
# show tooltip
|
||||
#Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
|
||||
|
||||
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
"""function to doubleclick event"""
|
||||
os.system("ksysguard")
|
||||
|
||||
|
||||
def setupNetdev(self):
|
||||
"""function to setup network device"""
|
||||
self.netdev = "lo"
|
||||
try:
|
||||
interfaces = []
|
||||
for line in commands.getoutput("ifconfig -a").split("\n"):
|
||||
if ((line != '') and (line[0] != ' ') and (line[0:3] != 'lo:')):
|
||||
interfaces.append(line.split(":")[0])
|
||||
|
||||
for device in interfaces:
|
||||
if (commands.getoutput("ifconfig " + device + " | grep 'inet '") != ''):
|
||||
self.netdev = device
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def setupVar(self):
|
||||
"""function to setup variables"""
|
||||
self.netdev = ''
|
||||
# setup number of cores
|
||||
commandOut = commands.getoutput("grep -c '^processor' /proc/cpuinfo")
|
||||
self.numCores = int(commandOut)
|
||||
|
||||
# create dictionaries
|
||||
self.dict_orders = {'6':'bat', '1':'cpu', '7':'cpuclock', '9':'gpu', 'a':'gputemp',
|
||||
'b':'hdd', 'c':'hddtemp', '3':'mem', '5':'net', '4':'swap', '2':'temp', '8':'uptime'}
|
||||
self.dict_defFormat = {'bat':'[bat: $bat%$ac]', 'cpu':'[cpu: $cpu%]',
|
||||
'cpuclock':'[mhz: $cpucl]', 'gpu':'[gpu: $gpu%]',
|
||||
'gputemp':'[gpu temp: $gputemp°C]', 'hdd':'[hdd: @@/@@%]',
|
||||
'hddtemp':'[hdd temp: @@/dev/sda@@°C]', 'mem':'[mem: $mem%]',
|
||||
'net':'[$netdev: $netKB/s]', 'swap':'[swap: $swap%]',
|
||||
'temp':'[temp: $temp°C]', 'uptime':'[uptime: $uptime]'}
|
||||
|
||||
def showConfigurationInterface(self):
|
||||
"""function to show configuration window"""
|
||||
plasmascript.Applet.showConfigurationInterface(self)
|
||||
|
||||
|
||||
def startPolling(self):
|
||||
try:
|
||||
self.timer.start()
|
||||
self.updateLabel()
|
||||
self.tooltip.setSubText('')
|
||||
except Exception as 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)
|
||||
return
|
||||
|
||||
def updateLabel(self):
|
||||
"""function to update label"""
|
||||
if ((self.memBool == 1) and (self.memInMb == False)):
|
||||
self.memText()
|
||||
if ((self.swapBool == 1) and (self.swapInMb == False)):
|
||||
self.swapText()
|
||||
if (self.batBool == 1):
|
||||
self.batText()
|
||||
|
||||
|
||||
def batText(self):
|
||||
"""function to set battery text"""
|
||||
line = self.batFormat
|
||||
if (line.split('$bat')[0] != line):
|
||||
try:
|
||||
with open (self.battery_device, 'r') as bat_file:
|
||||
bat = bat_file.readline().split('\n')[0]
|
||||
except:
|
||||
bat = 'off'
|
||||
bat = "%3s" % (bat)
|
||||
line = line.split('$bat')[0] + bat + line.split('$bat')[1]
|
||||
|
||||
if (line.split('$ac')[0] != line):
|
||||
try:
|
||||
with open (self.ac_device, 'r') as bat_file:
|
||||
bat = bat_file.readline().split('\n')[0]
|
||||
if (bat == '1'):
|
||||
bat = '(*)'
|
||||
else:
|
||||
bat = '( )'
|
||||
except:
|
||||
bat = '(?)'
|
||||
line = line.split('$ac')[0] + bat + line.split('$ac')[1]
|
||||
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
|
||||
self.label_bat.setText(text)
|
||||
|
||||
|
||||
def memText(self):
|
||||
"""function to set mem text"""
|
||||
full = self.mem_uf + self.mem_free
|
||||
mem = 100 * self.mem_used / full
|
||||
mem = "%5s" % (str(round(mem, 1)))
|
||||
if (self.memFormat.split('$mem')[0] != self.memFormat):
|
||||
line = self.memFormat.split('$mem')[0] + mem + self.memFormat.split('$mem')[1]
|
||||
else:
|
||||
line = self.memFormat
|
||||
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
|
||||
self.label_mem.setText(text)
|
||||
|
||||
|
||||
def swapText(self):
|
||||
"""function to set swap text"""
|
||||
full = self.swap_used + self.swap_free
|
||||
mem = 100 * self.swap_used / full
|
||||
mem = "%5s" % (str(round(mem, 1)))
|
||||
if (self.swapFormat.split('$swap')[0] != self.swapFormat):
|
||||
line = self.swapFormat.split('$swap')[0] + mem + self.swapFormat.split('$swap')[1]
|
||||
else:
|
||||
line = self.swapFormat
|
||||
text = self.formatLine.split('$LINE')[0] + line + self.formatLine.split('$LINE')[1]
|
||||
self.label_swap.setText(text)
|
||||
|
||||
|
||||
@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
|
||||
def dataUpdated(self, sourceName, data):
|
||||
"""function to update label"""
|
||||
self.dataengine.dataUpdated(sourceName, data)
|
||||
|
||||
|
||||
|
||||
def CreateApplet(parent):
|
||||
return pyTextWidget(parent)
|
284
sources/contents/code/reinit.py
Normal file
284
sources/contents/code/reinit.py
Normal file
@ -0,0 +1,284 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyKDE4.plasma import Plasma
|
||||
import config
|
||||
|
||||
|
||||
|
||||
class Reinit():
|
||||
def __init__(self, parent):
|
||||
"""class definition"""
|
||||
self.parent = parent
|
||||
|
||||
def reinit(self):
|
||||
"""function to reinitializate widget"""
|
||||
settings = config.Config(self.parent)
|
||||
self.parent.interval = settings.get('interval', 2000).toInt()[0]
|
||||
self.parent.font_family = str(settings.get('font_family', 'Terminus'))
|
||||
self.parent.font_size = settings.get('font_size', 12).toInt()[0]
|
||||
self.parent.font_color = str(settings.get('font_color', '#000000'))
|
||||
self.parent.font_style = str(settings.get('font_style', 'normal'))
|
||||
self.parent.font_weight = settings.get('font_weight', 400).toInt()[0]
|
||||
self.parent.formatLine = "<pre><p align=\"center\"><span style=\" font-family:'" + self.parent.font_family + "'; font-style:" + self.parent.font_style
|
||||
self.parent.formatLine = self.parent.formatLine + "; font-size:" + str(self.parent.font_size) + "pt; font-weight:" + str(self.parent.font_weight)
|
||||
self.parent.formatLine = self.parent.formatLine + "; color:" + self.parent.font_color + ";\">$LINE</span></p></pre>"
|
||||
self.parent.label_order = str(settings.get('label_order', '1345'))
|
||||
for label in self.parent.dict_orders.values():
|
||||
if ((label == 'cpu') or (label == 'mem') or (label == 'swap') or (label == 'net')):
|
||||
exec ('self.parent.' + label + 'Bool = int(settings.get("' + label + 'Bool", 1))')
|
||||
else:
|
||||
exec ('self.parent.' + label + 'Bool = int(settings.get("' + label + 'Bool", 0))')
|
||||
# small function for update if errors exist
|
||||
summ = 0
|
||||
for label in self.parent.dict_orders.values():
|
||||
exec ('summ += self.parent.' + label + 'Bool')
|
||||
if (len(self.parent.label_order) != summ):
|
||||
for label in self.parent.dict_orders.values():
|
||||
if ((label == 'cpu') or (label == 'mem') or (label == 'swap') or (label == 'net')):
|
||||
exec ('self.parent.' + label + 'Bool = 1')
|
||||
else:
|
||||
exec ('self.parent.' + label + 'Bool = 0')
|
||||
exec ('settings.set("' + label + 'Bool", self.parent.' + label + 'Bool)')
|
||||
self.parent.label_order = '1345'
|
||||
settings.set('label_order', self.parent.label_order)
|
||||
|
||||
for order in self.parent.label_order:
|
||||
if (order == "1"):
|
||||
if (self.parent.cpuBool == 1):
|
||||
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_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)
|
||||
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)')
|
||||
exec ('self.parent.label_coreCpu' + str(core) + '.setText(text)')
|
||||
exec ('self.parent.layout.addItem(self.parent.label_coreCpu' + str(core) + ')')
|
||||
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] + '-----' + self.parent.cpuFormat.split('$ccpu')[1].split('$cpu')[1]
|
||||
else:
|
||||
line = self.parent.cpuFormat.split('$ccpu')[1]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpu1.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_cpu1)
|
||||
else:
|
||||
self.parent.label_cpu = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.cpuFormat.split('$cpu')[0] != self.parent.cpuFormat):
|
||||
line = self.parent.cpuFormat.split('$cpu')[0] + '-----' + self.parent.cpuFormat.split('$cpu')[1]
|
||||
else:
|
||||
line = self.parent.cpuFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpu.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_cpu)
|
||||
elif (order == "2"):
|
||||
if (self.parent.tempBool == 1):
|
||||
self.parent.tempdev = str(settings.get('temp_device', '<select device>'))
|
||||
self.parent.tempFormat = str(settings.get('tempFormat', '[temp: $temp°C]'))
|
||||
self.parent.label_temp = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.tempFormat.split('$temp')[0] != self.parent.tempFormat):
|
||||
line = self.parent.tempFormat.split('$temp')[0] + '----' + self.parent.tempFormat.split('$temp')[1]
|
||||
else:
|
||||
line = self.parent.tempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_temp.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_temp)
|
||||
elif (order == "3"):
|
||||
if (self.parent.memBool == 1):
|
||||
self.parent.memFormat = str(settings.get('memFormat', '[mem: $mem%]'))
|
||||
if (self.parent.memFormat.split('$memmb')[0] != self.parent.memFormat):
|
||||
self.parent.memInMb = True
|
||||
text = self.parent.formatLine.split('$LINE')[0] + self.parent.memFormat.split('$memmb')[0] + '-----' + self.parent.memFormat.split('$memmb')[1] + self.parent.formatLine.split('$LINE')[1]
|
||||
elif (self.parent.memFormat.split('$mem')[0] != self.parent.memFormat):
|
||||
self.parent.memInMb = False
|
||||
self.parent.mem_used = 0.0
|
||||
self.parent.mem_free = 1.0
|
||||
self.parent.mem_uf = 0.0
|
||||
line = self.parent.memFormat.split('$mem')[0] + '-----' + self.parent.memFormat.split('$mem')[1]
|
||||
else:
|
||||
line = self.parent.memFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_mem = Plasma.Label(self.parent.applet)
|
||||
self.parent.label_mem.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_mem)
|
||||
elif (order == "4"):
|
||||
if (self.parent.swapBool == 1):
|
||||
self.parent.swapFormat = str(settings.get('swapFormat', '[swap: $swap%]'))
|
||||
if (self.parent.swapFormat.split('$swapmb')[0] != self.parent.swapFormat):
|
||||
self.parent.swapInMb = True
|
||||
text = self.parent.formatLine.split('$LINE')[0] + self.parent.swapFormat.split('$swapmb')[0] + '-----' + self.parent.swapFormat.split('$swapmb')[1] + self.parent.formatLine.split('$LINE')[1]
|
||||
elif (self.parent.swapFormat.split('$swap')[0] != self.parent.swapFormat):
|
||||
self.parent.swapInMb = False
|
||||
self.parent.swap_free = 1.0
|
||||
self.parent.swap_used = 0.0
|
||||
line = self.parent.swapFormat.split('$swap')[0] + '-----' + self.parent.swapFormat.split('$swap')[1]
|
||||
else:
|
||||
line = self.parent.swapFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_swap = Plasma.Label(self.parent.applet)
|
||||
self.parent.label_swap.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_swap)
|
||||
elif (order == "5"):
|
||||
if (self.parent.netBool == 1):
|
||||
self.parent.netNonFormat = str(settings.get('netNonFormat', '[net: $netKB/s]'))
|
||||
if (self.parent.netNonFormat.split('@@')[0] != self.parent.netNonFormat):
|
||||
self.parent.netdev = self.parent.netNonFormat.split('@@')[1]
|
||||
self.parent.netNonFormat = self.parent.netNonFormat.split('@@')[0] + self.parent.netNonFormat.split('@@')[2]
|
||||
else:
|
||||
self.parent.setupNetdev()
|
||||
if (self.parent.netNonFormat.split('$netdev')[0] != self.parent.netNonFormat):
|
||||
self.parent.netFormat = self.parent.netNonFormat.split('$netdev')[0] + self.parent.netdev + self.parent.netNonFormat.split('$netdev')[1]
|
||||
else:
|
||||
self.parent.netFormat = self.parent.netNonFormat
|
||||
self.parent.label_netDown = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.netFormat.split('$net')[0] != self.parent.netFormat):
|
||||
line = self.parent.netFormat.split('$net')[0] + '----'
|
||||
else:
|
||||
line = self.parent.netFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_netDown.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_netDown)
|
||||
self.parent.label_netUp = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.netFormat.split('$net')[0] != self.parent.netFormat):
|
||||
line = '/----' + self.parent.netFormat.split('$net')[1]
|
||||
else:
|
||||
line = ''
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_netUp.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_netUp)
|
||||
elif (order == "6"):
|
||||
if (self.parent.batBool == 1):
|
||||
self.parent.batFormat = str(settings.get('batFormat', '[bat: $bat%$ac]'))
|
||||
self.parent.battery_device= str(settings.get('battery_device', '/sys/class/power_supply/BAT0/capacity'))
|
||||
self.parent.ac_device = str(settings.get('ac_device', '/sys/class/power_supply/AC/online'))
|
||||
self.parent.label_bat = Plasma.Label(self.parent.applet)
|
||||
line = self.parent.batFormat
|
||||
if (line.split('$ac')[0] != line):
|
||||
line = line.split('$ac')[0] + '(-)' + line.split('$ac')[1]
|
||||
if (line.split('$bat')[0] != line):
|
||||
line = line.split('$bat')[0] + '---' + line.split('$bat')[1]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_bat.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_bat)
|
||||
elif (order == "7"):
|
||||
if (self.parent.cpuclockBool == 1):
|
||||
self.parent.cpuclockFormat = str(settings.get('cpuclockFormat', '[mhz: $cpucl]'))
|
||||
if (self.parent.cpuclockFormat.split('$ccpucl')[0] != self.parent.cpuclockFormat):
|
||||
self.parent.label_cpuclock0 = Plasma.Label(self.parent.applet)
|
||||
self.parent.label_cpuclock1 = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] != self.parent.cpuclockFormat.split('$ccpucl')[0]):
|
||||
line = self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[0] + '----' + self.parent.cpuclockFormat.split('$ccpucl')[0].split('$cpucl')[1]
|
||||
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.layout.addItem(self.parent.label_cpuclock0)
|
||||
text = self.parent.formatLine.split('$LINE')[0] + "----" + self.parent.formatLine.split('$LINE')[1]
|
||||
for core in range(self.parent.numCores):
|
||||
exec ('self.parent.label_coreCpuclock' + str(core) + ' = Plasma.Label(self.parent.applet)')
|
||||
exec ('self.parent.label_coreCpuclock' + str(core) + '.setText(text)')
|
||||
exec ('self.parent.layout.addItem(self.parent.label_coreCpuclock' + str(core) + ')')
|
||||
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] + '----' + self.parent.cpuclockFormat.split('$ccpucl')[1].split('$cpucl')[1]
|
||||
else:
|
||||
line = self.parent.cpuclockFormat.split('$ccpucl')[1]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpuclock1.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_cpuclock1)
|
||||
else:
|
||||
self.parent.label_cpuclock = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.cpuclockFormat.split('$cpucl')[0] != self.parent.cpuclockFormat):
|
||||
line = self.parent.cpuclockFormat.split('$cpucl')[0] + '----' + self.parent.cpuclockFormat.split('$cpucl')[1]
|
||||
else:
|
||||
line = self.parent.cpuclockFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_cpuclock.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_cpuclock)
|
||||
elif (order == "8"):
|
||||
if (self.parent.uptimeBool == 1):
|
||||
self.parent.uptimeFormat = str(settings.get('uptimeFormat', '[uptime: $uptime]'))
|
||||
self.parent.label_uptime = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.uptimeFormat.split('$uptime')[0] != self.parent.uptimeFormat):
|
||||
line = self.parent.uptimeFormat.split('$uptime')[0] + '---d--h--m' + self.parent.uptimeFormat.split('$uptime')[1]
|
||||
else:
|
||||
line = self.parent.uptimeFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_uptime.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_uptime)
|
||||
elif (order == "9"):
|
||||
if (self.parent.gpuBool == 1):
|
||||
self.parent.gpuFormat = str(settings.get('gpuFormat', '[gpu: $gpu%]'))
|
||||
self.parent.label_gpu = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.gpuFormat.split('$gpu')[0] != self.parent.gpuFormat):
|
||||
line = self.parent.gpuFormat.split('$gpu')[0] + '-----' + self.parent.gpuFormat.split('$gpu')[1]
|
||||
else:
|
||||
line = self.parent.gpuFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_gpu.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_gpu)
|
||||
elif (order == "a"):
|
||||
if (self.parent.gputempBool == 1):
|
||||
self.parent.gputempFormat = str(settings.get('gputempFormat', '[gpu temp: $gputemp°C]'))
|
||||
self.parent.label_gputemp = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.gputempFormat.split('$gputemp')[0] != self.parent.gputempFormat):
|
||||
line = self.parent.gputempFormat.split('$gputemp')[0] + '----' + self.parent.gputempFormat.split('$gputemp')[1]
|
||||
else:
|
||||
line = self.parent.gputempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_gputemp.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_gputemp)
|
||||
elif (order == "b"):
|
||||
if (self.parent.hddBool == 1):
|
||||
self.parent.hddFormat = str(settings.get('hddFormat', '[hdd: @@/@@%]'))
|
||||
if (self.parent.hddFormat.split('@@')[0] != self.parent.hddFormat):
|
||||
self.parent.mountPoints = self.parent.hddFormat.split('@@')[1].split(';')
|
||||
line = self.parent.hddFormat.split('@@')[0]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_hdd0 = Plasma.Label(self.parent.applet)
|
||||
self.parent.label_hdd0.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_hdd0)
|
||||
text = self.parent.formatLine.split('$LINE')[0] + "-----" + self.parent.formatLine.split('$LINE')[1]
|
||||
for mount in self.parent.mountPoints:
|
||||
exec ('self.parent.label_hdd_' + ''.join(mount.split('/')) + ' = Plasma.Label(self.parent.applet)')
|
||||
exec ('self.parent.label_hdd_' + ''.join(mount.split('/')) + '.setText(text)')
|
||||
exec ('self.parent.layout.addItem(self.parent.label_hdd_' + ''.join(mount.split('/')) + ')')
|
||||
line = self.parent.hddFormat.split('@@')[2]
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_hdd1 = Plasma.Label(self.parent.applet)
|
||||
self.parent.label_hdd1.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_hdd1)
|
||||
else:
|
||||
line = self.parent.hddFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_hdd0.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_hdd0)
|
||||
elif (order == "c"):
|
||||
if (self.parent.hddtempBool == 1):
|
||||
self.parent.hddtempFormat = str(settings.get('hddtempFormat', '[hdd temp: @@/dev/sda@@°C]'))
|
||||
self.parent.label_hddtemp = Plasma.Label(self.parent.applet)
|
||||
if (self.parent.hddtempFormat.split('@@')[0] != self.parent.hddtempFormat):
|
||||
line = self.parent.hddtempFormat.split('@@')[0] + '----' + self.parent.hddtempFormat.split('@@')[2]
|
||||
else:
|
||||
line = self.parent.hddtempFormat
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_hddtemp.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_hddtemp)
|
||||
self.parent.applet.setLayout(self.parent.layout)
|
||||
self.parent.theme = Plasma.Svg(self.parent)
|
||||
self.parent.theme.setImagePath("widgets/background")
|
||||
self.parent.setBackgroundHints(Plasma.Applet.DefaultBackground)
|
||||
self.parent.resize(10,10)
|
||||
|
||||
# create dataengines
|
||||
self.parent.thread().wait(60000)
|
||||
self.parent.dataengine.connectToEngine()
|
||||
|
||||
self.parent.timer.setInterval(self.parent.interval)
|
||||
self.parent.startPolling()
|
40
sources/contents/code/util.py
Normal file
40
sources/contents/code/util.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from shutil import copyfile
|
||||
from PyKDE4.kdecore import *
|
||||
import os
|
||||
|
||||
|
||||
|
||||
class Util():
|
||||
def __init__(self, applet):
|
||||
self.applet = applet
|
||||
|
||||
|
||||
def createDirectory(self, name):
|
||||
if not os.path.isdir(name):
|
||||
try:
|
||||
os.mkdir(name)
|
||||
except:
|
||||
print 'Failed to create directory: ' + name
|
||||
|
||||
|
||||
def kdeHome(self):
|
||||
return unicode(KGlobal.dirs().localkdedir())
|
||||
|
||||
|
||||
def createNotifyrc(self):
|
||||
print '[%s] creating notifyrc' % (self.applet._name)
|
||||
self.createDirectory(self.kdeHome() + 'share/apps/%s' % self.applet._name)
|
||||
|
||||
source = self.applet.package().path() + 'contents/misc/%s.notifyrc' % self.applet._name
|
||||
destination = self.kdeHome() + 'share/apps/%s/%s.notifyrc' % (self.applet._name, self.applet._name)
|
||||
copyfile(source, destination)
|
||||
|
||||
|
||||
def createConfig(self):
|
||||
self.createDirectory(self.kdeHome() + 'share/apps/%s' % self.applet._name)
|
||||
|
||||
source = self.applet.package().path() + 'contents/misc/%s.ini' % self.applet._name
|
||||
destination = self.kdeHome() + 'share/apps/%s/%s.ini' % (self.applet._name, self.applet._name)
|
||||
copyfile(source, destination)
|
2283
sources/contents/ui/configwindow.ui
Normal file
2283
sources/contents/ui/configwindow.ui
Normal file
File diff suppressed because it is too large
Load Diff
20
sources/metadata.desktop
Normal file
20
sources/metadata.desktop
Normal file
@ -0,0 +1,20 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Name=Py Text Monitor
|
||||
ServiceTypes=Plasma/Applet
|
||||
Type=Service
|
||||
Icon=utilities-system-monitor
|
||||
|
||||
X-Plasma-API=python
|
||||
X-Plasma-MainScript=code/main.py
|
||||
X-Plasma-RequiredExtensions=LaunchApp,LocalIO,FileDialog
|
||||
|
||||
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
|
||||
X-KDE-PluginInfo-Email=esalexeev@gmail.com
|
||||
X-KDE-PluginInfo-Name=py-text-monitor
|
||||
X-KDE-PluginInfo-Version=1.3.4
|
||||
X-KDE-PluginInfo-Website=http://kde-look.org/
|
||||
X-KDE-PluginInfo-Category=System Information
|
||||
X-KDE-PluginInfo-Depends=
|
||||
X-KDE-PluginInfo-License=GPL
|
||||
X-KDE-PluginInfo-EnabledByDefault=true
|
Reference in New Issue
Block a user