# -*- coding: utf-8 -*- # Copyright 2013 Evgeniy Alekseev # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from PyQt4.QtCore import * from PyQt4.QtGui import * from PyKDE4.plasma import Plasma import config import ptmnotify class NewPlasmaLabel(Plasma.Label): """new Label with defined clicked() event""" def __init__(self, applet, parent): """class definition""" Plasma.Label.__init__(self, applet) self.parent = parent self.notify = ptmnotify.PTMNotify(self) def mousePressEvent(self, event): """mouse click event""" if (event.button() == Qt.LeftButton): self.notify.init() class Reinit(): def __init__(self, parent): """class definition""" self.parent = parent def reinit(self, confAccept=False): """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 = "

$LINE

" 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", 2))') else: exec ('self.parent.' + label + 'Bool = int(settings.get("' + label + 'Bool", 0))') # labels for order in self.parent.label_order: if (order == "1"): if (self.parent.cpuBool > 0): self.parent.cpuFormat = str(settings.get('cpuFormat', '[cpu: $cpu%]')) if (self.parent.cpuFormat.split('$ccpu')[0] != self.parent.cpuFormat): self.parent.label_cpu = NewPlasmaLabel(self.parent.applet, self.parent) 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_cpu.setText(text) self.parent.layout.addItem(self.parent.label_cpu) 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 = NewPlasmaLabel(self.parent.applet, self.parent) 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 > 0): self.parent.tempdev = str(settings.get('temp_device', '