mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
add support of debug to widget
This commit is contained in:
parent
e32a37043a
commit
cebf3b9aea
@ -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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); 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(','));
|
||||
}
|
||||
|
||||
|
||||
QString ExtendedSysMon::getAutoGpu()
|
||||
{
|
||||
if (debug) qDebug() << "[getAutoGpu]";
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoGpu]";
|
||||
QProcess command;
|
||||
QString gpu = QString("disable");
|
||||
QString cmd = QString("lspci");
|
||||
QString qoutput = QString("");
|
||||
if (debug) qDebug() << "[getAutoGpu]" << ":" << "Run cmd" << cmd;
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Run cmd" << cmd;
|
||||
command.start(cmd);
|
||||
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());
|
||||
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<QString, QString> 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<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, QString> rawConfig)
|
||||
{
|
||||
if (debug) qDebug() << "[updateConfiguration]";
|
||||
if (debug) qDebug() << "[DE]" << "[updateConfiguration]";
|
||||
QMap<QString, QString> config;
|
||||
QString key, value;
|
||||
// remove spaces and copy source map
|
||||
@ -200,7 +200,7 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
||||
config[QString("PLAYER")] = QString("amarok");
|
||||
|
||||
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]];
|
||||
return config;
|
||||
}
|
||||
@ -208,24 +208,24 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
||||
|
||||
QString ExtendedSysMon::getCustomCmd(const QString cmd)
|
||||
{
|
||||
if (debug) qDebug() << "[getCustomCmd]";
|
||||
if (debug) qDebug() << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd;
|
||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]";
|
||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd;
|
||||
QProcess command;
|
||||
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.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();
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
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")) {
|
||||
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.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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
float ExtendedSysMon::getGpuTemp(const QString device)
|
||||
{
|
||||
if (debug) qDebug() << "[getGpuTemp]";
|
||||
if (debug) qDebug() << "[getGpuTemp]" << ":" << "Run function with device" << device;
|
||||
if (debug) qDebug() << "[DE]" << "[getGpuTemp]";
|
||||
if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run function with device" << device;
|
||||
float gpuTemp = 0.0;
|
||||
if ((device != QString("nvidia")) && (device != QString("ati")))
|
||||
return gpuTemp;
|
||||
@ -281,10 +281,10 @@ float ExtendedSysMon::getGpuTemp(const QString device)
|
||||
|
||||
if (device == QString("nvidia")) {
|
||||
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.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());
|
||||
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
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")) {
|
||||
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.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());
|
||||
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
float ExtendedSysMon::getHddTemp(const QString cmd, const QString device)
|
||||
{
|
||||
if (debug) qDebug() << "[getHddTemp]";
|
||||
if (debug) qDebug() << "[getHddTemp]" << ":" << "Run function with cmd" << cmd;
|
||||
if (debug) qDebug() << "[getHddTemp]" << ":" << "Run function with device" << device;
|
||||
if (debug) qDebug() << "[DE]" << "[getHddTemp]";
|
||||
if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with cmd" << cmd;
|
||||
if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with device" << device;
|
||||
float hddTemp = 0.0;
|
||||
QProcess command;
|
||||
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.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();
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); 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");
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
@ -396,10 +396,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
|
||||
else if (playerName == QString("clementine")) {
|
||||
// clementine
|
||||
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.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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); 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");
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
@ -430,10 +430,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
|
||||
// mpd
|
||||
cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") +
|
||||
mpdAddress + QString(":") + mpdPort + QString("\"");
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
@ -454,10 +454,10 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
|
||||
else if (playerName == QString("qmmp")) {
|
||||
// qmmp
|
||||
cmd = QString("qmmp --status");
|
||||
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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); 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;
|
||||
}
|
||||
|
||||
|
||||
QStringList ExtendedSysMon::getPsStats()
|
||||
{
|
||||
if (debug) qDebug() << "[getPsStats]";
|
||||
if (debug) qDebug() << "[DE]" << "[getPsStats]";
|
||||
int psCount = 0;
|
||||
QStringList psList;
|
||||
QString cmd;
|
||||
QProcess command;
|
||||
QString qoutput = QString("");
|
||||
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.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();
|
||||
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")) {
|
||||
@ -506,50 +506,50 @@ QStringList ExtendedSysMon::getPsStats()
|
||||
psStats.append(QString::number(psCount));
|
||||
psStats.append(psList.join(QString(",")));
|
||||
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.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();
|
||||
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<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
||||
|
@ -27,6 +27,14 @@ from PyQt4 import uic
|
||||
class AdvancedWindow(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', 'advanced.ui'), self)
|
||||
self.parent = parent
|
||||
@ -44,6 +52,8 @@ class AdvancedWindow(QWidget):
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
"""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 (self.ui.listWidget_hddDevice.hasFocus() and
|
||||
(self.ui.listWidget_hddDevice.currentRow() > -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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"):
|
||||
|
@ -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"))):
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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"):
|
||||
|
@ -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)
|
||||
|
@ -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']
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user