added scalling to tooltip

This commit is contained in:
arcan1s 2014-04-03 11:46:51 +04:00
parent 0db909d914
commit 4218a4da08
6 changed files with 45 additions and 55 deletions

View File

@ -3,7 +3,7 @@
pkgname=kdeplasma-applets-pytextmonitor
_pkgname=pytextmonitor
pkgver=1.7.1
pkgver=1.7.2
pkgrel=1
pkgdesc="Minimalistic Plasmoid script written on Python2. It looks like widgets in awesome-wm"
arch=('i686' 'x86_64')
@ -19,7 +19,7 @@ optdepends=("hddtemp: for HDD temperature monitor"
makedepends=('automoc4' 'cmake')
source=(https://github.com/arcan1s/pytextmonitor/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
install=${pkgname}.install
md5sums=('bdc5020484c0d5cf9404cdedfb51b341')
md5sums=('e6069564afe15e655c918d3411573415')
backup=('usr/share/config/extsysmon.conf')
build () {

View File

@ -135,15 +135,13 @@ class ConfigDefinition:
self.parent.layout.removeItem(self.parent.label_gputemp)
if (self.parent.memBool > 0):
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.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 > 0):
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.systemmonitor.disconnectSource("mem/swap/free", self.parent)
self.parent.label_swap.setText('')
self.parent.layout.removeItem(self.parent.label_swap)
if (self.parent.hddBool > 0):

View File

@ -65,18 +65,12 @@ class DataEngine:
if (self.parent.gputempBool > 0):
self.parent.extsysmon.connectSource("gputemp", self.parent, self.parent.interval)
if (self.parent.memBool > 0):
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))
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 > 0):
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))
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 > 0):
for item in self.parent.mountNames:
self.parent.systemmonitor.connectSource("partitions" + item + "/filllevel", self.parent, self.parent.interval)
@ -167,10 +161,11 @@ class DataEngine:
value = str(round(float(data[QString(u'value')]), 1))
self.parent.mount['/'+'/'.join(str(sourceName).split('/')[1:-1])] = "%5s" % (value)
elif (sourceName == "mem/physical/free"):
self.parent.mem_free = float(data[QString(u'value')])
self.parent.memValues['free'] = float(data[QString(u'value')])
elif (sourceName == "mem/physical/used"):
self.parent.mem_uf = float(data[QString(u'value')])
self.parent.memValues['total'] = self.parent.memValues['free'] + float(data[QString(u'value')])
elif (sourceName == "mem/physical/application"):
self.parent.memValues['used'] = float(data[QString(u'value')])
if (self.parent.memInMb):
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0]
mem = "%5s" % (mem)
@ -180,13 +175,13 @@ class DataEngine:
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')])
if (self.parent.memBool == 2):
self.parent.tooltipAgent.addValue('mem', float(data[QString(u'value')]), self.parent.tooltipNum)
elif (sourceName == "mem/swap/free"):
self.parent.swap_free = float(data[QString(u'value')])
self.parent.swapValues['free'] = float(data[QString(u'value')])
self.parent.swapValues['total'] = self.parent.swapValues['free'] + self.parent.swapValues['used']
elif (sourceName == "mem/swap/used"):
self.parent.swapValues['used'] = float(data[QString(u'value')])
if (self.parent.swapInMb):
mem = str(round(float(data[QString(u'value')]) / 1024, 0)).split('.')[0]
mem = "%5s" % (mem)
@ -196,8 +191,6 @@ class DataEngine:
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')])
if (self.parent.swapBool == 2):
self.parent.tooltipAgent.addValue('swap', float(data[QString(u'value')]), self.parent.tooltipNum)
elif (sourceName == "gpu"):

View File

@ -98,8 +98,11 @@ class pyTextWidget(plasmascript.Applet):
def updateTooltip(self):
"""function to update tooltip"""
self.tooltipBound['mem'] = self.memValues['total']
self.tooltipBound['swap'] = self.swapValues['total']
self.tooltip_view.resize(100.0*(len(self.tooltipReq)-self.tooltipReq.count('up')), 100.0)
self.tooltipAgent.createGraphic(self.tooltipReq, self.tooltipColors, self.tooltipValues, self.tooltip_scene)
self.tooltipAgent.createGraphic(self.tooltipReq, self.tooltipColors,
self.tooltipBound, self.tooltipValues, self.tooltip_scene)
self.tooltip.setImage(QPixmap.grabWidget(self.tooltip_view))
Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
@ -126,25 +129,29 @@ class pyTextWidget(plasmascript.Applet):
def setupVar(self):
"""function to setup variables"""
self.netdev = ''
self.cpuCore = {-1:" 0.0"}
self.cpuClockCore = {-1:" 0"}
numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo"))
for i in range(numCores):
self.cpuCore[i] = str(" 0.0")
self.cpuClockCore[i] = str(" 0")
self.netSpeed = {"up":" 0", "down":" 0"}
self.tempNames = []
self.temp = {}
self.mountNames = []
self.mount = {}
self.hddNames = []
self.hdd = {}
self.mountNames = []
self.mount = {}
self.memValues = {'used':0.0, 'free':0.0, 'total':1.0}
self.netdev = ''
self.netSpeed = {"up":" 0", "down":" 0"}
self.swapValues = {'used':0.0, 'free':0.0, 'total':1.0}
self.tempNames = []
self.temp = {}
self.tooltipBound = {'cpu':100.0, 'cpuclock':4000.0, 'mem':16000.0,
'swap':16000, 'down':10000.0, 'up':10000.0}
self.tooltipColors = {}
self.tooltipNum = 100
self.tooltipReq = []
self.tooltipValues = {'cpu':[0.0, 0.01], 'cpuclock':[0.0, 0.01], 'mem':[0.0, 0.01],
'swap':[0.0, 0.01], 'up':[0.0, 0.01], 'down':[0.0, 0.01]}
'swap':[0.0, 0.01], 'down':[0.0, 0.01], 'up':[0.0, 0.01]}
# create dictionaries
self.dict_orders = {'6':'bat', '1':'cpu', '7':'cpuclock', 'f':'custom', '9':'gpu',
@ -249,9 +256,8 @@ class pyTextWidget(plasmascript.Applet):
def memText(self):
"""function to set mem text"""
full = self.mem_uf + self.mem_free
try:
mem = 100 * self.mem_used / full
mem = 100 * self.memValues['used'] / self.memValues['total']
mem = "%5s" % (str(round(mem, 1)))
except:
mem = " N\\A"
@ -286,9 +292,8 @@ class pyTextWidget(plasmascript.Applet):
def swapText(self):
"""function to set swap text"""
full = self.swap_used + self.swap_free
try:
mem = 100 * self.swap_used / full
mem = 100 * self.swapValues['used'] / self.swapValues['total']
mem = "%5s" % (str(round(mem, 1)))
except:
mem = " N\\A"

View File

@ -128,9 +128,6 @@ class Reinit():
self.parent.memInMb = True
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
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_mem.setText(text)
@ -145,8 +142,6 @@ class Reinit():
self.parent.swapInMb = True
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
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
self.parent.label_swap.setText(text)

View File

@ -35,23 +35,22 @@ class Tooltip():
self.parent.tooltipValues[type].append(value)
def createGraphic(self, types, colors, values, widget):
def createGraphic(self, types, colors, bounds, values, widget):
"""function to create graph"""
widget.clear()
maxOne = [100.0, 100.0]
pen = QPen()
bounds['down'] = 1.0
for value in values['down']:
if (bounds['down'] < value):
bounds['down'] = value
for value in values['up']:
if (bounds['down'] < value):
bounds['down'] = value
bounds['up'] = bounds['down']
down = False
for type in types:
bound = [values[type][0], values[type][0]]
for value in values[type]:
if (value < bound[0]):
bound[0] = value
elif (value > bound[1]):
bound[1] = value
if ((bound[0] == 0.0) and (bound[0] == 0.0)):
norm = [maxOne[0] / len(values[type]), maxOne[1] / 1.5]
else:
norm = [maxOne[0] / len(values[type]), maxOne[1] / (1.5*(bound[1] - bound[0]))]
norm = [maxOne[0] / len(values[type]), maxOne[1] / (1.5 * bounds[type])]
pen.setColor(QColor(colors[type]))
if (down):
shift = (types.index(type) - 1) * maxOne[0]
@ -59,9 +58,9 @@ class Tooltip():
shift = types.index(type) * maxOne[0]
for i in range(len(values[type])-1):
x1 = i * norm[0] + shift
y1 = -(values[type][i] - bound[0]) * norm[1]
y1 = -values[type][i] * norm[1]
x2 = (i + 1) * norm[0] + shift
y2 = -(values[type][i+1] - bound[0]) * norm[1]
y2 = -values[type][i+1] * norm[1]
widget.addLine(x1, y1, x2, y2, pen)
if (type == 'down'):
down = True