add support of debug to widget

This commit is contained in:
arcan1s 2014-06-02 15:59:11 +04:00
parent e32a37043a
commit cebf3b9aea
12 changed files with 271 additions and 74 deletions

View File

@ -36,7 +36,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args)
// debug // debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); 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")) if (debugEnv == QString("yes"))
debug = true; debug = true;
else else
@ -49,47 +49,47 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args)
QString ExtendedSysMon::getAllHdd() QString ExtendedSysMon::getAllHdd()
{ {
if (debug) qDebug() << "[getAllHdd]"; if (debug) qDebug() << "[DE]" << "[getAllHdd]";
QProcess command; QProcess command;
QStringList devices; QStringList devices;
QString cmd = QString("find /dev -name [hms]d[a-z]"); QString cmd = QString("find /dev -name [hms]d[a-z]");
QString qoutput = QString(""); QString qoutput = QString("");
if (debug) qDebug() << "[getAllHdd]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++)
devices.append(qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]); devices.append(qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]);
if (debug) qDebug() << "[getAllHdd]" << ":" << "Device list" << devices; if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Device list" << devices;
return devices.join(QChar(',')); return devices.join(QChar(','));
} }
QString ExtendedSysMon::getAutoGpu() QString ExtendedSysMon::getAutoGpu()
{ {
if (debug) qDebug() << "[getAutoGpu]"; if (debug) qDebug() << "[DE]" << "[getAutoGpu]";
QProcess command; QProcess command;
QString gpu = QString("disable"); QString gpu = QString("disable");
QString cmd = QString("lspci"); QString cmd = QString("lspci");
QString qoutput = QString(""); QString qoutput = QString("");
if (debug) qDebug() << "[getAutoGpu]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getAutoGpu]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
if (qoutput.toLower().contains("nvidia")) if (qoutput.toLower().contains("nvidia"))
gpu = QString("nvidia"); gpu = QString("nvidia");
else if (qoutput.toLower().contains("radeon")) else if (qoutput.toLower().contains("radeon"))
gpu = QString("ati"); gpu = QString("ati");
if (debug) qDebug() << "[getAutoGpu]" << ":" << "Device" << gpu; if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Device" << gpu;
return gpu; return gpu;
} }
QStringList ExtendedSysMon::sources() const QStringList ExtendedSysMon::sources() const
{ {
if (debug) qDebug() << "[sources]"; if (debug) qDebug() << "[DE]" << "[sources]";
QStringList source; QStringList source;
source.append(QString("custom")); source.append(QString("custom"));
source.append(QString("gpu")); source.append(QString("gpu"));
@ -98,14 +98,14 @@ QStringList ExtendedSysMon::sources() const
source.append(QString("pkg")); source.append(QString("pkg"));
source.append(QString("player")); source.append(QString("player"));
source.append(QString("ps")); source.append(QString("ps"));
if (debug) qDebug() << "[sources]" << ":" << "Sources" << source; if (debug) qDebug() << "[DE]" << "[sources]" << ":" << "Sources" << source;
return source; return source;
} }
void ExtendedSysMon::readConfiguration() void ExtendedSysMon::readConfiguration()
{ {
if (debug) qDebug() << "[readConfiguration]"; if (debug) qDebug() << "[DE]" << "[readConfiguration]";
// pre-setup // pre-setup
QMap<QString, QString> rawConfig; QMap<QString, QString> rawConfig;
rawConfig[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip"); rawConfig[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip");
@ -119,7 +119,7 @@ void ExtendedSysMon::readConfiguration()
rawConfig[QString("PLAYER")] = QString("amarok"); rawConfig[QString("PLAYER")] = QString("amarok");
QString fileName = KGlobal::dirs()->findResource("config", "extsysmon.conf"); 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); QFile confFile(fileName);
bool ok = confFile.open(QIODevice::ReadOnly); bool ok = confFile.open(QIODevice::ReadOnly);
if (!ok) { if (!ok) {
@ -148,7 +148,7 @@ void ExtendedSysMon::readConfiguration()
QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, QString> rawConfig) QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, QString> rawConfig)
{ {
if (debug) qDebug() << "[updateConfiguration]"; if (debug) qDebug() << "[DE]" << "[updateConfiguration]";
QMap<QString, QString> config; QMap<QString, QString> config;
QString key, value; QString key, value;
// remove spaces and copy source map // remove spaces and copy source map
@ -200,7 +200,7 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
config[QString("PLAYER")] = QString("amarok"); config[QString("PLAYER")] = QString("amarok");
for (int i=0; i<config.keys().count(); i++) for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << "[updateConfiguration]" << ":" << if (debug) qDebug() << "[DE]" << "[updateConfiguration]" << ":" <<
config.keys()[i] + QString("=") + config[config.keys()[i]]; config.keys()[i] + QString("=") + config[config.keys()[i]];
return config; return config;
} }
@ -208,24 +208,24 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
QString ExtendedSysMon::getCustomCmd(const QString cmd) QString ExtendedSysMon::getCustomCmd(const QString cmd)
{ {
if (debug) qDebug() << "[getCustomCmd]"; if (debug) qDebug() << "[DE]" << "[getCustomCmd]";
if (debug) qDebug() << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd;
QProcess command; QProcess command;
QString qoutput = QString(""); QString qoutput = QString("");
if (debug) qDebug() << "[getCustomCmd]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\""); if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\"");
command.start(QString("bash -c \"") + cmd + QString("\"")); command.start(QString("bash -c \"") + cmd + QString("\""));
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getCustomCmd]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
if (debug) qDebug() << "[getCustomCmd]" << ":" << "Return" << qoutput; if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Return" << qoutput;
return qoutput; return qoutput;
} }
float ExtendedSysMon::getGpu(const QString device) float ExtendedSysMon::getGpu(const QString device)
{ {
if (debug) qDebug() << "[getGpu]"; if (debug) qDebug() << "[DE]" << "[getGpu]";
if (debug) qDebug() << "[getGpu]" << ":" << "Run function with device" << device; if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run function with device" << device;
float gpu = 0.0; float gpu = 0.0;
if ((device != QString("nvidia")) && (device != QString("ati"))) if ((device != QString("nvidia")) && (device != QString("ati")))
return gpu; return gpu;
@ -234,10 +234,10 @@ float ExtendedSysMon::getGpu(const QString device)
if (device == QString("nvidia")) { if (device == QString("nvidia")) {
QString cmd = QString("nvidia-smi -q -d UTILIZATION"); 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.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Gpu"))) { if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Gpu"))) {
@ -250,10 +250,10 @@ float ExtendedSysMon::getGpu(const QString device)
} }
else if (device == QString("ati")) { else if (device == QString("ati")) {
QString cmd = QString("aticonfig --od-getclocks"); QString cmd = QString("aticonfig --od-getclocks");
if (debug) qDebug() << "[getGpu]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("load"))) { if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("load"))) {
@ -264,15 +264,15 @@ float ExtendedSysMon::getGpu(const QString device)
} }
} }
} }
if (debug) qDebug() << "[getGpu]" << ":" << "Return" << gpu; if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Return" << gpu;
return gpu; return gpu;
} }
float ExtendedSysMon::getGpuTemp(const QString device) float ExtendedSysMon::getGpuTemp(const QString device)
{ {
if (debug) qDebug() << "[getGpuTemp]"; if (debug) qDebug() << "[DE]" << "[getGpuTemp]";
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Run function with device" << device; if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run function with device" << device;
float gpuTemp = 0.0; float gpuTemp = 0.0;
if ((device != QString("nvidia")) && (device != QString("ati"))) if ((device != QString("nvidia")) && (device != QString("ati")))
return gpuTemp; return gpuTemp;
@ -281,10 +281,10 @@ float ExtendedSysMon::getGpuTemp(const QString device)
if (device == QString("nvidia")) { if (device == QString("nvidia")) {
QString cmd = QString("nvidia-smi -q -d TEMPERATURE"); QString cmd = QString("nvidia-smi -q -d TEMPERATURE");
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Gpu"))) { if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Gpu"))) {
@ -296,10 +296,10 @@ float ExtendedSysMon::getGpuTemp(const QString device)
} }
else if (device == QString("ati")) { else if (device == QString("ati")) {
QString cmd = QString("aticonfig --od-gettemperature"); QString cmd = QString("aticonfig --od-gettemperature");
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Temperature"))) { if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i].contains(QString("Temperature"))) {
@ -309,30 +309,30 @@ float ExtendedSysMon::getGpuTemp(const QString device)
} }
} }
} }
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Return" << gpuTemp; if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Return" << gpuTemp;
return gpuTemp; return gpuTemp;
} }
float ExtendedSysMon::getHddTemp(const QString cmd, const QString device) float ExtendedSysMon::getHddTemp(const QString cmd, const QString device)
{ {
if (debug) qDebug() << "[getHddTemp]"; if (debug) qDebug() << "[DE]" << "[getHddTemp]";
if (debug) qDebug() << "[getHddTemp]" << ":" << "Run function with cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with cmd" << cmd;
if (debug) qDebug() << "[getHddTemp]" << ":" << "Run function with device" << device; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with device" << device;
float hddTemp = 0.0; float hddTemp = 0.0;
QProcess command; QProcess command;
QString qoutput = QString(""); QString qoutput = QString("");
if (debug) qDebug() << "[getHddTemp]" << ":" << "Run cmd" << cmd + QString(" ") + device; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run cmd" << cmd + QString(" ") + device;
command.start(cmd + QString(" ") + device); command.start(cmd + QString(" ") + device);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getHddTemp]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2]; QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2];
temp.remove(QChar(0260)).remove(QChar('C')); temp.remove(QChar(0260)).remove(QChar('C'));
hddTemp = temp.toFloat(); hddTemp = temp.toFloat();
} }
if (debug) qDebug() << "[getHddTemp]" << ":" << "Return" << hddTemp; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Return" << hddTemp;
return hddTemp; return hddTemp;
} }
@ -341,9 +341,9 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
const QString mpdAddress, const QString mpdAddress,
const QString mpdPort) const QString mpdPort)
{ {
if (debug) qDebug() << "[getPlayerInfo]"; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]";
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run function with player" << playerName; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with player" << playerName;
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" << if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" <<
mpdAddress + QString(":") + mpdPort; mpdAddress + QString(":") + mpdPort;
QStringList info; QStringList info;
// album // album
@ -363,10 +363,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
if (playerName == QString("amarok")) { if (playerName == QString("amarok")) {
// amarok // amarok
cmd = QString("qdbus org.kde.amarok /Player GetMetadata"); 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.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -382,10 +382,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
} }
} }
cmd = QString("qdbus org.kde.amarok /Player PositionGet"); cmd = QString("qdbus org.kde.amarok /Player PositionGet");
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -396,10 +396,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
else if (playerName == QString("clementine")) { else if (playerName == QString("clementine")) {
// clementine // clementine
cmd = QString("qdbus org.mpris.clementine /Player GetMetadata"); cmd = QString("qdbus org.mpris.clementine /Player GetMetadata");
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -415,10 +415,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
} }
} }
cmd = QString("qdbus org.mpris.clementine /Player PositionGet"); cmd = QString("qdbus org.mpris.clementine /Player PositionGet");
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -430,10 +430,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
// mpd // mpd
cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") + cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") +
mpdAddress + QString(":") + mpdPort + QString("\""); mpdAddress + QString(":") + mpdPort + QString("\"");
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -454,10 +454,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
else if (playerName == QString("qmmp")) { else if (playerName == QString("qmmp")) {
// qmmp // qmmp
cmd = QString("qmmp --status"); cmd = QString("qmmp --status");
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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()); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]; qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
@ -478,24 +478,24 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
} }
} }
} }
if (debug) qDebug() << "[getPlayerInfo]" << ":" << "Return" << info; if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Return" << info;
return info; return info;
} }
QStringList ExtendedSysMon::getPsStats() QStringList ExtendedSysMon::getPsStats()
{ {
if (debug) qDebug() << "[getPsStats]"; if (debug) qDebug() << "[DE]" << "[getPsStats]";
int psCount = 0; int psCount = 0;
QStringList psList; QStringList psList;
QString cmd; QString cmd;
QProcess command; QProcess command;
QString qoutput = QString(""); QString qoutput = QString("");
cmd = QString("ps --no-headers -o command"); cmd = QString("ps --no-headers -o command");
if (debug) qDebug() << "[getPsStats]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getPsStats]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++)
if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i] != QString("ps --no-headers -o command")) { if (qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i] != QString("ps --no-headers -o command")) {
@ -506,50 +506,50 @@ QStringList ExtendedSysMon::getPsStats()
psStats.append(QString::number(psCount)); psStats.append(QString::number(psCount));
psStats.append(psList.join(QString(","))); psStats.append(psList.join(QString(",")));
cmd = QString("ps -e --no-headers -o command"); cmd = QString("ps -e --no-headers -o command");
if (debug) qDebug() << "[getPsStats]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); command.waitForFinished(-1);
if (debug) qDebug() << "[getPsStats]" << ":" << "Cmd returns" << command.exitCode(); if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Cmd returns" << command.exitCode();
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
int psTotal = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); int psTotal = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count();
psStats.append(QString::number(psTotal)); psStats.append(QString::number(psTotal));
if (debug) qDebug() << "[getPsStats]" << ":" << "Return" << psStats; if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Return" << psStats;
return psStats; return psStats;
} }
int ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int pkgNull) int ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int pkgNull)
{ {
if (debug) qDebug() << "[getUpgradeInfo]"; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]";
if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run function with cmd" << pkgCommand; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with cmd" << pkgCommand;
if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run function with number of null lines" << pkgNull; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with number of null lines" << pkgNull;
int count = 0; int count = 0;
QString cmd = QString("bash -c \"") + pkgCommand + QString("\""); QString cmd = QString("bash -c \"") + pkgCommand + QString("\"");
QProcess command; QProcess command;
QString qoutput = QString(""); QString qoutput = QString("");
if (debug) qDebug() << "[getUpgradeInfo]" << ":" << "Run cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run cmd" << cmd;
command.start(cmd); command.start(cmd);
command.waitForFinished(-1); 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(); qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
count = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); 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); return (count - pkgNull);
} }
bool ExtendedSysMon::sourceRequestEvent(const QString &name) bool ExtendedSysMon::sourceRequestEvent(const QString &name)
{ {
if (debug) qDebug() << "[sourceRequestEvent]"; if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]";
if (debug) qDebug() << "[sourceRequestEvent]" << ":" << "Run function with source name" << name; if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]" << ":" << "Run function with source name" << name;
return updateSourceEvent(name); return updateSourceEvent(name);
} }
bool ExtendedSysMon::updateSourceEvent(const QString &source) bool ExtendedSysMon::updateSourceEvent(const QString &source)
{ {
if (debug) qDebug() << "[updateSourceEvent]"; if (debug) qDebug() << "[DE]" << "[updateSourceEvent]";
if (debug) qDebug() << "[updateSourceEvent]" << ":" << "Run function with source name" << source; if (debug) qDebug() << "[DE]" << "[updateSourceEvent]" << ":" << "Run function with source name" << source;
QString key; QString key;
if (source == QString("custom")) { if (source == QString("custom")) {
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) { for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {

View File

@ -27,6 +27,14 @@ from PyQt4 import uic
class AdvancedWindow(QWidget): class AdvancedWindow(QWidget):
def __init__(self, parent): def __init__(self, parent):
"""settings window definition""" """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) QWidget.__init__(self)
self.ui = uic.loadUi(parent.package().filePath('ui', 'advanced.ui'), self) self.ui = uic.loadUi(parent.package().filePath('ui', 'advanced.ui'), self)
self.parent = parent self.parent = parent
@ -44,6 +52,8 @@ class AdvancedWindow(QWidget):
def keyPressEvent(self, event): def keyPressEvent(self, event):
"""delete events""" """delete events"""
if self.debug: qDebug("[PTM] [advanced.py] [keyPressEvent]")
if self.debug: qDebug("[PTM] [advanced.py] [keyPressEvent] : Run function with event '%s'" %(event.key()))
if (event.key() == Qt.Key_Delete): if (event.key() == Qt.Key_Delete):
if (self.ui.listWidget_hddDevice.hasFocus() and if (self.ui.listWidget_hddDevice.hasFocus() and
(self.ui.listWidget_hddDevice.currentRow() > -1)): (self.ui.listWidget_hddDevice.currentRow() > -1)):
@ -61,30 +71,40 @@ class AdvancedWindow(QWidget):
def addHddDevice(self): def addHddDevice(self):
"""function to add mount points""" """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.clearSelection()
self.ui.listWidget_hddDevice.addItem(self.ui.comboBox_hddDevice.currentText()) self.ui.listWidget_hddDevice.addItem(self.ui.comboBox_hddDevice.currentText())
def addHddSpeedDevice(self): def addHddSpeedDevice(self):
"""function to add disk device""" """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.clearSelection()
self.ui.listWidget_hddSpeedDevice.addItem(self.ui.comboBox_hddSpeedDevice.currentText()) self.ui.listWidget_hddSpeedDevice.addItem(self.ui.comboBox_hddSpeedDevice.currentText())
def addMount(self): def addMount(self):
"""function to add mount points""" """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.clearSelection()
self.ui.listWidget_mount.addItem(self.ui.comboBox_mount.currentText()) self.ui.listWidget_mount.addItem(self.ui.comboBox_mount.currentText())
def addTempDevice(self): def addTempDevice(self):
"""function to add temperature device""" """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.clearSelection()
self.ui.listWidget_tempDevice.addItem(self.ui.comboBox_tempDevice.currentText()) self.ui.listWidget_tempDevice.addItem(self.ui.comboBox_tempDevice.currentText())
def setNetdevEnabled(self): def setNetdevEnabled(self):
"""function to set enabled netdev""" """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): if (self.ui.checkBox_netdev.checkState() == 0):
self.ui.comboBox_netdev.setDisabled(True) self.ui.comboBox_netdev.setDisabled(True)
else: else:

View File

@ -27,6 +27,14 @@ from PyQt4 import uic
class AppearanceWindow(QWidget): class AppearanceWindow(QWidget):
def __init__(self, parent): def __init__(self, parent):
"""settings window definition""" """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) QWidget.__init__(self)
self.ui = uic.loadUi(parent.package().filePath('ui', 'appearance.ui'), self) self.ui = uic.loadUi(parent.package().filePath('ui', 'appearance.ui'), self)
self.parent = parent self.parent = parent

View File

@ -29,6 +29,14 @@ import config
class ConfigDefinition: class ConfigDefinition:
def __init__(self, parent, configpage, defaults): def __init__(self, parent, configpage, defaults):
"""class definition""" """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.parent = parent
self.configpage = configpage self.configpage = configpage
self.defaults = defaults self.defaults = defaults
@ -36,6 +44,7 @@ class ConfigDefinition:
def configAccepted(self): def configAccepted(self):
"""function to accept settings""" """function to accept settings"""
if self.debug: qDebug("[PTM] [configdef.py] [configAccepted]")
settings = config.Config(self.parent) settings = config.Config(self.parent)
# update local variables # update local variables
@ -128,6 +137,7 @@ class ConfigDefinition:
def createConfigurationInterface(self, parent): def createConfigurationInterface(self, parent):
"""function to setup configuration window""" """function to setup configuration window"""
if self.debug: qDebug("[PTM] [configdef.py] [createConfigurationInterface]")
settings = config.Config(self.parent) settings = config.Config(self.parent)
font = QFont(str(settings.get('font_family', 'Terminus')), settings.get('font_size', 12).toInt()[0], 400, False) font = QFont(str(settings.get('font_family', 'Terminus')), settings.get('font_size', 12).toInt()[0], 400, False)

View File

@ -32,11 +32,23 @@ timeLetters = ['dddd', 'ddd', 'dd', 'd', \
class DataEngine: class DataEngine:
def __init__(self, parent): def __init__(self, parent):
"""class definition""" """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.parent = parent
def connectToEngine(self, bools=None, dataEngines=None, interval=1000, names=None): def connectToEngine(self, bools=None, dataEngines=None, interval=1000, names=None):
"""function to initializate engine""" """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): if (bools['cpu'] > 0):
dataEngines['system'].connectSource("cpu/system/TotalLoad", self.parent, interval) dataEngines['system'].connectSource("cpu/system/TotalLoad", self.parent, interval)
for core in range(8): for core in range(8):
@ -90,6 +102,10 @@ class DataEngine:
def dataUpdated(self, sourceName, data, ptm): def dataUpdated(self, sourceName, data, ptm):
"""function to update data""" """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'] adv = ptm['vars']['adv']
systemDataEngine = ptm['dataengine']['system'] systemDataEngine = ptm['dataengine']['system']
formats = ptm['vars']['formats'] 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]) updatedData['value'] = "%s%i%s" % (updatedData['value'].split('$m')[0], minutes, updatedData['value'].split('$m')[1])
except: except:
pass pass
if self.debug: qDebug("[PTM] [dataengine.py] [dataUpdated] : Returns '%s'" %(updatedData))
return updatedData return updatedData
def disconnectFromSource(self, dataEngines=None, keys=None, name=None): def disconnectFromSource(self, dataEngines=None, keys=None, name=None):
"""function to disconnect from sources""" """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"): if (name == "bat"):
pass pass
elif (name == "cpu"): elif (name == "cpu"):

View File

@ -27,6 +27,14 @@ from PyQt4 import uic
class DEConfigWindow(QWidget): class DEConfigWindow(QWidget):
def __init__(self, parent): def __init__(self, parent):
"""settings window definition""" """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) QWidget.__init__(self)
self.ui = uic.loadUi(parent.package().filePath('ui', 'deconfig.ui'), self) self.ui = uic.loadUi(parent.package().filePath('ui', 'deconfig.ui'), self)
self.parent = parent self.parent = parent
@ -41,6 +49,8 @@ class DEConfigWindow(QWidget):
def keyPressEvent(self, event): def keyPressEvent(self, event):
"""delete events""" """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 (event.key() == Qt.Key_Delete):
if (self.ui.listWidget_customCommand.hasFocus() and if (self.ui.listWidget_customCommand.hasFocus() and
(self.ui.listWidget_customCommand.currentRow() > -1)): (self.ui.listWidget_customCommand.currentRow() > -1)):
@ -52,12 +62,16 @@ class DEConfigWindow(QWidget):
def addCustomCommand(self): def addCustomCommand(self):
"""function to add custom command""" """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.clearSelection()
self.ui.listWidget_customCommand.addItem(self.ui.lineEdit_customCommand.text()) self.ui.listWidget_customCommand.addItem(self.ui.lineEdit_customCommand.text())
def addPkgCommand(self): def addPkgCommand(self):
"""function to add package manager command""" """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.clearSelection()
self.ui.listWidget_pkgCommand.addItem(self.ui.comboBox_pkgCommand.currentText() +\ self.ui.listWidget_pkgCommand.addItem(self.ui.comboBox_pkgCommand.currentText() +\
QString(":") + QString.number(self.ui.spinBox_pkgCommandNum.value())) QString(":") + QString.number(self.ui.spinBox_pkgCommandNum.value()))
@ -65,6 +79,7 @@ class DEConfigWindow(QWidget):
def updatePkgNullValue(self): def updatePkgNullValue(self):
"""function to set default values to PKGNULL spinbox""" """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"))): if (self.ui.comboBox_pkgCommand.currentText().contains(QString("pacman -Qu"))):
self.ui.spinBox_pkgCommandNum.setValue(0) self.ui.spinBox_pkgCommandNum.setValue(0)
elif (self.ui.comboBox_pkgCommand.currentText().contains(QString("apt-show-versions -u -b"))): elif (self.ui.comboBox_pkgCommand.currentText().contains(QString("apt-show-versions -u -b"))):

View File

@ -72,12 +72,21 @@ class CustomPlasmaLabel(Plasma.Label):
class pyTextWidget(plasmascript.Applet): class pyTextWidget(plasmascript.Applet):
def __init__(self, parent, args=None): def __init__(self, parent, args=None):
"""widget definition""" """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) plasmascript.Applet.__init__(self, parent)
# initialization # initialization
def init(self): def init(self):
"""function to initializate widget""" """function to initializate widget"""
if self.debug: qDebug("[PTM] [main.py] [init]")
self.setupVar() self.setupVar()
self.dataengine = dataengine.DataEngine(self) self.dataengine = dataengine.DataEngine(self)
@ -85,7 +94,7 @@ class pyTextWidget(plasmascript.Applet):
self.tooltipAgent = tooltip.Tooltip(self) self.tooltipAgent = tooltip.Tooltip(self)
self.timer = QTimer() self.timer = QTimer()
QObject.connect(self.timer, SIGNAL("timeout()"), self.updateLabel) QObject.connect(self.timer, SIGNAL("timeout()"), self.startPolling)
self.initTooltip() self.initTooltip()
self.reInit() self.reInit()
@ -103,6 +112,7 @@ class pyTextWidget(plasmascript.Applet):
# context menu # context menu
def createActions(self): def createActions(self):
"""function to create actions""" """function to create actions"""
if self.debug: qDebug("[PTM] [main.py] [createActions]")
self.ptmActions = {} self.ptmActions = {}
self.ptmActions['ksysguard'] = QAction(i18n("Run ksysguard"), self) self.ptmActions['ksysguard'] = QAction(i18n("Run ksysguard"), self)
QObject.connect(self.ptmActions['ksysguard'], SIGNAL("triggered(bool)"), self.runKsysguard) QObject.connect(self.ptmActions['ksysguard'], SIGNAL("triggered(bool)"), self.runKsysguard)
@ -120,6 +130,7 @@ class pyTextWidget(plasmascript.Applet):
def contextualActions(self): def contextualActions(self):
"""function to create context menu""" """function to create context menu"""
if self.debug: qDebug("[PTM] [main.py] [contextualActions]")
contextMenu = [] contextMenu = []
contextMenu.append(self.ptmActions['ksysguard']) contextMenu.append(self.ptmActions['ksysguard'])
contextMenu.append(self.ptmActions['readme']) contextMenu.append(self.ptmActions['readme'])
@ -129,11 +140,14 @@ class pyTextWidget(plasmascript.Applet):
def runKsysguard(self, event): def runKsysguard(self, event):
"""function to run ksysguard""" """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 &") os.system("ksysguard &")
def showReadme(self): def showReadme(self):
"""function to show readme file""" """function to show readme file"""
if self.debug: qDebug("[PTM] [main.py] [showReadme]")
kdehome = unicode(KGlobal.dirs().localkdedir()) kdehome = unicode(KGlobal.dirs().localkdedir())
if (os.path.exists("/usr/share/pytextmonitor/")): if (os.path.exists("/usr/share/pytextmonitor/")):
dirPath = "/usr/share/pytextmonitor/" dirPath = "/usr/share/pytextmonitor/"
@ -152,18 +166,22 @@ class pyTextWidget(plasmascript.Applet):
filePath = dirPath + "en.html" filePath = dirPath + "en.html"
else: else:
return return
if self.debug: qDebug("[PTM] [main.py] [showReadme] : Run cmd " + "'kioclient exec " + str(filePath) + " &'")
os.system("kioclient exec " + str(filePath) + " &") os.system("kioclient exec " + str(filePath) + " &")
# internal functions # internal functions
def addDiskDevice(self, sourceName): def addDiskDevice(self, sourceName):
if self.debug: qDebug("[PTM] [main.py] [addDiskDevice]")
diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)") diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)")
if (diskRegexp.indexIn(sourceName) > -1): 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])) self.ptm['defaults']['disk'].append('/'.join(str(sourceName).split('/')[0:2]))
def createConfigurationInterface(self, parent): def createConfigurationInterface(self, parent):
"""function to setup configuration window""" """function to setup configuration window"""
if self.debug: qDebug("[PTM] [main.py] [createConfigurationInterface]")
configpage = {} configpage = {}
configpage['advanced'] = advanced.AdvancedWindow(self) configpage['advanced'] = advanced.AdvancedWindow(self)
configpage['appearance'] = appearance.AppearanceWindow(self) configpage['appearance'] = appearance.AppearanceWindow(self)
@ -177,6 +195,7 @@ class pyTextWidget(plasmascript.Applet):
def initTooltip(self): def initTooltip(self):
"""function to create tooltip""" """function to create tooltip"""
if self.debug: qDebug("[PTM] [main.py] [initTooltip]")
self.tooltip = Plasma.ToolTipContent() self.tooltip = Plasma.ToolTipContent()
self.tooltip.setMainText("PyTextMonitor") self.tooltip.setMainText("PyTextMonitor")
self.tooltip.setSubText('') self.tooltip.setSubText('')
@ -192,6 +211,8 @@ class pyTextWidget(plasmascript.Applet):
def setupVar(self): def setupVar(self):
"""function to setup variables""" """function to setup variables"""
if self.debug: qDebug("[PTM] [main.py] [setupVar]")
# variables
self.ptm = {} self.ptm = {}
# dataengines # dataengines
self.ptm['dataengine'] = {'ext':None, 'system':None, 'time':None} 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']['cpu'] = {-1:0.0}
self.ptm['values']['cpuclock'] = {-1:0.0} self.ptm['values']['cpuclock'] = {-1:0.0}
numCores = int(commands.getoutput("grep -c '^processor' /proc/cpuinfo")) 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): for i in range(numCores):
self.ptm['values']['cpu'][i] = 0.0 self.ptm['values']['cpu'][i] = 0.0
self.ptm['values']['cpuclock'][i] = 0.0 self.ptm['values']['cpuclock'][i] = 0.0
@ -270,21 +292,26 @@ class pyTextWidget(plasmascript.Applet):
def showConfigurationInterface(self): def showConfigurationInterface(self):
"""function to show configuration window""" """function to show configuration window"""
if self.debug: qDebug("[PTM] [main.py] [showConfigurationInterface]")
plasmascript.Applet.showConfigurationInterface(self) plasmascript.Applet.showConfigurationInterface(self)
def startPolling(self): def startPolling(self):
"""function to update"""
if self.debug: qDebug("[PTM] [main.py] [startPolling]")
try: try:
self.timer.start()
self.updateLabel() self.updateLabel()
self.tooltip.setSubText('') self.tooltip.setSubText('')
if self.debug: qDebug("[PTM] [main.py] [startPolling] : Update without errors")
except Exception as strerror: except Exception as strerror:
self.tooltip.setSubText(str(strerror)) self.tooltip.setSubText(str(strerror))
if self.debug: qDebug("[PTM] [main.py] [startPolling] : There is some errors '%s'" %(str(strerror)))
return return
def updateLabel(self): def updateLabel(self):
"""function to update label""" """function to update label"""
if self.debug: qDebug("[PTM] [main.py] [updateLabel]")
if (self.ptm['vars']['bools']['bat'] > 0): if (self.ptm['vars']['bools']['bat'] > 0):
self.batText() self.batText()
if (self.ptm['vars']['bools']['cpu'] > 0): if (self.ptm['vars']['bools']['cpu'] > 0):
@ -310,11 +337,13 @@ class pyTextWidget(plasmascript.Applet):
def updateNetdev(self): def updateNetdev(self):
"""function to update netdev""" """function to update netdev"""
if self.debug: qDebug("[PTM] [main.py] [updateNetdev]")
self.ptm['names']['net'] = self.setNetdev() self.ptm['names']['net'] = self.setNetdev()
def updateTooltip(self): def updateTooltip(self):
"""function to update tooltip""" """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.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.tooltipAgent.createGraphic(self.ptm['vars']['tooltip'], self.ptm['tooltip'], self.tooltipScene)
self.tooltip.setImage(QPixmap.grabWidget(self.tooltipView)) self.tooltip.setImage(QPixmap.grabWidget(self.tooltipView))
@ -326,7 +355,11 @@ class pyTextWidget(plasmascript.Applet):
@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)") @pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
def dataUpdated(self, sourceName, data): def dataUpdated(self, sourceName, data):
"""function to update label""" """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) 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): if (updatedData['value'] == None):
return return
# update values where is needed # update values where is needed
@ -362,6 +395,7 @@ class pyTextWidget(plasmascript.Applet):
# update labels # update labels
def batText(self): def batText(self):
"""function to set battery text""" """function to set battery text"""
if self.debug: qDebug("[PTM] [main.py] [batText]")
line = self.ptm['vars']['formats']['bat'] line = self.ptm['vars']['formats']['bat']
if (line.split('$bat')[0] != line): if (line.split('$bat')[0] != line):
try: try:
@ -388,6 +422,7 @@ class pyTextWidget(plasmascript.Applet):
def cpuText(self): def cpuText(self):
"""function to set cpu text""" """function to set cpu text"""
if self.debug: qDebug("[PTM] [main.py] [cpuText]")
line = self.ptm['vars']['formats']['cpu'] line = self.ptm['vars']['formats']['cpu']
keys = self.ptm['values']['cpu'].keys() keys = self.ptm['values']['cpu'].keys()
keys.sort() keys.sort()
@ -405,6 +440,7 @@ class pyTextWidget(plasmascript.Applet):
def cpuclockText(self): def cpuclockText(self):
"""function to set cpu clock text""" """function to set cpu clock text"""
if self.debug: qDebug("[PTM] [main.py] [cpuclockText]")
line = self.ptm['vars']['formats']['cpuclock'] line = self.ptm['vars']['formats']['cpuclock']
keys = self.ptm['values']['cpuclock'].keys() keys = self.ptm['values']['cpuclock'].keys()
keys.sort() keys.sort()
@ -421,6 +457,8 @@ class pyTextWidget(plasmascript.Applet):
def diskText(self): def diskText(self):
"""function to update hdd speed text"""
if self.debug: qDebug("[PTM] [main.py] [diskText]")
line = self.ptm['vars']['formats']['disk'] line = self.ptm['vars']['formats']['disk']
devices = range(len(self.ptm['names']['disk'])) devices = range(len(self.ptm['names']['disk']))
devices.reverse() devices.reverse()
@ -437,6 +475,7 @@ class pyTextWidget(plasmascript.Applet):
def hddText(self): def hddText(self):
"""function to set hdd text""" """function to set hdd text"""
if self.debug: qDebug("[PTM] [main.py] [hddText]")
line = self.ptm['vars']['formats']['hdd'] line = self.ptm['vars']['formats']['hdd']
devices = range(len(self.ptm['names']['hdd'])) devices = range(len(self.ptm['names']['hdd']))
devices.reverse() devices.reverse()
@ -464,6 +503,7 @@ class pyTextWidget(plasmascript.Applet):
def hddtempText(self): def hddtempText(self):
"""function to set hddtemp text""" """function to set hddtemp text"""
if self.debug: qDebug("[PTM] [main.py] [hddtempText]")
line = self.ptm['vars']['formats']['hddtemp'] line = self.ptm['vars']['formats']['hddtemp']
devices = range(len(self.ptm['names']['hddtemp'])) devices = range(len(self.ptm['names']['hddtemp']))
devices.reverse() devices.reverse()
@ -478,6 +518,7 @@ class pyTextWidget(plasmascript.Applet):
def memText(self): def memText(self):
"""function to set mem text""" """function to set mem text"""
if self.debug: qDebug("[PTM] [main.py] [memText]")
line = self.ptm['vars']['formats']['mem'] line = self.ptm['vars']['formats']['mem']
if (line.split('$memtotgb')[0] != line): if (line.split('$memtotgb')[0] != line):
mem = "%4.1f" %((self.ptm['values']['mem']['free'] + self.ptm['values']['mem']['used']) / (1024.0 * 1024.0)) 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): def netText(self):
"""function to set network text""" """function to set network text"""
if self.debug: qDebug("[PTM] [main.py] [netText]")
line = self.ptm['vars']['formats']['net'] line = self.ptm['vars']['formats']['net']
if (line.split('$netdev')[0] != 0): if (line.split('$netdev')[0] != 0):
line = line.split('$netdev')[0] + self.ptm['names']['net'] + line.split('$netdev')[1] line = line.split('$netdev')[0] + self.ptm['names']['net'] + line.split('$netdev')[1]
@ -519,6 +561,7 @@ class pyTextWidget(plasmascript.Applet):
def swapText(self): def swapText(self):
"""function to set swap text""" """function to set swap text"""
if self.debug: qDebug("[PTM] [main.py] [swapText]")
line = self.ptm['vars']['formats']['swap'] line = self.ptm['vars']['formats']['swap']
if (line.split('$swaptotgb')[0] != line): if (line.split('$swaptotgb')[0] != line):
mem = "%4.1f" % ((self.ptm['values']['swap']['free'] + self.ptm['values']['swap']['used']) / (1024.0 * 1024.0)) 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): def tempText(self):
"""function to set temperature text""" """function to set temperature text"""
if self.debug: qDebug("[PTM] [main.py] [tempText]")
line = self.ptm['vars']['formats']['temp'] line = self.ptm['vars']['formats']['temp']
devices = range(len(self.ptm['names']['temp'])) devices = range(len(self.ptm['names']['temp']))
devices.reverse() devices.reverse()
@ -560,6 +604,11 @@ class pyTextWidget(plasmascript.Applet):
# external functions # external functions
def addLabel(self, name=None, text=None, add=True, enablePopup=2): def addLabel(self, name=None, text=None, add=True, enablePopup=2):
"""function to add new label""" """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): if (add):
self.ptm['labels'][name] = CustomPlasmaLabel(self.applet, name, enablePopup) self.ptm['labels'][name] = CustomPlasmaLabel(self.applet, name, enablePopup)
self.ptm['layout'].addItem(self.ptm['labels'][name]) self.ptm['layout'].addItem(self.ptm['labels'][name])
@ -571,6 +620,9 @@ class pyTextWidget(plasmascript.Applet):
def applySettings(self, name=None, ptm=None): def applySettings(self, name=None, ptm=None):
"""function to read settings""" """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 self.ptm[name] = ptm
if (name == "names"): if (name == "names"):
for item in ['hddtemp', 'temp']: for item in ['hddtemp', 'temp']:
@ -588,6 +640,7 @@ class pyTextWidget(plasmascript.Applet):
def connectToEngine(self): def connectToEngine(self):
"""function to connect to dataengines""" """function to connect to dataengines"""
if self.debug: qDebug("[PTM] [main.py] [connectToEngine]")
self.ptm['dataengine']['ext'] = self.dataEngine("ext-sysmon") self.ptm['dataengine']['ext'] = self.dataEngine("ext-sysmon")
self.ptm['dataengine']['system'] = self.dataEngine("systemmonitor") self.ptm['dataengine']['system'] = self.dataEngine("systemmonitor")
self.ptm['dataengine']['time'] = self.dataEngine("time") self.ptm['dataengine']['time'] = self.dataEngine("time")
@ -598,6 +651,8 @@ class pyTextWidget(plasmascript.Applet):
def createLayout(self, verticalLayout=0): def createLayout(self, verticalLayout=0):
"""function to create layout""" """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): if (verticalLayout == 0):
self.ptm['layout'] = QGraphicsLinearLayout(Qt.Horizontal, self.applet) self.ptm['layout'] = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
else: else:
@ -607,6 +662,7 @@ class pyTextWidget(plasmascript.Applet):
def disconnectFromSource(self): def disconnectFromSource(self):
"""function to disconnect from sources""" """function to disconnect from sources"""
if self.debug: qDebug("[PTM] [main.py] [disconnectFromSource]")
for label in self.ptm['defaults']['format'].keys(): for label in self.ptm['defaults']['format'].keys():
if (self.ptm['vars']['bools'][label] > 0): if (self.ptm['vars']['bools'][label] > 0):
self.addLabel(label, None, False) self.addLabel(label, None, False)
@ -618,6 +674,7 @@ class pyTextWidget(plasmascript.Applet):
def reInit(self): def reInit(self):
"""function to run reinit""" """function to run reinit"""
if self.debug: qDebug("[PTM] [main.py] [reInit]")
self.reinit.reinit() self.reinit.reinit()
self.updateNetdev() self.updateNetdev()
self.resize(10, 10) self.resize(10, 10)
@ -627,11 +684,13 @@ class pyTextWidget(plasmascript.Applet):
self.connectToEngine() self.connectToEngine()
self.timer.setInterval(self.ptm['vars']['app']['interval']) self.timer.setInterval(self.ptm['vars']['app']['interval'])
self.timer.start()
self.startPolling() self.startPolling()
def setNetdev(self): def setNetdev(self):
"""function to set network device""" """function to set network device"""
if self.debug: qDebug("[PTM] [main.py] [setNetdev]")
if (self.ptm['vars']['adv']['netdevBool'] > 0): if (self.ptm['vars']['adv']['netdevBool'] > 0):
return self.ptm['vars']['adv']['netdev'] return self.ptm['vars']['adv']['netdev']
netdev = "lo" netdev = "lo"
@ -645,16 +704,23 @@ class pyTextWidget(plasmascript.Applet):
netdev = str(device) netdev = str(device)
except: except:
pass pass
if self.debug: qDebug("[PTM] [main.py] [setNetdev] : Returns '%s'" %(netdev))
return netdev return netdev
def setText(self, name=None, text=None): def setText(self, name=None, text=None):
"""function to set text to labels""" """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) self.ptm['labels'][name].setText(text)
def textPrepare(self, name=None, text=None): def textPrepare(self, name=None, text=None):
"""function to prepare text""" """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] line = self.ptm['vars']['formats'][name]
if (name == "custom"): if (name == "custom"):
cmds = range(len(text.keys())) cmds = range(len(text.keys()))
@ -713,6 +779,7 @@ class pyTextWidget(plasmascript.Applet):
elif (line.split('$custom')[0] != line): elif (line.split('$custom')[0] != line):
line = line.split('$custom')[0] + text + line.split('$custom')[1] line = line.split('$custom')[0] + text + line.split('$custom')[1]
output = self.ptm['vars']['app']['format'][0] + line + self.ptm['vars']['app']['format'][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 return output

View File

@ -17,6 +17,7 @@
# along with pytextmonitor. If not, see http://www.gnu.org/licenses/ # # along with pytextmonitor. If not, see http://www.gnu.org/licenses/ #
############################################################################ ############################################################################
from PyQt4.QtCore import *
from PyKDE4.kdecore import KComponentData from PyKDE4.kdecore import KComponentData
from PyKDE4.kdeui import KNotification from PyKDE4.kdeui import KNotification
import commands import commands
@ -26,16 +27,28 @@ import commands
class PTMNotify: class PTMNotify:
def __init__(self, parent): def __init__(self, parent):
"""class definition""" """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): def init(self, name=None):
"""function to init notification""" """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) content = self.initText(name)
self.createNotify(content) self.createNotify(content)
def createNotify(self, content): def createNotify(self, content):
"""function to create notification for label""" """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 = KNotification(content[0])
notification.setComponentData(KComponentData("plasma_applet_pytextmonitor")) notification.setComponentData(KComponentData("plasma_applet_pytextmonitor"))
notification.setTitle("PyTextMonitor info ::: " + content[0]); notification.setTitle("PyTextMonitor info ::: " + content[0]);
@ -45,6 +58,8 @@ class PTMNotify:
def createText(self, type): def createText(self, type):
"""function to create text""" """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 = "" text = ""
if (type == "battery"): if (type == "battery"):
try: try:
@ -187,11 +202,14 @@ class PTMNotify:
except: except:
text = "Something wrong" text = "Something wrong"
content = [type, text] content = [type, text]
if self.debug: qDebug("[PTM] [ptmnotify.py] [createText] : Returns '%s'" %(content))
return content return content
def initText(self, name): def initText(self, name):
"""function to send text""" """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"): if (name == "bat"):
return self.createText("battery") return self.createText("battery")
elif (name == "cpu"): elif (name == "cpu"):

View File

@ -26,6 +26,14 @@ import config
class Reinit(): class Reinit():
def __init__(self, parent, defaults=None): def __init__(self, parent, defaults=None):
"""class definition""" """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.parent = parent
self.defaults = defaults self.defaults = defaults
self.labels = defaults['format'].keys() self.labels = defaults['format'].keys()
@ -33,6 +41,7 @@ class Reinit():
def reinit(self): def reinit(self):
"""function to reinitializate widget""" """function to reinitializate widget"""
if self.debug: qDebug("[PTM] [reinit.py] [reinit]")
settings = config.Config(self.parent) settings = config.Config(self.parent)
ptmVars = {} ptmVars = {}
@ -77,6 +86,7 @@ class Reinit():
ptmNames['hdd'] = str(settings.get('mount', '/')).split('@@') ptmNames['hdd'] = str(settings.get('mount', '/')).split('@@')
ptmNames['hddtemp'] = str(settings.get('hdd', '/dev/sda')).split('@@') ptmNames['hddtemp'] = str(settings.get('hdd', '/dev/sda')).split('@@')
ptmNames['temp'] = str(settings.get('temp_device', '')).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.applySettings('names', ptmNames)
self.parent.createLayout(ptmVars['adv']['layout']) self.parent.createLayout(ptmVars['adv']['layout'])
@ -94,4 +104,5 @@ class Reinit():
ptmVars['tooltip']['required'].append("up") ptmVars['tooltip']['required'].append("up")
else: else:
ptmVars['tooltip']['required'].append(label) ptmVars['tooltip']['required'].append(label)
if self.debug: qDebug("[PTM] [reinit.py] [reinit] : Returns vars '%s'" %(ptmVars))
self.parent.applySettings('vars', ptmVars) self.parent.applySettings('vars', ptmVars)

View File

@ -25,11 +25,20 @@ from PyQt4.QtGui import *
class Tooltip(): class Tooltip():
def __init__(self, parent): def __init__(self, parent):
"""class definition""" """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.parent = parent
def createGraphic(self, ptmVars, ptmTooltip, widget): def createGraphic(self, ptmVars, ptmTooltip, widget):
"""function to create graph""" """function to create graph"""
if self.debug: qDebug("[PTM] [tooltip.py] [createGraphic]")
widget.clear() widget.clear()
pen = QPen() pen = QPen()
bounds = ptmTooltip['bounds'] bounds = ptmTooltip['bounds']

View File

@ -27,6 +27,14 @@ from PyQt4 import uic
class TooltipWindow(QWidget): class TooltipWindow(QWidget):
def __init__(self, parent): def __init__(self, parent):
"""settings window definition""" """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) QWidget.__init__(self)
self.ui = uic.loadUi(parent.package().filePath('ui', 'tooltipconfig.ui'), self) self.ui = uic.loadUi(parent.package().filePath('ui', 'tooltipconfig.ui'), self)
self.parent = parent self.parent = parent

View File

@ -27,6 +27,14 @@ from PyQt4 import uic
class WidgetWindow(QWidget): class WidgetWindow(QWidget):
def __init__(self, parent): def __init__(self, parent):
"""settings window definition""" """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) QWidget.__init__(self)
self.ui = uic.loadUi(parent.package().filePath('ui', 'widget.ui'), self) self.ui = uic.loadUi(parent.package().filePath('ui', 'widget.ui'), self)
self.parent = parent self.parent = parent
@ -66,6 +74,7 @@ class WidgetWindow(QWidget):
def setSlider(self): def setSlider(self):
"""function to set sliders""" """function to set sliders"""
if self.debug: qDebug("[PTM] [widget.py] [setSlider]")
if (self.sender().isEnabled() == True): if (self.sender().isEnabled() == True):
second_slider = self.sender() second_slider = self.sender()
order = [] order = []
@ -84,6 +93,7 @@ class WidgetWindow(QWidget):
def setStatus(self): def setStatus(self):
"""function to enable label""" """function to enable label"""
if self.debug: qDebug("[PTM] [widget.py] [setStatus]")
for label in self.checkboxes.keys(): for label in self.checkboxes.keys():
if ((self.checkboxes[label].checkState() > 0) and (self.sliders[label].isEnabled() == False)): if ((self.checkboxes[label].checkState() > 0) and (self.sliders[label].isEnabled() == False)):
self.lineedits[label].setEnabled(True) self.lineedits[label].setEnabled(True)