diff --git a/sources/ptm/contents/code/dataengine.py b/sources/ptm/contents/code/dataengine.py index 9abf108..c258f29 100644 --- a/sources/ptm/contents/code/dataengine.py +++ b/sources/ptm/contents/code/dataengine.py @@ -91,22 +91,22 @@ class DataEngine: updatedData['name'] = "cpu" updatedData['type'] = -1 value = round(data[QString(u'value')].toFloat()[0], 1) - updatedData['value'] = "%5.1f" % (value) + updatedData['value'] = value elif ((sourceName[:7] == "cpu/cpu") and (sourceName.split('/')[2] == "TotalLoad")): updatedData['name'] = "cpu" updatedData['type'] = int(sourceName[7]) value = round(data[QString(u'value')].toFloat()[0], 1) - updatedData['value'] = "%5.1f" % (value) + updatedData['value'] = value elif (sourceName == "cpu/system/AverageClock"): updatedData['name'] = "cpuclock" updatedData['type'] = -1 value = round(data[QString(u'value')].toFloat()[0], 0) - updatedData['value'] = "%4.0f" % (value) + updatedData['value'] = value elif ((sourceName[:7] == "cpu/cpu") and (sourceName.split('/')[2] == "clock")): updatedData['name'] = "cpuclock" updatedData['type'] = int(sourceName[7]) value = round(data[QString(u'value')].toFloat()[0], 0) - updatedData['value'] = "%4.0f" % (value) + updatedData['value'] = value elif (sourceName == "custom"): updatedData['name'] = "custom" value = str(data[QString(u'custom')].toUtf8()).decode("utf-8") @@ -149,7 +149,7 @@ class DataEngine: updatedData['name'] = "net" updatedData['type'] = "down" value = round(data[QString(u'value')].toFloat()[0], 0) - updatedData['value'] = "%4.0f" % (value) + updatedData['value'] = value # update network device self.updateNetdev = self.updateNetdev + 1 if (self.updateNetdev == 100): @@ -164,7 +164,7 @@ class DataEngine: updatedData['name'] = "net" updatedData['type'] = "up" value = round(data[QString(u'value')].toFloat()[0], 0) - updatedData['value'] = "%4.0f" % (value) + updatedData['value'] = value elif (sourceName == "player"): updatedData['name'] = "player" updatedData['value'] = {} diff --git a/sources/ptm/contents/code/main.py b/sources/ptm/contents/code/main.py index de4841d..51c656e 100644 --- a/sources/ptm/contents/code/main.py +++ b/sources/ptm/contents/code/main.py @@ -107,23 +107,19 @@ class pyTextWidget(plasmascript.Applet): self.tooltip.setSubText('') Plasma.ToolTipManager.self().registerWidget(self.applet) # graphical tooltip - self.tooltip_pixmap = QPixmap() - self.tooltip_scene = QGraphicsScene() - self.tooltip_view = QGraphicsView(self.tooltip_scene) - self.tooltip_view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.tooltip_view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.tooltipScene = QGraphicsScene() + self.tooltipView = QGraphicsView(self.tooltipScene) + self.tooltipView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.tooltipView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # show tooltip Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip) 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.tooltipBound, self.tooltipValues, self.tooltip_scene) - self.tooltip.setImage(QPixmap.grabWidget(self.tooltip_view)) + self.tooltipView.resize(100.0*(len(self.ptm['vars']['tooltip']['required']) - self.ptm['vars']['tooltip']['required'].count('up')), 100.0) + self.tooltipAgent.createGraphic(self.ptm['vars']['tooltip'], self.ptm['tooltip'], self.tooltipScene) + self.tooltip.setImage(QPixmap.grabWidget(self.tooltipView)) Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip) @@ -183,18 +179,18 @@ class pyTextWidget(plasmascript.Applet): 'swap':[0, 0], 'down':[0, 0], 'up':[0, 0]} # values self.ptm['values'] = {} - self.ptm['values']['cpu'] = {-1:" 0.0"} - self.ptm['values']['cpuclock'] = {-1:" 0"} + self.ptm['values']['cpu'] = {-1:0.0} + self.ptm['values']['cpuclock'] = {-1:0.0} numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo")) for i in range(numCores): - self.ptm['values']['cpu'][i] = " 0.0" - self.ptm['values']['cpuclock'][i] = " 0" + self.ptm['values']['cpu'][i] = 0.0 + self.ptm['values']['cpuclock'][i] = 0.0 self.ptm['values']['hdd'] = {} self.ptm['values']['hddtemp'] = {} - self.ptm['values']['mem'] = {'app':0, 'used':0, 'free':1} - self.ptm['values']['net'] = {"up":" 0", "down":" 0"} + self.ptm['values']['mem'] = {'app':0.0, 'used':0.0, 'free':1.0} + self.ptm['values']['net'] = {"up":0.0, "down":0.0} self.ptm['values']['player'] = {} - self.ptm['values']['swap'] = {'used':0, 'free':1} + self.ptm['values']['swap'] = {'used':0.0, 'free':1.0} self.ptm['values']['temp'] = {} # variables self.ptm['vars'] = {} @@ -274,9 +270,11 @@ class pyTextWidget(plasmascript.Applet): line = self.ptm['vars']['formats']['cpu'] for core in self.ptm['values']['cpu'].keys(): if ((core > -1) and (line.split('$cpu' + str(core))[0] != line)): - line = line.split('$cpu' + str(core))[0] + self.ptm['values']['cpu'][core] + line.split('$cpu' + str(core))[1] + value = "%5.1f" % (self.ptm['values']['cpu'][core]) + line = line.split('$cpu' + str(core))[0] + value + line.split('$cpu' + str(core))[1] if (line.split('$cpu')[0] != line): - line = line.split('$cpu')[0] + self.ptm['values']['cpu'][-1] + line.split('$cpu')[1] + value = "%5.1f" % (self.ptm['values']['cpu'][-1]) + line = line.split('$cpu')[0] + value + line.split('$cpu')[1] text = self.ptm['vars']['app']['format'].split('$LINE')[0] + line + self.ptm['vars']['app']['format'].split('$LINE')[1] self.setText("cpu", text) @@ -286,9 +284,11 @@ class pyTextWidget(plasmascript.Applet): line = self.ptm['vars']['formats']['cpuclock'] for core in self.ptm['values']['cpuclock'].keys(): if ((core > -1) and (line.split('$cpucl' + str(core))[0] != line)): - line = line.split('$cpucl' + str(core))[0] + self.ptm['values']['cpuclock'][core] + line.split('$cpucl' + str(core))[1] + value = "%4.0f" % (self.ptm['values']['cpuclock'][core]) + line = line.split('$cpucl' + str(core))[0] + value + line.split('$cpucl' + str(core))[1] if (line.split('$cpucl')[0] != line): - line = line.split('$cpucl')[0] + self.ptm['values']['cpuclock'][-1] + line.split('$cpucl')[1] + value = "%4.0f" % (self.ptm['values']['cpuclock'][-1]) + line = line.split('$cpucl')[0] + value + line.split('$cpucl')[1] text = self.ptm['vars']['app']['format'].split('$LINE')[0] + line + self.ptm['vars']['app']['format'].split('$LINE')[1] self.setText("cpuclock", text) @@ -335,9 +335,11 @@ class pyTextWidget(plasmascript.Applet): if (line.split('$netdev')[0] != 0): line = line.split('$netdev')[0] + self.ptm['names']['net'] + line.split('$netdev')[1] if (line.split('$down')[0] != line): - line = line.split('$down')[0] + self.ptm['values']['net']['down'] + line.split('$down')[1] + value = "%4.0f" %(self.ptm['values']['net']['down']) + line = line.split('$down')[0] + value + line.split('$down')[1] if (line.split('$up')[0] != line): - line = line.split('$up')[0] + self.ptm['values']['net']['up'] + line.split('$up')[1] + value = "%4.0f" %(self.ptm['values']['net']['up']) + line = line.split('$up')[0] + value + line.split('$up')[1] text = self.ptm['vars']['app']['format'].split('$LINE')[0] + line + self.ptm['vars']['app']['format'].split('$LINE')[1] self.setText("net", text) diff --git a/sources/ptm/contents/code/tooltip.py b/sources/ptm/contents/code/tooltip.py index 47d7fb1..1f654f6 100644 --- a/sources/ptm/contents/code/tooltip.py +++ b/sources/ptm/contents/code/tooltip.py @@ -28,11 +28,15 @@ class Tooltip(): self.parent = parent - def createGraphic(self, types, colors, bounds, values, widget): + def createGraphic(self, ptmVars, ptmTooltip, widget): """function to create graph""" widget.clear() - maxOne = [100.0, 100.0] pen = QPen() + bounds = ptmTooltip['bounds'] + colors = ptmVars['colors'] + types = ptmVars['required'] + values = ptmTooltip['values'] + maxOne = [100.0, 100.0] bounds['down'] = 1.0 for value in values['down']: if (bounds['down'] < value):