mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-15 06:45:48 +00:00
prepare to release 1.7.0
Commit before merging
This commit is contained in:
@ -80,6 +80,12 @@ class ConfigDefinition:
|
||||
settings.set('player_name', self.parent.player_name)
|
||||
self.parent.custom_command = str(self.configpage.ui.lineEdit_customCommand.text())
|
||||
settings.set('custom_command', self.parent.custom_command)
|
||||
|
||||
self.parent.tooltipNum = self.configpage.ui.spinBox_tooltipNum.value()
|
||||
settings.set('tooltip_num', self.parent.tooltipNum)
|
||||
for label in ['cpu', 'cpuclock', 'mem', 'swap', 'down', 'up']:
|
||||
exec ('self.parent.tooltipColors["' + label + '"] = str(self.configpage.kcolorcombo_' + label + '.color().name())')
|
||||
exec ('settings.set("' + label + '_color", self.parent.tooltipColors["' + label + '"])')
|
||||
|
||||
# disconnecting from source and clear layout
|
||||
if (self.parent.uptimeBool > 0):
|
||||
@ -249,6 +255,14 @@ class ConfigDefinition:
|
||||
self.configpage.ui.comboBox_playerSelect.setCurrentIndex(settings.get('player_name', 0).toInt()[0])
|
||||
self.configpage.ui.lineEdit_customCommand.setText(str(settings.get('custom_command', 'wget -qO- http://ifconfig.me/ip')))
|
||||
|
||||
self.configpage.ui.spinBox_tooltipNum.setValue(settings.get('tooltip_num', 100).toInt()[0])
|
||||
self.configpage.ui.kcolorcombo_cpu.setColor(QColor(str(settings.get('cpu_color', '#ff0000'))))
|
||||
self.configpage.ui.kcolorcombo_cpuclock.setColor(QColor(str(settings.get('cpuclock_color', '#00ff00'))))
|
||||
self.configpage.ui.kcolorcombo_mem.setColor(QColor(str(settings.get('mem_color', '#0000ff'))))
|
||||
self.configpage.ui.kcolorcombo_swap.setColor(QColor(str(settings.get('swap_color', '#ffff00'))))
|
||||
self.configpage.ui.kcolorcombo_down.setColor(QColor(str(settings.get('down_color', '#00ffff'))))
|
||||
self.configpage.ui.kcolorcombo_up.setColor(QColor(str(settings.get('up_color', '#ff00ff'))))
|
||||
|
||||
for label in self.parent.dict_orders.keys():
|
||||
exec ('bool = self.parent.' + self.parent.dict_orders[label] + 'Bool')
|
||||
self.configpage.checkboxes[self.parent.dict_orders[label]].setCheckState(bool)
|
||||
|
@ -115,21 +115,29 @@ class DataEngine:
|
||||
elif (sourceName == "cpu/system/TotalLoad"):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
self.parent.cpuCore[-1] = "%5s" % (value)
|
||||
if (self.parent.cpuBool == 2):
|
||||
self.parent.tooltipAgent.addValue('cpu', float(value), self.parent.tooltipNum)
|
||||
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "TotalLoad")):
|
||||
value = str(round(float(data[QString(u'value')]), 1))
|
||||
self.parent.cpuCore[int(str(sourceName)[7])] = "%5s" % (value)
|
||||
elif (sourceName == "cpu/system/AverageClock"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
self.parent.cpuClockCore[-1] = "%4s" % (value)
|
||||
if (self.parent.cpuclockBool == 2):
|
||||
self.parent.tooltipAgent.addValue('cpuclock', float(value), self.parent.tooltipNum)
|
||||
elif ((str(sourceName)[:7] == "cpu/cpu") and (str(sourceName).split('/')[2] == "clock")):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
self.parent.cpuClockCore[int(str(sourceName)[7])] = "%4s" % (value)
|
||||
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/transmitter/data"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
self.parent.netSpeed["up"] = "%4s" % (value)
|
||||
if (self.parent.netBool == 2):
|
||||
self.parent.tooltipAgent.addValue('up', float(value), self.parent.tooltipNum)
|
||||
elif (sourceName == "network/interfaces/"+self.parent.netdev+"/receiver/data"):
|
||||
value = str(data[QString(u'value')]).split('.')[0]
|
||||
self.parent.netSpeed["down"] = "%4s" % (value)
|
||||
if (self.parent.netBool == 2):
|
||||
self.parent.tooltipAgent.addValue('down', float(value), self.parent.tooltipNum)
|
||||
# update network device
|
||||
self.parent.updateNetdev = self.parent.updateNetdev + 1
|
||||
if (self.parent.updateNetdev == 100):
|
||||
@ -166,6 +174,8 @@ class DataEngine:
|
||||
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')])
|
||||
elif (sourceName == "mem/swap/used"):
|
||||
@ -180,6 +190,8 @@ class DataEngine:
|
||||
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"):
|
||||
value = str(data[QString(u'GPU')])
|
||||
gpuText = "%4s" % (value)
|
||||
|
@ -30,6 +30,7 @@ import configdef
|
||||
import configwindow
|
||||
import dataengine
|
||||
import reinit
|
||||
import tooltip
|
||||
from util import *
|
||||
|
||||
|
||||
@ -43,16 +44,17 @@ class pyTextWidget(plasmascript.Applet):
|
||||
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.tooltipAgent = tooltip.Tooltip(self)
|
||||
|
||||
self.timer = QTimer()
|
||||
QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel)
|
||||
|
||||
self.setupVar()
|
||||
self.initTooltip()
|
||||
self.reinit.reinit(confAccept=False)
|
||||
|
||||
self.setHasConfigurationInterface(True)
|
||||
@ -84,8 +86,22 @@ class pyTextWidget(plasmascript.Applet):
|
||||
self.tooltip.setMainText("PyTextMonitor")
|
||||
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)
|
||||
# show tooltip
|
||||
#Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
|
||||
Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
|
||||
|
||||
|
||||
def updateTooltip(self):
|
||||
"""function to update tooltip"""
|
||||
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.tooltip.setImage(QPixmap.grabWidget(self.tooltip_view))
|
||||
Plasma.ToolTipManager.self().setContent(self.applet, self.tooltip)
|
||||
|
||||
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
@ -124,6 +140,11 @@ class pyTextWidget(plasmascript.Applet):
|
||||
self.mount = {}
|
||||
self.hddNames = []
|
||||
self.hdd = {}
|
||||
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]}
|
||||
|
||||
# create dictionaries
|
||||
self.dict_orders = {'6':'bat', '1':'cpu', '7':'cpuclock', 'f':'custom', '9':'gpu',
|
||||
@ -176,6 +197,7 @@ class pyTextWidget(plasmascript.Applet):
|
||||
self.swapText()
|
||||
if (self.tempBool > 0):
|
||||
self.tempText()
|
||||
self.updateTooltip()
|
||||
|
||||
|
||||
def batText(self):
|
||||
|
@ -85,6 +85,15 @@ class Reinit():
|
||||
self.parent.player_name = settings.get('player_name', 0).toInt()[0]
|
||||
self.parent.custom_command = str(settings.get('custom_command', 'wget -qO- http://ifconfig.me/ip'))
|
||||
|
||||
self.parent.tooltipNum = settings.get('tooltip_num', 100).toInt()[0]
|
||||
self.parent.tooltipColors['cpu'] = str(settings.get('cpu_color', '#ff0000'))
|
||||
self.parent.tooltipColors['cpuclock'] = str(settings.get('cpuclock_color', '#00ff00'))
|
||||
self.parent.tooltipColors['mem'] = str(settings.get('mem_color', '#0000ff'))
|
||||
self.parent.tooltipColors['swap'] = str(settings.get('swap_color', '#ffff00'))
|
||||
self.parent.tooltipColors['down'] = str(settings.get('down_color', '#00ffff'))
|
||||
self.parent.tooltipColors['up'] = str(settings.get('up_color', '#ff00ff'))
|
||||
|
||||
self.parent.tooltipReq = []
|
||||
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')):
|
||||
@ -102,6 +111,8 @@ class Reinit():
|
||||
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)
|
||||
if (self.parent.cpuBool == 2):
|
||||
self.parent.tooltipReq.append('cpu')
|
||||
elif (order == "2"):
|
||||
if (self.parent.tempBool > 0):
|
||||
self.parent.tempFormat = str(settings.get('tempFormat', '[temp: $temp0°C]'))
|
||||
@ -125,6 +136,8 @@ class Reinit():
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_mem.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_mem)
|
||||
if (self.parent.memBool == 2):
|
||||
self.parent.tooltipReq.append('mem')
|
||||
elif (order == "4"):
|
||||
if (self.parent.swapBool > 0):
|
||||
self.parent.swapFormat = str(settings.get('swapFormat', '[swap: $swap%]'))
|
||||
@ -139,6 +152,8 @@ class Reinit():
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_swap.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_swap)
|
||||
if (self.parent.swapBool == 2):
|
||||
self.parent.tooltipReq.append('swap')
|
||||
elif (order == "5"):
|
||||
if (self.parent.netBool > 0):
|
||||
self.parent.netNonFormat = str(settings.get('netNonFormat', '[net: $down/$upKB/s]'))
|
||||
@ -155,6 +170,9 @@ class Reinit():
|
||||
text = self.parent.formatLine.split('$LINE')[0] + line + self.parent.formatLine.split('$LINE')[1]
|
||||
self.parent.label_net.setText(text)
|
||||
self.parent.layout.addItem(self.parent.label_net)
|
||||
if (self.parent.netBool == 2):
|
||||
self.parent.tooltipReq.append('down')
|
||||
self.parent.tooltipReq.append('up')
|
||||
elif (order == "6"):
|
||||
if (self.parent.batBool > 0):
|
||||
self.parent.batFormat = str(settings.get('batFormat', '[bat: $bat%$ac]'))
|
||||
@ -171,6 +189,8 @@ class Reinit():
|
||||
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)
|
||||
if (self.parent.cpuclockBool == 2):
|
||||
self.parent.tooltipReq.append('cpuclock')
|
||||
elif (order == "8"):
|
||||
if (self.parent.uptimeBool > 0):
|
||||
self.parent.uptimeFormat = str(settings.get('uptimeFormat', '[uptime: $uptime]'))
|
||||
|
65
sources/ptm/contents/code/tooltip.py
Normal file
65
sources/ptm/contents/code/tooltip.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################################################################
|
||||
# This file is part of pytextmonitor #
|
||||
# #
|
||||
# pytextmonitor is free software: you can redistribute it and/or #
|
||||
# modify it under the terms of the GNU General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# pytextmonitor is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with pytextmonitor. If not, see http://www.gnu.org/licenses/ #
|
||||
############################################################################
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
|
||||
|
||||
class Tooltip():
|
||||
def __init__(self, parent):
|
||||
"""class definition"""
|
||||
self.parent = parent
|
||||
|
||||
|
||||
def addValue(self, type, value=0.0, tooltipNum=100):
|
||||
"""function to add value to list"""
|
||||
if (len(self.parent.tooltipValues[type]) > tooltipNum):
|
||||
self.parent.tooltipValues[type] = self.parent.tooltipValues[type][1:]
|
||||
self.parent.tooltipValues[type].append(value)
|
||||
|
||||
|
||||
def createGraphic(self, types, colors, values, widget):
|
||||
"""function to create graph"""
|
||||
widget.clear()
|
||||
maxOne = [100.0, 100.0]
|
||||
pen = QPen()
|
||||
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
|
||||
norm = [maxOne[0] / len(values[type]), maxOne[1] / (1.5*(bound[1] - bound[0]))]
|
||||
pen.setColor(QColor(colors[type]))
|
||||
if (down):
|
||||
shift = (types.index(type) - 1) * maxOne[0]
|
||||
else:
|
||||
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]
|
||||
x2 = (i + 1) * norm[0] + shift
|
||||
y2 = -(values[type][i+1] - bound[0]) * norm[1]
|
||||
widget.addLine(x1, y1, x2, y2, pen)
|
||||
if (type == 'down'):
|
||||
down = True
|
||||
|
Reference in New Issue
Block a user