diff --git a/sources/ext-sysmon/extsysmon.cpp b/sources/ext-sysmon/extsysmon.cpp index 42944b4..97f5e62 100644 --- a/sources/ext-sysmon/extsysmon.cpp +++ b/sources/ext-sysmon/extsysmon.cpp @@ -36,7 +36,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) // debug QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString debugEnv = environment.value(QString("PTM_DE_DEBUG"), QString("no")); + QString debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); if (debugEnv == QString("yes")) debug = true; else @@ -49,47 +49,47 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) QString ExtendedSysMon::getAllHdd() { - if (debug) qDebug() << "[getAllHdd]"; + if (debug) qDebug() << "[DE]" << "[getAllHdd]"; QProcess command; QStringList devices; QString cmd = QString("find /dev -name [hms]d[a-z]"); QString qoutput = QString(""); - if (debug) qDebug() << "[getAllHdd]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Run cmd" << cmd; command.start(cmd); command.waitForFinished(-1); - if (debug) qDebug() << "[getAllHdd]" << ":" << "Cmd returns" << command.exitCode(); + if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Cmd returns" << command.exitCode(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); if (qoutput.toLower().contains("nvidia")) gpu = QString("nvidia"); else if (qoutput.toLower().contains("radeon")) gpu = QString("ati"); - if (debug) qDebug() << "[getAutoGpu]" << ":" << "Device" << gpu; + if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Device" << gpu; return gpu; } QStringList ExtendedSysMon::sources() const { - if (debug) qDebug() << "[sources]"; + if (debug) qDebug() << "[DE]" << "[sources]"; QStringList source; source.append(QString("custom")); source.append(QString("gpu")); @@ -98,14 +98,14 @@ QStringList ExtendedSysMon::sources() const source.append(QString("pkg")); source.append(QString("player")); source.append(QString("ps")); - if (debug) qDebug() << "[sources]" << ":" << "Sources" << source; + if (debug) qDebug() << "[DE]" << "[sources]" << ":" << "Sources" << source; return source; } void ExtendedSysMon::readConfiguration() { - if (debug) qDebug() << "[readConfiguration]"; + if (debug) qDebug() << "[DE]" << "[readConfiguration]"; // pre-setup QMap rawConfig; rawConfig[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip"); @@ -119,7 +119,7 @@ void ExtendedSysMon::readConfiguration() rawConfig[QString("PLAYER")] = QString("amarok"); QString fileName = KGlobal::dirs()->findResource("config", "extsysmon.conf"); - if (debug) qDebug() << "[readConfiguration]" << ":" << "Configuration file" << fileName; + if (debug) qDebug() << "[DE]" << "[readConfiguration]" << ":" << "Configuration file" << fileName; QFile confFile(fileName); bool ok = confFile.open(QIODevice::ReadOnly); if (!ok) { @@ -148,7 +148,7 @@ void ExtendedSysMon::readConfiguration() QMap ExtendedSysMon::updateConfiguration(const QMap rawConfig) { - if (debug) qDebug() << "[updateConfiguration]"; + if (debug) qDebug() << "[DE]" << "[updateConfiguration]"; QMap config; QString key, value; // remove spaces and copy source map @@ -200,7 +200,7 @@ QMap ExtendedSysMon::updateConfiguration(const QMaptoUnicode(command.readAllStandardOutput()).trimmed(); - if (debug) qDebug() << "[getCustomCmd]" << ":" << "Return" << qoutput; + if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Return" << qoutput; return qoutput; } float ExtendedSysMon::getGpu(const QString device) { - if (debug) qDebug() << "[getGpu]"; - if (debug) qDebug() << "[getGpu]" << ":" << "Run function with device" << device; + if (debug) qDebug() << "[DE]" << "[getGpu]"; + if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run function with device" << device; float gpu = 0.0; if ((device != QString("nvidia")) && (device != QString("ati"))) return gpu; @@ -234,10 +234,10 @@ float ExtendedSysMon::getGpu(const QString device) if (device == QString("nvidia")) { QString cmd = QString("nvidia-smi -q -d UTILIZATION"); - if (debug) qDebug() << "[getGpu]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run cmd" << cmd; command.start(cmd); command.waitForFinished(-1); - if (debug) qDebug() << "[getGpu]" << ":" << "Cmd returns" << command.exitCode(); + if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Cmd returns" << command.exitCode(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2]; temp.remove(QChar(0260)).remove(QChar('C')); hddTemp = temp.toFloat(); } - if (debug) qDebug() << "[getHddTemp]" << ":" << "Return" << hddTemp; + if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Return" << hddTemp; return hddTemp; } @@ -341,9 +341,9 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName, const QString mpdAddress, const QString mpdPort) { - if (debug) qDebug() << "[getPlayerInfo]"; - if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run function with player" << playerName; - if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" << + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]"; + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with player" << playerName; + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" << mpdAddress + QString(":") + mpdPort; QStringList info; // album @@ -363,10 +363,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName, if (playerName == QString("amarok")) { // amarok cmd = QString("qdbus org.kde.amarok /Player GetMetadata"); - if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; command.start(cmd); command.waitForFinished(-1); - if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); + if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Cmd returns" << command.exitCode(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()); for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); int psTotal = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); psStats.append(QString::number(psTotal)); - if (debug) qDebug() << "[getPsStats]" << ":" << "Return" << psStats; + if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Return" << psStats; return psStats; } int ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int pkgNull) { - if (debug) qDebug() << "[getUpgradeInfo]"; - if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run function with cmd" << pkgCommand; - if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run function with number of null lines" << pkgNull; + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]"; + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with cmd" << pkgCommand; + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with number of null lines" << pkgNull; int count = 0; QString cmd = QString("bash -c \"") + pkgCommand + QString("\""); QProcess command; QString qoutput = QString(""); - if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run cmd" << cmd; command.start(cmd); command.waitForFinished(-1); - if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Cmd returns" << command.exitCode(); + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Cmd returns" << command.exitCode(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); count = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); - if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Return" << (count - pkgNull); + if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Return" << (count - pkgNull); return (count - pkgNull); } bool ExtendedSysMon::sourceRequestEvent(const QString &name) { - if (debug) qDebug() << "[sourceRequestEvent]"; - if (debug) qDebug() << "[sourceRequestEvent]" << ":" << "Run function with source name" << name; + if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]"; + if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]" << ":" << "Run function with source name" << name; return updateSourceEvent(name); } bool ExtendedSysMon::updateSourceEvent(const QString &source) { - if (debug) qDebug() << "[updateSourceEvent]"; - if (debug) qDebug() << "[updateSourceEvent]" << ":" << "Run function with source name" << source; + if (debug) qDebug() << "[DE]" << "[updateSourceEvent]"; + if (debug) qDebug() << "[DE]" << "[updateSourceEvent]" << ":" << "Run function with source name" << source; QString key; if (source == QString("custom")) { for (int i=0; i -1)): @@ -61,30 +71,40 @@ class AdvancedWindow(QWidget): def addHddDevice(self): """function to add mount points""" + if self.debug: qDebug("[PTM] [advanced.py] [addHddDevice]") + if self.debug: qDebug("[PTM] [advanced.py] [addHddDevice] : Device '%s'" %(self.ui.comboBox_hddDevice.currentText())) self.ui.listWidget_hddDevice.clearSelection() self.ui.listWidget_hddDevice.addItem(self.ui.comboBox_hddDevice.currentText()) def addHddSpeedDevice(self): """function to add disk device""" + if self.debug: qDebug("[PTM] [advanced.py] [addHddSpeedDevice]") + if self.debug: qDebug("[PTM] [advanced.py] [addHddSpeedDevice] : Device '%s'" %(self.ui.comboBox_hddSpeedDevice.currentText())) self.ui.listWidget_hddSpeedDevice.clearSelection() self.ui.listWidget_hddSpeedDevice.addItem(self.ui.comboBox_hddSpeedDevice.currentText()) def addMount(self): """function to add mount points""" + if self.debug: qDebug("[PTM] [advanced.py] [addMount]") + if self.debug: qDebug("[PTM] [advanced.py] [addMount] : Device '%s'" %(self.ui.comboBox_mount.currentText())) self.ui.listWidget_mount.clearSelection() self.ui.listWidget_mount.addItem(self.ui.comboBox_mount.currentText()) def addTempDevice(self): """function to add temperature device""" + if self.debug: qDebug("[PTM] [advanced.py] [addTempDevice]") + if self.debug: qDebug("[PTM] [advanced.py] [addTempDevice] : Device '%s'" %(self.ui.comboBox_tempDevice.currentText())) self.ui.listWidget_tempDevice.clearSelection() self.ui.listWidget_tempDevice.addItem(self.ui.comboBox_tempDevice.currentText()) def setNetdevEnabled(self): """function to set enabled netdev""" + if self.debug: qDebug("[PTM] [advanced.py] [setNetdevEnabled]") + if self.debug: qDebug("[PTM] [advanced.py] [setNetdevEnabled] : State '%s'" %(self.ui.checkBox_netdev.checkState())) if (self.ui.checkBox_netdev.checkState() == 0): self.ui.comboBox_netdev.setDisabled(True) else: diff --git a/sources/ptm/contents/code/appearance.py b/sources/ptm/contents/code/appearance.py index c3f8aa4..a4e8b9b 100644 --- a/sources/ptm/contents/code/appearance.py +++ b/sources/ptm/contents/code/appearance.py @@ -27,6 +27,14 @@ from PyQt4 import uic class AppearanceWindow(QWidget): def __init__(self, parent): """settings window definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main QWidget.__init__(self) self.ui = uic.loadUi(parent.package().filePath('ui', 'appearance.ui'), self) self.parent = parent diff --git a/sources/ptm/contents/code/configdef.py b/sources/ptm/contents/code/configdef.py index c716e84..077b1e7 100644 --- a/sources/ptm/contents/code/configdef.py +++ b/sources/ptm/contents/code/configdef.py @@ -29,6 +29,14 @@ import config class ConfigDefinition: def __init__(self, parent, configpage, defaults): """class definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main self.parent = parent self.configpage = configpage self.defaults = defaults @@ -36,6 +44,7 @@ class ConfigDefinition: def configAccepted(self): """function to accept settings""" + if self.debug: qDebug("[PTM] [configdef.py] [configAccepted]") settings = config.Config(self.parent) # update local variables @@ -128,6 +137,7 @@ class ConfigDefinition: def createConfigurationInterface(self, parent): """function to setup configuration window""" + if self.debug: qDebug("[PTM] [configdef.py] [createConfigurationInterface]") settings = config.Config(self.parent) font = QFont(str(settings.get('font_family', 'Terminus')), settings.get('font_size', 12).toInt()[0], 400, False) diff --git a/sources/ptm/contents/code/dataengine.py b/sources/ptm/contents/code/dataengine.py index 925ad50..1acd04f 100644 --- a/sources/ptm/contents/code/dataengine.py +++ b/sources/ptm/contents/code/dataengine.py @@ -32,11 +32,23 @@ timeLetters = ['dddd', 'ddd', 'dd', 'd', \ class DataEngine: def __init__(self, parent): """class definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main self.parent = parent def connectToEngine(self, bools=None, dataEngines=None, interval=1000, names=None): """function to initializate engine""" + if self.debug: qDebug("[PTM] [dataengine.py] [connectToEngine]") + if self.debug: qDebug("[PTM] [dataengine.py] [connectToEngine] : Run function with bools '%s'" %(bools)) + if self.debug: qDebug("[PTM] [dataengine.py] [connectToEngine] : Run function with dataengines '%s'" %(dataEngines)) + if self.debug: qDebug("[PTM] [dataengine.py] [connectToEngine] : Run function with names '%s'" %(names)) if (bools['cpu'] > 0): dataEngines['system'].connectSource("cpu/system/TotalLoad", self.parent, interval) for core in range(8): @@ -90,6 +102,10 @@ class DataEngine: def dataUpdated(self, sourceName, data, ptm): """function to update data""" + if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated]") + if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated] : Run function with source '%s'" %(sourceName)) + if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated] : Run function with data '%s'" %(data)) + if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated] : Run function with settings '%s'" %(ptm)) adv = ptm['vars']['adv'] systemDataEngine = ptm['dataengine']['system'] formats = ptm['vars']['formats'] @@ -271,11 +287,16 @@ class DataEngine: updatedData['value'] = "%s%i%s" % (updatedData['value'].split('$m')[0], minutes, updatedData['value'].split('$m')[1]) except: pass + if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated] : Returns '%s'" %(updatedData)) return updatedData def disconnectFromSource(self, dataEngines=None, keys=None, name=None): """function to disconnect from sources""" + if self.debug: qDebug("[PTM] [dataengine.py] [disconnectFromSource]") + if self.debug: qDebug("[PTM] [dataengine.py] [disconnectFromSource] : Run function with dataengines '%s'" %(dataEngines)) + if self.debug: qDebug("[PTM] [dataengine.py] [disconnectFromSource] : Run function with keys '%s'" %(keys)) + if self.debug: qDebug("[PTM] [dataengine.py] [disconnectFromSource] : Run function with name '%s'" %(name)) if (name == "bat"): pass elif (name == "cpu"): diff --git a/sources/ptm/contents/code/deconfig.py b/sources/ptm/contents/code/deconfig.py index b912afd..5c6d3d3 100644 --- a/sources/ptm/contents/code/deconfig.py +++ b/sources/ptm/contents/code/deconfig.py @@ -27,6 +27,14 @@ from PyQt4 import uic class DEConfigWindow(QWidget): def __init__(self, parent): """settings window definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main QWidget.__init__(self) self.ui = uic.loadUi(parent.package().filePath('ui', 'deconfig.ui'), self) self.parent = parent @@ -41,6 +49,8 @@ class DEConfigWindow(QWidget): def keyPressEvent(self, event): """delete events""" + if self.debug: qDebug("[PTM] [deconfig.py] [keyPressEvent]") + if self.debug: qDebug("[PTM] [deconfig.py] [keyPressEvent] : Run function with event '%s'" %(event.key())) if (event.key() == Qt.Key_Delete): if (self.ui.listWidget_customCommand.hasFocus() and (self.ui.listWidget_customCommand.currentRow() > -1)): @@ -52,12 +62,16 @@ class DEConfigWindow(QWidget): def addCustomCommand(self): """function to add custom command""" + if self.debug: qDebug("[PTM] [deconfig.py] [addCustomCommand]") + if self.debug: qDebug("[PTM] [deconfig.py] [addCustomCommand] : Cmd '%s'" %(self.ui.lineEdit_customCommand.text())) self.ui.listWidget_customCommand.clearSelection() self.ui.listWidget_customCommand.addItem(self.ui.lineEdit_customCommand.text()) def addPkgCommand(self): """function to add package manager command""" + if self.debug: qDebug("[PTM] [deconfig.py] [addPkgCommand]") + if self.debug: qDebug("[PTM] [deconfig.py] [addPkgCommand] : Cmd '%s'" %(self.ui.comboBox_pkgCommand.currentText())) self.ui.listWidget_pkgCommand.clearSelection() self.ui.listWidget_pkgCommand.addItem(self.ui.comboBox_pkgCommand.currentText() +\ QString(":") + QString.number(self.ui.spinBox_pkgCommandNum.value())) @@ -65,6 +79,7 @@ class DEConfigWindow(QWidget): def updatePkgNullValue(self): """function to set default values to PKGNULL spinbox""" + if self.debug: qDebug("[PTM] [deconfig.py] [updatePkgNullValue]") if (self.ui.comboBox_pkgCommand.currentText().contains(QString("pacman -Qu"))): self.ui.spinBox_pkgCommandNum.setValue(0) elif (self.ui.comboBox_pkgCommand.currentText().contains(QString("apt-show-versions -u -b"))): diff --git a/sources/ptm/contents/code/main.py b/sources/ptm/contents/code/main.py index b78dfe3..27f21b9 100644 --- a/sources/ptm/contents/code/main.py +++ b/sources/ptm/contents/code/main.py @@ -72,12 +72,21 @@ class CustomPlasmaLabel(Plasma.Label): class pyTextWidget(plasmascript.Applet): def __init__(self, parent, args=None): """widget definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main plasmascript.Applet.__init__(self, parent) # initialization def init(self): """function to initializate widget""" + if self.debug: qDebug("[PTM] [main.py] [init]") self.setupVar() self.dataengine = dataengine.DataEngine(self) @@ -85,7 +94,7 @@ class pyTextWidget(plasmascript.Applet): self.tooltipAgent = tooltip.Tooltip(self) self.timer = QTimer() - QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel) + QObject.connect(self.timer, SIGNAL("timeout()"), self.startPolling) self.initTooltip() self.reInit() @@ -103,6 +112,7 @@ class pyTextWidget(plasmascript.Applet): # context menu def createActions(self): """function to create actions""" + if self.debug: qDebug("[PTM] [main.py] [createActions]") self.ptmActions = {} self.ptmActions['ksysguard'] = QAction(i18n("Run ksysguard"), self) QObject.connect(self.ptmActions['ksysguard'], SIGNAL("triggered(bool)"), self.runKsysguard) @@ -120,6 +130,7 @@ class pyTextWidget(plasmascript.Applet): def contextualActions(self): """function to create context menu""" + if self.debug: qDebug("[PTM] [main.py] [contextualActions]") contextMenu = [] contextMenu.append(self.ptmActions['ksysguard']) contextMenu.append(self.ptmActions['readme']) @@ -129,11 +140,14 @@ class pyTextWidget(plasmascript.Applet): def runKsysguard(self, event): """function to run ksysguard""" + if self.debug: qDebug("[PTM] [main.py] [runKsysguard]") + if self.debug: qDebug("[PTM] [main.py] [runKsysguard] : Run cmd " + "'ksysguard &'") os.system("ksysguard &") def showReadme(self): """function to show readme file""" + if self.debug: qDebug("[PTM] [main.py] [showReadme]") kdehome = unicode(KGlobal.dirs().localkdedir()) if (os.path.exists("/usr/share/pytextmonitor/")): dirPath = "/usr/share/pytextmonitor/" @@ -152,18 +166,22 @@ class pyTextWidget(plasmascript.Applet): filePath = dirPath + "en.html" else: return + if self.debug: qDebug("[PTM] [main.py] [showReadme] : Run cmd " + "'kioclient exec " + str(filePath) + " &'") os.system("kioclient exec " + str(filePath) + " &") # internal functions def addDiskDevice(self, sourceName): + if self.debug: qDebug("[PTM] [main.py] [addDiskDevice]") diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)") if (diskRegexp.indexIn(sourceName) > -1): + if self.debug: qDebug("[PTM] [main.py] [addDiskDevice] : Add device '%s'" %(str(sourceName).split('/')[1])) self.ptm['defaults']['disk'].append('/'.join(str(sourceName).split('/')[0:2])) def createConfigurationInterface(self, parent): """function to setup configuration window""" + if self.debug: qDebug("[PTM] [main.py] [createConfigurationInterface]") configpage = {} configpage['advanced'] = advanced.AdvancedWindow(self) configpage['appearance'] = appearance.AppearanceWindow(self) @@ -177,6 +195,7 @@ class pyTextWidget(plasmascript.Applet): def initTooltip(self): """function to create tooltip""" + if self.debug: qDebug("[PTM] [main.py] [initTooltip]") self.tooltip = Plasma.ToolTipContent() self.tooltip.setMainText("PyTextMonitor") self.tooltip.setSubText('') @@ -192,6 +211,8 @@ class pyTextWidget(plasmascript.Applet): def setupVar(self): """function to setup variables""" + if self.debug: qDebug("[PTM] [main.py] [setupVar]") + # variables self.ptm = {} # dataengines self.ptm['dataengine'] = {'ext':None, 'system':None, 'time':None} @@ -246,6 +267,7 @@ class pyTextWidget(plasmascript.Applet): self.ptm['values']['cpu'] = {-1:0.0} self.ptm['values']['cpuclock'] = {-1:0.0} numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo")) + if self.debug: qDebug("[PTM] [main.py] [setupVar] : Number of cores '%s'" %(numCores)) for i in range(numCores): self.ptm['values']['cpu'][i] = 0.0 self.ptm['values']['cpuclock'][i] = 0.0 @@ -270,21 +292,26 @@ class pyTextWidget(plasmascript.Applet): def showConfigurationInterface(self): """function to show configuration window""" + if self.debug: qDebug("[PTM] [main.py] [showConfigurationInterface]") plasmascript.Applet.showConfigurationInterface(self) def startPolling(self): + """function to update""" + if self.debug: qDebug("[PTM] [main.py] [startPolling]") try: - self.timer.start() self.updateLabel() self.tooltip.setSubText('') + if self.debug: qDebug("[PTM] [main.py] [startPolling] : Update without errors") except Exception as strerror: self.tooltip.setSubText(str(strerror)) + if self.debug: qDebug("[PTM] [main.py] [startPolling] : There is some errors '%s'" %(str(strerror))) return def updateLabel(self): """function to update label""" + if self.debug: qDebug("[PTM] [main.py] [updateLabel]") if (self.ptm['vars']['bools']['bat'] > 0): self.batText() if (self.ptm['vars']['bools']['cpu'] > 0): @@ -310,11 +337,13 @@ class pyTextWidget(plasmascript.Applet): def updateNetdev(self): """function to update netdev""" + if self.debug: qDebug("[PTM] [main.py] [updateNetdev]") self.ptm['names']['net'] = self.setNetdev() def updateTooltip(self): """function to update tooltip""" + if self.debug: qDebug("[PTM] [main.py] [updateTooltip]") 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)) @@ -326,7 +355,11 @@ class pyTextWidget(plasmascript.Applet): @pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)") def dataUpdated(self, sourceName, data): """function to update label""" + if self.debug: qDebug("[PTM] [main.py] [dataUpdated]") + if self.debug: qDebug("[PTM] [main.py] [dataUpdated] : Run function with source '%s'" %(sourceName)) + if self.debug: qDebug("[PTM] [main.py] [dataUpdated] : Run function with data '%s'" %(data)) updatedData = self.dataengine.dataUpdated(str(sourceName), data, self.ptm) + if self.debug: qDebug("[PTM] [main.py] [dataUpdated] : Received data '%s'" %(updatedData)) if (updatedData['value'] == None): return # update values where is needed @@ -362,6 +395,7 @@ class pyTextWidget(plasmascript.Applet): # update labels def batText(self): """function to set battery text""" + if self.debug: qDebug("[PTM] [main.py] [batText]") line = self.ptm['vars']['formats']['bat'] if (line.split('$bat')[0] != line): try: @@ -388,6 +422,7 @@ class pyTextWidget(plasmascript.Applet): def cpuText(self): """function to set cpu text""" + if self.debug: qDebug("[PTM] [main.py] [cpuText]") line = self.ptm['vars']['formats']['cpu'] keys = self.ptm['values']['cpu'].keys() keys.sort() @@ -405,6 +440,7 @@ class pyTextWidget(plasmascript.Applet): def cpuclockText(self): """function to set cpu clock text""" + if self.debug: qDebug("[PTM] [main.py] [cpuclockText]") line = self.ptm['vars']['formats']['cpuclock'] keys = self.ptm['values']['cpuclock'].keys() keys.sort() @@ -421,6 +457,8 @@ class pyTextWidget(plasmascript.Applet): def diskText(self): + """function to update hdd speed text""" + if self.debug: qDebug("[PTM] [main.py] [diskText]") line = self.ptm['vars']['formats']['disk'] devices = range(len(self.ptm['names']['disk'])) devices.reverse() @@ -437,6 +475,7 @@ class pyTextWidget(plasmascript.Applet): def hddText(self): """function to set hdd text""" + if self.debug: qDebug("[PTM] [main.py] [hddText]") line = self.ptm['vars']['formats']['hdd'] devices = range(len(self.ptm['names']['hdd'])) devices.reverse() @@ -464,6 +503,7 @@ class pyTextWidget(plasmascript.Applet): def hddtempText(self): """function to set hddtemp text""" + if self.debug: qDebug("[PTM] [main.py] [hddtempText]") line = self.ptm['vars']['formats']['hddtemp'] devices = range(len(self.ptm['names']['hddtemp'])) devices.reverse() @@ -478,6 +518,7 @@ class pyTextWidget(plasmascript.Applet): def memText(self): """function to set mem text""" + if self.debug: qDebug("[PTM] [main.py] [memText]") line = self.ptm['vars']['formats']['mem'] if (line.split('$memtotgb')[0] != line): mem = "%4.1f" %((self.ptm['values']['mem']['free'] + self.ptm['values']['mem']['used']) / (1024.0 * 1024.0)) @@ -504,6 +545,7 @@ class pyTextWidget(plasmascript.Applet): def netText(self): """function to set network text""" + if self.debug: qDebug("[PTM] [main.py] [netText]") line = self.ptm['vars']['formats']['net'] if (line.split('$netdev')[0] != 0): line = line.split('$netdev')[0] + self.ptm['names']['net'] + line.split('$netdev')[1] @@ -519,6 +561,7 @@ class pyTextWidget(plasmascript.Applet): def swapText(self): """function to set swap text""" + if self.debug: qDebug("[PTM] [main.py] [swapText]") line = self.ptm['vars']['formats']['swap'] if (line.split('$swaptotgb')[0] != line): mem = "%4.1f" % ((self.ptm['values']['swap']['free'] + self.ptm['values']['swap']['used']) / (1024.0 * 1024.0)) @@ -545,6 +588,7 @@ class pyTextWidget(plasmascript.Applet): def tempText(self): """function to set temperature text""" + if self.debug: qDebug("[PTM] [main.py] [tempText]") line = self.ptm['vars']['formats']['temp'] devices = range(len(self.ptm['names']['temp'])) devices.reverse() @@ -560,6 +604,11 @@ class pyTextWidget(plasmascript.Applet): # external functions def addLabel(self, name=None, text=None, add=True, enablePopup=2): """function to add new label""" + if self.debug: qDebug("[PTM] [main.py] [addLabel]") + if self.debug: qDebug("[PTM] [main.py] [addLabel] : Run function with name '%s'" %(name)) + if self.debug: qDebug("[PTM] [main.py] [addLabel] : Run function with text '%s'" %(text)) + if self.debug: qDebug("[PTM] [main.py] [addLabel] : Run function with add '%s'" %(add)) + if self.debug: qDebug("[PTM] [main.py] [addLabel] : Run function with popup '%s'" %(enablePopup)) if (add): self.ptm['labels'][name] = CustomPlasmaLabel(self.applet, name, enablePopup) self.ptm['layout'].addItem(self.ptm['labels'][name]) @@ -571,6 +620,9 @@ class pyTextWidget(plasmascript.Applet): def applySettings(self, name=None, ptm=None): """function to read settings""" + if self.debug: qDebug("[PTM] [main.py] [applySettings]") + if self.debug: qDebug("[PTM] [main.py] [applySettings] : Run function with name '%s'" %(name)) + if self.debug: qDebug("[PTM] [main.py] [applySettings] : Run function with settings '%s'" %(ptm)) self.ptm[name] = ptm if (name == "names"): for item in ['hddtemp', 'temp']: @@ -588,6 +640,7 @@ class pyTextWidget(plasmascript.Applet): def connectToEngine(self): """function to connect to dataengines""" + if self.debug: qDebug("[PTM] [main.py] [connectToEngine]") self.ptm['dataengine']['ext'] = self.dataEngine("ext-sysmon") self.ptm['dataengine']['system'] = self.dataEngine("systemmonitor") self.ptm['dataengine']['time'] = self.dataEngine("time") @@ -598,6 +651,8 @@ class pyTextWidget(plasmascript.Applet): def createLayout(self, verticalLayout=0): """function to create layout""" + if self.debug: qDebug("[PTM] [main.py] [createLayout]") + if self.debug: qDebug("[PTM] [main.py] [createLayout] : Run function with vertical layout '%s'" %(verticalLayout)) if (verticalLayout == 0): self.ptm['layout'] = QGraphicsLinearLayout(Qt.Horizontal, self.applet) else: @@ -607,6 +662,7 @@ class pyTextWidget(plasmascript.Applet): def disconnectFromSource(self): """function to disconnect from sources""" + if self.debug: qDebug("[PTM] [main.py] [disconnectFromSource]") for label in self.ptm['defaults']['format'].keys(): if (self.ptm['vars']['bools'][label] > 0): self.addLabel(label, None, False) @@ -618,6 +674,7 @@ class pyTextWidget(plasmascript.Applet): def reInit(self): """function to run reinit""" + if self.debug: qDebug("[PTM] [main.py] [reInit]") self.reinit.reinit() self.updateNetdev() self.resize(10, 10) @@ -627,11 +684,13 @@ class pyTextWidget(plasmascript.Applet): self.connectToEngine() self.timer.setInterval(self.ptm['vars']['app']['interval']) + self.timer.start() self.startPolling() def setNetdev(self): """function to set network device""" + if self.debug: qDebug("[PTM] [main.py] [setNetdev]") if (self.ptm['vars']['adv']['netdevBool'] > 0): return self.ptm['vars']['adv']['netdev'] netdev = "lo" @@ -645,16 +704,23 @@ class pyTextWidget(plasmascript.Applet): netdev = str(device) except: pass + if self.debug: qDebug("[PTM] [main.py] [setNetdev] : Returns '%s'" %(netdev)) return netdev def setText(self, name=None, text=None): """function to set text to labels""" + if self.debug: qDebug("[PTM] [main.py] [setText]") + if self.debug: qDebug("[PTM] [main.py] [setText] : Run function with name '%s'" %(name)) + if self.debug: qDebug("[PTM] [main.py] [setText] : Run function with text '%s'" %(text)) self.ptm['labels'][name].setText(text) def textPrepare(self, name=None, text=None): """function to prepare text""" + if self.debug: qDebug("[PTM] [main.py] [textPrepare]") + if self.debug: qDebug("[PTM] [main.py] [textPrepare] : Run function with name '%s'" %(name)) + if self.debug: qDebug("[PTM] [main.py] [textPrepare] : Run function with text '%s'" %(text)) line = self.ptm['vars']['formats'][name] if (name == "custom"): cmds = range(len(text.keys())) @@ -713,6 +779,7 @@ class pyTextWidget(plasmascript.Applet): elif (line.split('$custom')[0] != line): line = line.split('$custom')[0] + text + line.split('$custom')[1] output = self.ptm['vars']['app']['format'][0] + line + self.ptm['vars']['app']['format'][1] + if self.debug: qDebug("[PTM] [main.py] [textPrepare] : Returns '%s'" %(output)) return output diff --git a/sources/ptm/contents/code/ptmnotify.py b/sources/ptm/contents/code/ptmnotify.py index 769d669..2d81fcf 100644 --- a/sources/ptm/contents/code/ptmnotify.py +++ b/sources/ptm/contents/code/ptmnotify.py @@ -17,6 +17,7 @@ # along with pytextmonitor. If not, see http://www.gnu.org/licenses/ # ############################################################################ +from PyQt4.QtCore import * from PyKDE4.kdecore import KComponentData from PyKDE4.kdeui import KNotification import commands @@ -26,16 +27,28 @@ import commands class PTMNotify: def __init__(self, parent): """class definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main def init(self, name=None): """function to init notification""" + if self.debug: qDebug("[PTM] [ptmnotify.py] [init]") + if self.debug: qDebug("[PTM] [ptmnotify.py] [init] : Run function with name '%s'" %(name)) content = self.initText(name) self.createNotify(content) def createNotify(self, content): """function to create notification for label""" + if self.debug: qDebug("[PTM] [ptmnotify.py] [createNotify]") + if self.debug: qDebug("[PTM] [ptmnotify.py] [createNotify] : Run function with content '%s'" %(content)) notification = KNotification(content[0]) notification.setComponentData(KComponentData("plasma_applet_pytextmonitor")) notification.setTitle("PyTextMonitor info ::: " + content[0]); @@ -45,6 +58,8 @@ class PTMNotify: def createText(self, type): """function to create text""" + if self.debug: qDebug("[PTM] [ptmnotify.py] [createText]") + if self.debug: qDebug("[PTM] [ptmnotify.py] [createText] : Run function with type '%s'" %(type)) text = "" if (type == "battery"): try: @@ -187,11 +202,14 @@ class PTMNotify: except: text = "Something wrong" content = [type, text] + if self.debug: qDebug("[PTM] [ptmnotify.py] [createText] : Returns '%s'" %(content)) return content def initText(self, name): """function to send text""" + if self.debug: qDebug("[PTM] [ptmnotify.py] [initText]") + if self.debug: qDebug("[PTM] [ptmnotify.py] [initText] : Run function with name '%s'" %(name)) if (name == "bat"): return self.createText("battery") elif (name == "cpu"): diff --git a/sources/ptm/contents/code/reinit.py b/sources/ptm/contents/code/reinit.py index a65f785..b55f42c 100644 --- a/sources/ptm/contents/code/reinit.py +++ b/sources/ptm/contents/code/reinit.py @@ -26,6 +26,14 @@ import config class Reinit(): def __init__(self, parent, defaults=None): """class definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main self.parent = parent self.defaults = defaults self.labels = defaults['format'].keys() @@ -33,6 +41,7 @@ class Reinit(): def reinit(self): """function to reinitializate widget""" + if self.debug: qDebug("[PTM] [reinit.py] [reinit]") settings = config.Config(self.parent) ptmVars = {} @@ -77,6 +86,7 @@ class Reinit(): ptmNames['hdd'] = str(settings.get('mount', '/')).split('@@') ptmNames['hddtemp'] = str(settings.get('hdd', '/dev/sda')).split('@@') ptmNames['temp'] = str(settings.get('temp_device', '')).split('@@') + if self.debug: qDebug("[PTM] [reinit.py] [reinit] : Returns names '%s'" %(ptmNames)) self.parent.applySettings('names', ptmNames) self.parent.createLayout(ptmVars['adv']['layout']) @@ -94,4 +104,5 @@ class Reinit(): ptmVars['tooltip']['required'].append("up") else: ptmVars['tooltip']['required'].append(label) + if self.debug: qDebug("[PTM] [reinit.py] [reinit] : Returns vars '%s'" %(ptmVars)) self.parent.applySettings('vars', ptmVars) diff --git a/sources/ptm/contents/code/tooltip.py b/sources/ptm/contents/code/tooltip.py index 1f654f6..6e2b21d 100644 --- a/sources/ptm/contents/code/tooltip.py +++ b/sources/ptm/contents/code/tooltip.py @@ -25,11 +25,20 @@ from PyQt4.QtGui import * class Tooltip(): def __init__(self, parent): """class definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main self.parent = parent def createGraphic(self, ptmVars, ptmTooltip, widget): """function to create graph""" + if self.debug: qDebug("[PTM] [tooltip.py] [createGraphic]") widget.clear() pen = QPen() bounds = ptmTooltip['bounds'] diff --git a/sources/ptm/contents/code/tooltipconfig.py b/sources/ptm/contents/code/tooltipconfig.py index 232dd08..7adac2d 100644 --- a/sources/ptm/contents/code/tooltipconfig.py +++ b/sources/ptm/contents/code/tooltipconfig.py @@ -27,6 +27,14 @@ from PyQt4 import uic class TooltipWindow(QWidget): def __init__(self, parent): """settings window definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main QWidget.__init__(self) self.ui = uic.loadUi(parent.package().filePath('ui', 'tooltipconfig.ui'), self) self.parent = parent diff --git a/sources/ptm/contents/code/widget.py b/sources/ptm/contents/code/widget.py index d67f087..d5c3bf5 100644 --- a/sources/ptm/contents/code/widget.py +++ b/sources/ptm/contents/code/widget.py @@ -27,6 +27,14 @@ from PyQt4 import uic class WidgetWindow(QWidget): def __init__(self, parent): """settings window definition""" + # debug + environment = QProcessEnvironment.systemEnvironment() + debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")): + self.debug = True + else: + self.debug = False + # main QWidget.__init__(self) self.ui = uic.loadUi(parent.package().filePath('ui', 'widget.ui'), self) self.parent = parent @@ -66,6 +74,7 @@ class WidgetWindow(QWidget): def setSlider(self): """function to set sliders""" + if self.debug: qDebug("[PTM] [widget.py] [setSlider]") if (self.sender().isEnabled() == True): second_slider = self.sender() order = [] @@ -84,6 +93,7 @@ class WidgetWindow(QWidget): def setStatus(self): """function to enable label""" + if self.debug: qDebug("[PTM] [widget.py] [setStatus]") for label in self.checkboxes.keys(): if ((self.checkboxes[label].checkState() > 0) and (self.sliders[label].isEnabled() == False)): self.lineedits[label].setEnabled(True)