refactoring dataengine

This commit is contained in:
arcan1s 2014-04-04 13:23:21 +04:00
parent c1d55962a7
commit 0fdb7317cc
4 changed files with 212 additions and 228 deletions

View File

@ -159,10 +159,6 @@ class ConfigDefinition:
if (self.configpage.checkboxes[self.parent.dict_orders[label]].checkState() > 0): if (self.configpage.checkboxes[self.parent.dict_orders[label]].checkState() > 0):
pos = self.configpage.sliders[self.parent.dict_orders[label]].value() - 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:] self.parent.label_order = self.parent.label_order[:pos] + label + self.parent.label_order[pos+1:]
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 ('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] + '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)') exec ('settings.set("' + self.parent.dict_orders[label] + 'Bool", self.parent.' + self.parent.dict_orders[label] + 'Bool)')
@ -170,7 +166,7 @@ class ConfigDefinition:
settings.set('label_order', self.parent.label_order) settings.set('label_order', self.parent.label_order)
# reinitializate # reinitializate
self.parent.reinit.reinit(confAccept=True) self.parent.reInit()
def createConfigurationInterface(self, parent): def createConfigurationInterface(self, parent):
@ -272,9 +268,6 @@ class ConfigDefinition:
self.configpage.checkboxes[self.parent.dict_orders[label]].setCheckState(bool) self.configpage.checkboxes[self.parent.dict_orders[label]].setCheckState(bool)
if (bool > 0): if (bool > 0):
self.configpage.sliders[self.parent.dict_orders[label]].setValue(self.parent.label_order.find(label)+1) self.configpage.sliders[self.parent.dict_orders[label]].setValue(self.parent.label_order.find(label)+1)
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]]))) 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]])))
# add config page # add config page

View File

@ -77,209 +77,170 @@ class DataEngine:
dataEngines['system'].connectSource("system/uptime", self.parent, interval) dataEngines['system'].connectSource("system/uptime", self.parent, interval)
def dataUpdated(self, sourceName, data): def dataUpdated(self, sourceName, data, ptm):
"""function to update data""" """function to update data"""
try: adv = ptm['vars']['adv']
systemDataEngine = ptm['dataengine']['system']
formats = ptm['vars']['formats']
interval = ptm['vars']['app']['interval']
names = ptm['names']
updatedData = {'name':None, 'type':None, 'value':None}
if True:
#try:
if (sourceName == "system/uptime"): if (sourceName == "system/uptime"):
updatedData['name'] = "uptime"
value = datetime.timedelta(0, int(round(float(data[QString(u'value')]), 1))) value = datetime.timedelta(0, int(round(float(data[QString(u'value')]), 1)))
days = value.days days = value.days
hours = int(value.seconds / 60 / 60) hours = int(value.seconds / 60 / 60)
minutes = int(value.seconds / 60 % 60) minutes = int(value.seconds / 60 % 60)
line = self.parent.uptimeFormat if (formats['uptime'].split('$uptime')[0] != formats['uptime']):
if (line.split('$uptime')[0] != line): updatedData['value'] = "%3id%2ih%2im" % (days, hours, minutes)
uptimeText = "%3id%2ih%2im" % (days, hours, minutes) elif (formats['uptime'].split('$custom')[0] != formats['uptime']):
line = line.split('$uptime')[0] + uptimeText + line.split('$uptime')[1] updatedData['value'] = adv['customUptime']
elif (line.split('$custom')[0] != line): if (updatedData['value'].split('$dd')[0] != updatedData['value']):
uptimeText = self.parent.custom_uptime updatedData['value'] = "%s%03i%s" % (updatedData['value'].split('$dd')[0], days, updatedData['value'].split('$dd')[1])
if (uptimeText.split('$dd')[0] != uptimeText): if (updatedData['value'].split('$d')[0] != updatedData['value']):
uptimeText = "%s%03i%s" % (uptimeText.split('$dd')[0], days, uptimeText.split('$dd')[1]) updatedData['value'] = "%s%3i%s" % (updatedData['value'].split('$d')[0], days, updatedData['value'].split('$d')[1])
if (uptimeText.split('$d')[0] != uptimeText): if (updatedData['value'].split('$hh')[0] != updatedData['value']):
uptimeText = "%s%3i%s" % (uptimeText.split('$d')[0], days, uptimeText.split('$d')[1]) updatedData['value'] = "%s%02i%s" % (updatedData['value'].split('$hh')[0], hours, updatedData['value'].split('$hh')[1])
if (uptimeText.split('$hh')[0] != uptimeText): if (updatedData['value'].split('$h')[0] != updatedData['value']):
uptimeText = "%s%02i%s" % (uptimeText.split('$hh')[0], hours, uptimeText.split('$hh')[1]) updatedData['value'] = "%s%2i%s" % (updatedData['value'].split('$h')[0], hours, updatedData['value'].split('$h')[1])
if (uptimeText.split('$h')[0] != uptimeText): if (updatedData['value'].split('$mm')[0] != updatedData['value']):
uptimeText = "%s%2i%s" % (uptimeText.split('$h')[0], hours, uptimeText.split('$h')[1]) updatedData['value'] = "%s%02i%s" % (updatedData['value'].split('$mm')[0], minutes, updatedData['value'].split('$mm')[1])
if (uptimeText.split('$mm')[0] != uptimeText): if (updatedData['value'].split('$m')[0] != updatedData['value']):
uptimeText = "%s%02i%s" % (uptimeText.split('$mm')[0], minutes, uptimeText.split('$mm')[1]) updatedData['value'] = "%s%2i%s" % (updatedData['value'].split('$m')[0], minutes, updatedData['value'].split('$m')[1])
if (uptimeText.split('$m')[0] != uptimeText):
uptimeText = "%s%2i%s" % (uptimeText.split('$m')[0], minutes, uptimeText.split('$m')[1])
line = line.split('$custom')[0] + uptimeText + line.split('$custom')[1]
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"): elif (sourceName == "cpu/system/TotalLoad"):
value = str(round(float(data[QString(u'value')]), 1)) updatedData['name'] = "cpu"
self.parent.cpuCore[-1] = "%5s" % (value) updatedData['type'] = -1
if (self.parent.cpuBool == 2): value = round(data[QString(u'value')].toFloat()[0], 1)
self.parent.tooltipAgent.addValue('cpu', float(value), self.parent.tooltipNum) updatedData['value'] = "%5.1f" % (value)
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "TotalLoad")): elif ((sourceName[:7] == "cpu/cpu") and (sourceName.split('/')[2] == "TotalLoad")):
value = str(round(float(data[QString(u'value')]), 1)) updatedData['name'] = "cpu"
self.parent.cpuCore[int(str(sourceName)[7])] = "%5s" % (value) updatedData['type'] = int(sourceName[7])
value = round(data[QString(u'value')].toFloat()[0], 1)
updatedData['value'] = "%5.1f" % (value)
elif (sourceName == "cpu/system/AverageClock"): elif (sourceName == "cpu/system/AverageClock"):
value = str(data[QString(u'value')]).split('.')[0] updatedData['name'] = "cpuclock"
self.parent.cpuClockCore[-1] = "%4s" % (value) updatedData['type'] = -1
if (self.parent.cpuclockBool == 2): value = round(data[QString(u'value')].toFloat()[0], 0)
self.parent.tooltipAgent.addValue('cpuclock', float(value), self.parent.tooltipNum) updatedData['value'] = "%4.0f" % (value)
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "clock")): elif ((sourceName[:7] == "cpu/cpu") and (sourceName.split('/')[2] == "clock")):
value = str(data[QString(u'value')]).split('.')[0] updatedData['name'] = "cpuclock"
self.parent.cpuClockCore[int(str(sourceName)[7])] = "%4s" % (value) updatedData['type'] = int(sourceName[7])
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/transmitter/data"): value = round(data[QString(u'value')].toFloat()[0], 0)
value = str(data[QString(u'value')]).split('.')[0] updatedData['value'] = "%4.0f" % (value)
self.parent.netSpeed["up"] = "%4s" % (value) elif ((sourceName.split('/')[0] == "network") and (sourceName.split('/')[3] == "transmitter")):
if (self.parent.netBool == 2): updatedData['name'] = "net"
self.parent.tooltipAgent.addValue('up', float(value), self.parent.tooltipNum) updatedData['type'] = "up"
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/receiver/data"): value = round(data[QString(u'value')].toFloat()[0], 0)
value = str(data[QString(u'value')]).split('.')[0] updatedData['value'] = "%4.0f" % (value)
self.parent.netSpeed["down"] = "%4s" % (value) elif ((sourceName.split('/')[0] == "network") and (sourceName.split('/')[3] == "receiver")):
if (self.parent.netBool == 2): updatedData['name'] = "net"
self.parent.tooltipAgent.addValue('down', float(value), self.parent.tooltipNum) updatedData['type'] = "down"
value = round(data[QString(u'value')].toFloat()[0], 0)
updatedData['value'] = "%4.0f" % (value)
# update network device # update network device
self.parent.updateNetdev = self.parent.updateNetdev + 1 self.updateNetdev = self.updateNetdev + 1
if (self.parent.updateNetdev == 100): if (self.updateNetdev == 100):
self.parent.updateNetdev = 0 self.updateNetdev = 0
if (self.parent.netNonFormat.split('@@')[0] == self.parent.netNonFormat): if (adv['netdevBool'] > 0):
dataEngines['system'].disconnectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent) systemDataEngine.disconnectSource("network/interfaces/" + names['net'] + "/transmitter/data", self.parent)
dataEngines['system'].disconnectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent) systemDataEngine.disconnectSource("network/interfaces/" + names['net'] + "/receiver/data", self.parent)
self.parent.netdev = self.parent.setupNetdev() names['net'] = self.parent.setNetdev()
dataEngines['system'].connectSource("network/interfaces/"+self.parent.netdev+"/transmitter/data", self.parent, self.parent.interval) systemDataEngine.connectSource("network/interfaces/" + names['net'] + "/transmitter/data", self.parent, interval)
dataEngines['system'].connectSource("network/interfaces/"+self.parent.netdev+"/receiver/data", self.parent, self.parent.interval) systemDataEngine.connectSource("network/interfaces/" + names['net'] + "/receiver/data", self.parent, interval)
if (self.parent.netNonFormat.split('$netdev')[0] != self.parent.netNonFormat): elif (sourceName.split('/')[0] == "lmsensors"):
self.parent.netFormat = self.parent.netNonFormat.split('$netdev')[0] + self.parent.netdev + self.parent.netNonFormat.split('$netdev')[1] updatedData['name'] = "temp"
else: updatedData['type'] = sourceName
self.parent.netFormat = self.parent.netNonFormat value = round(data[QString(u'value')].toFloat()[0], 1)
elif (str(sourceName).split('/')[0] == "lmsensors"): updatedData['value'] = "%4.1f" % (value)
value = str(round(float(data[QString(u'value')]), 1))
self.parent.temp[str(sourceName)] = "%4s" % (value)
elif (str(sourceName).split('/')[0] == "partitions"): elif (str(sourceName).split('/')[0] == "partitions"):
value = str(round(float(data[QString(u'value')]), 1)) updatedData['name'] = "hdd"
self.parent.mount['/'+'/'.join(str(sourceName).split('/')[1:-1])] = "%5s" % (value) updatedData['type'] = '/' + '/'.join(sourceName.split('/')[1:-1])
value = round(data[QString(u'value')].toFloat()[0], 1)
updatedData['value'] = "%5.1f" % (value)
elif (sourceName == "mem/physical/free"): elif (sourceName == "mem/physical/free"):
self.parent.memValues['free'] = float(data[QString(u'value')]) updatedData['name'] = "mem"
updatedData['type'] = "free"
value = round(data[QString(u'value')].toFloat()[0], 1)
updatedData['value'] = value
elif (sourceName == "mem/physical/used"): elif (sourceName == "mem/physical/used"):
self.parent.memValues['total'] = self.parent.memValues['free'] + float(data[QString(u'value')]) updatedData['name'] = "mem"
updatedData['type'] = "used"
value = round(data[QString(u'value')].toFloat()[0], 1)
updatedData['value'] = value
elif (sourceName == "mem/physical/application"): elif (sourceName == "mem/physical/application"):
self.parent.memValues['used'] = float(data[QString(u'value')]) updatedData['name'] = "mem"
if (self.parent.memInMb): updatedData['type'] = "app"
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0] value = round(data[QString(u'value')].toFloat()[0], 1)
mem = "%5s" % (mem) updatedData['value'] = value
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)
if (self.parent.memBool == 2):
self.parent.tooltipAgent.addValue('mem', float(data[QString(u'value')]), self.parent.tooltipNum)
elif (sourceName == "mem/swap/free"): elif (sourceName == "mem/swap/free"):
self.parent.swapValues['free'] = float(data[QString(u'value')]) updatedData['name'] = "swap"
self.parent.swapValues['total'] = self.parent.swapValues['free'] + self.parent.swapValues['used'] updatedData['type'] = "free"
value = round(data[QString(u'value')].toFloat()[0], 1)
updatedData['value'] = value
elif (sourceName == "mem/swap/used"): elif (sourceName == "mem/swap/used"):
self.parent.swapValues['used'] = float(data[QString(u'value')]) updatedData['name'] = "swap"
if (self.parent.swapInMb): updatedData['type'] = "used"
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0] value = round(data[QString(u'value')].toFloat()[0], 1)
mem = "%5s" % (mem) updatedData['value'] = value
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)
if (self.parent.swapBool == 2):
self.parent.tooltipAgent.addValue('swap', float(data[QString(u'value')]), self.parent.tooltipNum)
elif (sourceName == "gpu"): elif (sourceName == "gpu"):
value = str(data[QString(u'GPU')]) updatedData['name'] = "gpu"
gpuText = "%4s" % (value) value = round(data[QString(u'GPU')].toFloat()[0], 1)
if (self.parent.gpuFormat.split('$gpu')[0] != self.parent.gpuFormat): updatedData['value'] = "%4.1f" % (value)
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"): elif (sourceName == "gputemp"):
value = str(data[QString(u'GPUTemp')]) updatedData['name'] = "gputemp"
gputempText = "%4s" % (value) value = round(data[QString(u'GPUTemp')].toFloat()[0], 1)
if (self.parent.gputempFormat.split('$gputemp')[0] != self.parent.gputempFormat): updatedData['value'] = "%4.1f" % (value)
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"): elif (sourceName == "hddtemp"):
for item in self.parent.hddNames: updatedData['name'] = "hddtemp"
value = str(data[QString(item)]) updatedData['value'] = {}
self.parent.hdd[item] = "%4s" % (value) for item in names['hddtemp']:
line = self.parent.hddtempFormat value = round(data[QString(item)].toFloat()[0], 1)
for i in range(len(self.parent.hddNames)): updatedData['value'][item] = "%4.1f" % (value)
if (line.split('$hddtemp'+str(i))[0] != line):
line = line.split('$hddtemp'+str(i))[0] + self.parent.hdd[self.parent.hddNames[i]] + line.split('$hddtemp'+str(i))[1]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_hddtemp.setText(text)
elif (sourceName == "player"): elif (sourceName == "player"):
if (self.parent.player_name == 0): updatedData['name'] = "player"
album = str(data[QString(u'amarok_album')].toUtf8()).decode("utf-8") updatedData['value'] = {}
artist = str(data[QString(u'amarok_artist')].toUtf8()).decode("utf-8") if (adv['player'] == 0):
progress = str(data[QString(u'amarok_progress')].toUtf8()).decode("utf-8") updatedData['value']['album'] = str(data[QString(u'amarok_album')].toUtf8()).decode("utf-8")
time = str(data[QString(u'amarok_duration')].toUtf8()).decode("utf-8") updatedData['value']['artist'] = str(data[QString(u'amarok_artist')].toUtf8()).decode("utf-8")
title = str(data[QString(u'amarok_title')].toUtf8()).decode("utf-8") updatedData['value']['progress'] = str(data[QString(u'amarok_progress')].toUtf8()).decode("utf-8")
elif (self.parent.player_name == 1): updatedData['value']['time'] = str(data[QString(u'amarok_duration')].toUtf8()).decode("utf-8")
album = str(data[QString(u'mpd_album')].toUtf8()).decode("utf-8") updatedData['value']['title'] = str(data[QString(u'amarok_title')].toUtf8()).decode("utf-8")
artist = str(data[QString(u'mpd_artist')].toUtf8()).decode("utf-8") elif (adv['player'] == 1):
progress = str(data[QString(u'mpd_progress')].toUtf8()).decode("utf-8") updatedData['value']['album'] = str(data[QString(u'mpd_album')].toUtf8()).decode("utf-8")
time = str(data[QString(u'mpd_duration')].toUtf8()).decode("utf-8") updatedData['value']['artist'] = str(data[QString(u'mpd_artist')].toUtf8()).decode("utf-8")
title = str(data[QString(u'mpd_title')].toUtf8()).decode("utf-8") updatedData['value']['progress'] = str(data[QString(u'mpd_progress')].toUtf8()).decode("utf-8")
elif (self.parent.player_name == 2): updatedData['value']['time'] = str(data[QString(u'mpd_duration')].toUtf8()).decode("utf-8")
album = str(data[QString(u'qmmp_album')].toUtf8()).decode("utf-8") updatedData['value']['title'] = str(data[QString(u'mpd_title')].toUtf8()).decode("utf-8")
artist = str(data[QString(u'qmmp_artist')].toUtf8()).decode("utf-8") elif (adv['player'] == 2):
progress = str(data[QString(u'qmmp_progress')].toUtf8()).decode("utf-8") updatedData['value']['album'] = str(data[QString(u'qmmp_album')].toUtf8()).decode("utf-8")
time = str(data[QString(u'qmmp_duration')].toUtf8()).decode("utf-8") updatedData['value']['artist'] = str(data[QString(u'qmmp_artist')].toUtf8()).decode("utf-8")
title = str(data[QString(u'qmmp_title')].toUtf8()).decode("utf-8") updatedData['value']['progress'] = str(data[QString(u'qmmp_progress')].toUtf8()).decode("utf-8")
line = self.parent.playerFormat updatedData['value']['time'] = str(data[QString(u'qmmp_duration')].toUtf8()).decode("utf-8")
if (line.split('$album')[0] != line): updatedData['value']['title'] = str(data[QString(u'qmmp_title')].toUtf8()).decode("utf-8")
line = line.split('$album')[0] + album + line.split('$album')[1]
if (line.split('$artist')[0] != line):
line = line.split('$artist')[0] + artist + line.split('$artist')[1]
if (line.split('$progress')[0] != line):
timeText = '%02i:%02i' % (int(time)/60, int(time)%60)
line = line.split('$progress')[0] + progress + line.split('$progress')[1]
if (line.split('$time')[0] != line):
timeText = '%02i:%02i' % (int(time)/60, int(time)%60)
line = line.split('$time')[0] + timeText + line.split('$time')[1]
if (line.split('$title')[0] != line):
line = line.split('$title')[0] + title + line.split('$title')[1]
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_player.setText(text)
elif (sourceName == "Local"): elif (sourceName == "Local"):
if (self.parent.timeFormat.split('$time')[0] != self.parent.timeFormat): updatedData['name'] = "time"
value = str(data[QString(u'DateTime')].toString(Qt.TextDate).toUtf8()) if (formats['time'].split('$time')[0] != formats['time']):
line = self.parent.timeFormat.split('$time')[0] + value.decode("utf-8") + self.parent.timeFormat.split('$time')[1] value = str(data[QString(u'DateTime')].toString(Qt.TextDate).toUtf8()).decode("utf-8")
elif (self.parent.timeFormat.split('$isotime')[0] != self.parent.timeFormat): elif (formats['time'].split('$isotime')[0] != formats['time']):
value = str(data[QString(u'DateTime')].toString(Qt.ISODate).toUtf8()) value = str(data[QString(u'DateTime')].toString(Qt.ISODate).toUtf8()).decode("utf-8")
line = self.parent.timeFormat.split('$isotime')[0] + value.decode("utf-8") + self.parent.timeFormat.split('$isotime')[1] elif (formats['time'].split('$shorttime')[0] != formats['time']):
elif (self.parent.timeFormat.split('$shorttime')[0] != self.parent.timeFormat): value = str(data[QString(u'DateTime')].toString(Qt.SystemLocaleShortDate).toUtf8()).decode("utf-8")
value = str(data[QString(u'DateTime')].toString(Qt.SystemLocaleShortDate).toUtf8()) elif (formats['time'].split('$longtime')[0] != formats['time']):
line = self.parent.timeFormat.split('$shorttime')[0] + value.decode("utf-8") + self.parent.timeFormat.split('$shorttime')[1] value = str(data[QString(u'DateTime')].toString(Qt.SystemLocaleLongDate).toUtf8()).decode("utf-8")
elif (self.parent.timeFormat.split('$longtime')[0] != self.parent.timeFormat): elif (formats['time'].split('$custom')[0] != formats['time']):
value = str(data[QString(u'DateTime')].toString(Qt.SystemLocaleLongDate).toUtf8())
line = self.parent.timeFormat.split('$longtime')[0] + value.decode("utf-8") + self.parent.timeFormat.split('$longtime')[1]
elif (self.parent.timeFormat.split('$custom')[0] != self.parent.timeFormat):
rawDate = data[QString(u'DateTime')] rawDate = data[QString(u'DateTime')]
value = self.parent.custom_time value = adv['customTime']
for letters in timeLetters: for letters in timeLetters:
if (value.split('$' + letters)[0] != value): if (value.split('$' + letters)[0] != value):
value = value.split('$' + letters)[0] + str(rawDate.toString(letters).toUtf8()).decode("utf-8") + value.split('$' + letters)[1] value = value.split('$' + letters)[0] + str(rawDate.toString(letters).toUtf8()).decode("utf-8") + value.split('$' + letters)[1]
line = self.parent.timeFormat.split('$custom')[0] + value + self.parent.timeFormat.split('$custom')[1] updatedData['value'] = value
else:
line = self.parent.timeFormat
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_time.setText(text)
elif (sourceName == "custom"): elif (sourceName == "custom"):
updatedData['name'] = "custom"
value = str(data[QString(u'custom')].toUtf8()).decode("utf-8") value = str(data[QString(u'custom')].toUtf8()).decode("utf-8")
if (self.parent.customFormat.split('$custom')[0] != self.parent.customFormat): updatedData['value'] = value
line = self.parent.customFormat.split('$custom')[0] + value + self.parent.customFormat.split('$custom')[1] #except:
else: #pass
line = self.parent.customFormat
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_custom.setText(text)
self.parent.update() return updatedData
except:
pass

View File

@ -71,7 +71,7 @@ class pyTextWidget(plasmascript.Applet):
QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel) QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel)
self.initTooltip() self.initTooltip()
self.reinit.reinit() self.reInit()
self.applet.setLayout(self.ptm['layout']) self.applet.setLayout(self.ptm['layout'])
self.theme = Plasma.Svg(self) self.theme = Plasma.Svg(self)
self.theme.setImagePath("widgets/background") self.theme.setImagePath("widgets/background")
@ -132,21 +132,6 @@ class pyTextWidget(plasmascript.Applet):
os.system("ksysguard &") os.system("ksysguard &")
def setupNetdev(self):
"""function to setup network device"""
netdev = "lo"
interfaces = QDir.entryList(QDir(self.netdir), QDir.Dirs | QDir.NoDotAndDotDot)
for device in interfaces:
if (str(device) != "lo"):
try:
with open(self.netdir+"/"+str(device)+"/operstate", "r") as stateFile:
if (stateFile.readline() == "up\n"):
netdev = str(device)
except:
pass
return netdev
def setupVar(self): def setupVar(self):
"""function to setup variables""" """function to setup variables"""
self.ptm = {} self.ptm = {}
@ -182,16 +167,17 @@ class pyTextWidget(plasmascript.Applet):
'swap':[0, 0], 'down':[0, 0], 'up':[0, 0]} 'swap':[0, 0], 'down':[0, 0], 'up':[0, 0]}
# values # values
self.ptm['values'] = {} self.ptm['values'] = {}
self.ptm['values']['cpu'] = {-1:0.0} self.ptm['values']['cpu'] = {-1:" 0.0"}
self.ptm['values']['cpuclock'] = {-1:0} self.ptm['values']['cpuclock'] = {-1:" 0"}
numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo")) numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo"))
for i in range(numCores): for i in range(numCores):
self.ptm['values']['cpu'][i] = 0.0 self.ptm['values']['cpu'][i] = " 0.0"
self.ptm['values']['cpuclock'][i] = 0 self.ptm['values']['cpuclock'][i] = " 0"
self.ptm['values']['hdd'] = {} self.ptm['values']['hdd'] = {}
self.ptm['values']['hddtemp'] = {} self.ptm['values']['hddtemp'] = {}
self.ptm['values']['mem'] = {'used':0, 'free':0, 'total':1} self.ptm['values']['mem'] = {'used':0, 'free':0, 'total':1}
self.ptm['values']['net'] = {"up":0, "down":0} self.ptm['values']['net'] = {"up":" 0", "down":" 0"}
self.ptm['values']['player'] = {}
self.ptm['values']['swap'] = {'used':0, 'free':0, 'total':1} self.ptm['values']['swap'] = {'used':0, 'free':0, 'total':1}
self.ptm['values']['temp'] = {} self.ptm['values']['temp'] = {}
# variables # variables
@ -212,10 +198,10 @@ class pyTextWidget(plasmascript.Applet):
self.hdd = {} self.hdd = {}
self.mountNames = [] self.mountNames = []
self.mount = {} self.mount = {}
self.memValues = {'used':0.0, 'free':0.0, 'total':1.0} self.memValues = {'app':0.0, 'free':0.0, 'used':0.0}
self.netdev = '' self.netdev = ''
self.netSpeed = {"up":" 0", "down":" 0"} self.netSpeed = {"up":" 0", "down":" 0"}
self.swapValues = {'used':0.0, 'free':0.0, 'total':1.0} self.swapValues = {'free':0.0, 'used':0.0}
self.tempNames = [] self.tempNames = []
self.temp = {} self.temp = {}
self.tooltipBound = {'cpu':100.0, 'cpuclock':4000.0, 'mem':16000.0, self.tooltipBound = {'cpu':100.0, 'cpuclock':4000.0, 'mem':16000.0,
@ -327,6 +313,10 @@ class pyTextWidget(plasmascript.Applet):
self.label_cpuclock.setText(text) self.label_cpuclock.setText(text)
def hddText(self):
"""function to set hddtemp text"""
def memText(self): def memText(self):
"""function to set mem text""" """function to set mem text"""
try: try:
@ -355,6 +345,8 @@ class pyTextWidget(plasmascript.Applet):
def netText(self): def netText(self):
"""function to set network text""" """function to set network text"""
line = self.netFormat line = self.netFormat
if (line.split('$netdev')[0] != 0):
line = line.split('$netdev')[0] + self.ptm['names']['net'] + line.split('$netdev')[1]
if (line.split('$up')[0] != line): if (line.split('$up')[0] != line):
line = line.split('$up')[0] + self.netSpeed['up'] + line.split('$up')[1] line = line.split('$up')[0] + self.netSpeed['up'] + line.split('$up')[1]
if (line.split('$down')[0] != line): if (line.split('$down')[0] != line):
@ -422,6 +414,39 @@ class pyTextWidget(plasmascript.Applet):
"""function to disconnect from sources""" """function to disconnect from sources"""
def reInit(self):
"""function to run reinit"""
self.reinit.reinit()
if (self.ptm['vars']['adv']['netdevBool'] == 0):
self.ptm['names']['net'] = self.setNetdev()
self.resize(10, 10)
# create dataengines
self.thread().wait(60000)
self.connectToEngine()
self.timer.setInterval(self.ptm['vars']['app']['interval'])
self.startPolling()
def setNetdev(self):
"""function to set network device"""
netdev = "lo"
self.ptm['vars']['adv']
netdir = self.ptm['vars']['adv']['netDir']
interfaces = QDir.entryList(QDir(netdir), QDir.Dirs | QDir.NoDotAndDotDot)
for device in interfaces:
if (str(device) != "lo"):
try:
with open(netdir + '/' + str(device) + '/operstate', 'r') as stateFile:
if (stateFile.readline() == "up\n"):
netdev = str(device)
except:
pass
self.ptm['names']['net'] = netdev
return netdev
def setText(self, name=None, text=None): def setText(self, name=None, text=None):
"""function to set text to labels""" """function to set text to labels"""
self.ptm['labels'][name].setText(text) self.ptm['labels'][name].setText(text)
@ -430,7 +455,19 @@ class pyTextWidget(plasmascript.Applet):
@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)") @pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
def dataUpdated(self, sourceName, data): def dataUpdated(self, sourceName, data):
"""function to update label""" """function to update label"""
self.dataengine.dataUpdated(sourceName, data) updatedData = self.dataengine.dataUpdated(str(sourceName), data, self.ptm)
# update tooltips
if (updatedData['name'] in ['cpu', 'cpuclock', 'mem', 'swap', 'net']):
pass
# update labels where is needed
if (updatedData['name'] in ['gpu', 'gputemp', 'player']):
pass
else:
if (updatedData['type']):
pass
else:
pass
self.update()

View File

@ -69,12 +69,14 @@ class Reinit():
exec("ptmVars['bools'][label] = settings.get('" + label + "Bool', 2).toInt()[0]") exec("ptmVars['bools'][label] = settings.get('" + label + "Bool', 2).toInt()[0]")
else: else:
exec("ptmVars['bools'][label] = settings.get('" + label + "Bool', 0).toInt()[0]") exec("ptmVars['bools'][label] = settings.get('" + label + "Bool', 0).toInt()[0]")
print (ptmVars['bools'])
ptmNames = {} ptmNames = {}
ptmNames['hdd'] = str(settings.get('mount', '/')).split('@@') ptmNames['hdd'] = str(settings.get('mount', '/')).split('@@')
ptmNames['hddtemp'] = str(settings.get('hdd', '/dev/sda')).split('@@') ptmNames['hddtemp'] = str(settings.get('hdd', '/dev/sda')).split('@@')
if (ptmVars['adv']['netdevBool'] > 0):
ptmNames['net'] = str(settings.get('custom_netdev', 'lo')) ptmNames['net'] = str(settings.get('custom_netdev', 'lo'))
else:
ptmNames['net'] = ""
ptmNames['temp'] = str(settings.get('temp_device', '')).split('@@') ptmNames['temp'] = str(settings.get('temp_device', '')).split('@@')
self.parent.applySettings('names', ptmNames) self.parent.applySettings('names', ptmNames)
@ -93,12 +95,3 @@ class Reinit():
else: else:
ptmVars['tooltip']['required'].append(label) ptmVars['tooltip']['required'].append(label)
self.parent.applySettings('vars', ptmVars) self.parent.applySettings('vars', ptmVars)
self.parent.resize(10, 10)
# create dataengines
self.parent.thread().wait(60000)
self.parent.connectToEngine()
self.parent.timer.setInterval(self.parent.interval)
self.parent.startPolling()