void ConsoleDevice::setForeColor(const Qt::GlobalColor pColor) { switch (pColor) { case Qt::black: case Qt::white: case Qt::darkGray: case Qt::gray: case Qt::lightGray: case Qt::green: case Qt::blue: case Qt::cyan: case Qt::magenta: case Qt::yellow: case Qt::darkGreen: case Qt::darkBlue: case Qt::darkCyan: case Qt::darkMagenta: case Qt::darkYellow: case Qt::transparent: case Qt::darkRed: case Qt::red: stdOut()->write(QString("\033[37m").toUtf8()); break; default: break; } }
BottomBar::BottomBar(QWidget *parent) : QTabWidget(parent) { this->parent = (MainWindow*)parent; //console textArea = new QTextEdit(); QFont font; font.setFamily("Courier"); font.setStyleHint(QFont::Monospace); font.setFixedPitch(true); font.setPointSize(10); textArea->setFont(font); textArea->setReadOnly(true); this->addTab(textArea, "Console"); //errorlist errorList = new QListWidget(); this->addTab(errorList, "Errors"); //tabwidget QPalette Pal(palette()); Pal.setColor(QPalette::Background, "#323232"); setAutoFillBackground(true); setPalette(Pal); setStyleSheet("QTextEdit, QListWidget { color: white; background-color: #2D2D2F; border-style: solid; border-width: 1px; border-color: black; } QTabWidget::pane { background-color: #2D2D2F; } QTabBar::tab { color: white; background-color: #2D2D2F; border-style: solid; border-width: 1px; border-color: black; padding: 3px;} QTabBar::tab:selected { background-color: black; }"); connect(errorList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(errorListItemDoubleClicked(QListWidgetItem*))); connect(this, SIGNAL(stdOut(QString)), this, SLOT(onStdOut(QString))); createRedirector(); }
void SynchronousProcess::processStdOut(bool emitSignals) { // Handle binary data const QByteArray ba = m_d->m_process.readAllStandardOutput(); if (debug > 1) { qDebug() << Q_FUNC_INFO << emitSignals << ba; } if (!ba.isEmpty()) { m_d->m_stdOut.data += ba; if (emitSignals) { // Emit binary signals emit stdOut(ba, m_d->m_stdOut.firstData); m_d->m_stdOut.firstData = false; // Buffered. Emit complete lines? if (m_d->m_stdOut.bufferedSignalsEnabled) { const QByteArray lines = m_d->m_stdOut.linesRead(); if (!lines.isEmpty()) { emit stdOutBuffered(convertStdOut(lines), m_d->m_stdOut.firstBuffer); m_d->m_stdOut.firstBuffer = false; } } } } }
manViever::manViever(QWidget *parent) : QWidget(parent) { lneSearch = new QLineEdit; lneSearch->setText(""); txtMan = new QTextEdit; txtMan->setText(""); txtMan->setReadOnly(true); btnSearch = new QPushButton; btnSearch->setText("Search"); Hlayout = new QHBoxLayout; Hlayout->addWidget(lneSearch); Hlayout->addWidget(btnSearch); Vlayout = new QVBoxLayout; Vlayout->addLayout(Hlayout); Vlayout->addWidget(txtMan); setLayout(Vlayout); out=""; connect(btnSearch,SIGNAL(clicked()),this,SLOT(startSearch())); connect(lneSearch,SIGNAL(returnPressed()),this,SLOT(startSearch())); connect(&proc,SIGNAL(readyReadStandardOutput()),this,SLOT(stdOut())); connect(&proc,SIGNAL(readyReadStandardError()),this,SLOT(stdErr())); connect(&proc,SIGNAL(finished(int ,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus))); }
bool KPBinaryIface::checkDir(const QString& possibleDir) { bool ret = false; QString possiblePath = path(possibleDir); kDebug() << "Testing " << possiblePath << "..."; QProcess process; process.setProcessChannelMode(QProcess::MergedChannels); process.start(possiblePath, m_binaryArguments); bool val = process.waitForFinished(); if (val && (process.error() != QProcess::FailedToStart)) { m_isFound = true; QString stdOut(process.readAllStandardOutput()); if (parseHeader(stdOut)) { m_pathDir = possibleDir; writeConfig(); kDebug() << "Found " << path() << " version: " << version(); ret = true; } else { // TODO: do something if the version is not right or not found } } emit signalBinaryValid(); return ret; }
void PythonEngine::init() { m_isRunning = false; m_stdOut = ""; // connect stdout connect(this, SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); // init python Py_Initialize(); // read functions m_functions = readFileContent(datadir() + "/functions.py"); m_dict = PyDict_New(); PyDict_SetItemString(m_dict, "__builtins__", PyEval_GetBuiltins()); // init engine extensions Py_InitModule("pythonlab", pythonEngineFuntions); addCustomExtensions(); // custom modules PyRun_String(QString("import sys; sys.path.insert(0, \"" + datadir() + "/resources/python" + "\")").toStdString().c_str(), Py_file_input, m_dict, m_dict); // functions.py PyRun_String(m_functions.toStdString().c_str(), Py_file_input, m_dict, m_dict); }
void PythonQtScriptingConsole::flushStdOut() { if (!_stdOut.isEmpty()) { stdOut("\n"); } if (!_stdErr.isEmpty()) { stdErr("\n"); } }
ShapeKnotsProcess::ShapeKnotsProcess(QObject *parent) : QProcess(parent) { connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(stdOut())); connect(this, SIGNAL(readyReadStandardError()), this, SLOT(stdErr())); connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(terminate())); }
void milxQtPythonConsole::flushStdOut() { if (!_stdOut.isEmpty()) { stdOut("\n"); } if (!_stdErr.isEmpty()) { stdErr("\n"); } }
void valid(const FileUnit& file) { bf::ifstream strm; const auto result=bomUtf8Check(file, strm); if(strm.is_open()==false) return; stdOut() << core::WCharConverter::to(file.total.string()) << (result.second ? ": valid" : ": invalid") << std::endl; }
void CMapQMAPExport::slotCancel() { if(cmd.state() != QProcess::NotRunning) { stdOut(tr("\nCanceled by user's request.\n")); cmd.kill(); cmd.waitForFinished(1000); } else { reject(); } }
Profiler::~Profiler() { QString fileName = QString("callgrind.%1.out").arg(QCoreApplication::applicationPid()); QTextStream stdOut(stdout); stdOut << "===" << fileName << "===" << endl; QFile file(fileName); file.open(QFile::ReadWrite); QTextStream out(&file); out << "creator: " << QCoreApplication::applicationName() << endl; out << "positions: line" << endl; out << "events: microseconds" << endl; out << endl; QHashIterator<int, Object> i(objects); while (i.hasNext()) { i.next(); Object *object = &objects[i.key()]; for (int j = 0; j < object->functions.count(); ++j) { out << "fl=" << (object->fileName.isEmpty() ? "native" : object->fileName) << endl; out << "fn=" << (object->functions[j].functionName.isEmpty() ? (QString("native_") + object->functions[j].startLine) : object->functions[j].functionName) << endl; int curLine = -1; for (int k = 0; k < objects[i.key()].functions[j].actions.count(); ++k) { const Action *action = &(objects[i.key()].functions.at(j).actions[k]); if (action->called != 0) { out << "cfl=" << objects[action->callObject].fileName << endl; out << "cfn=" << action->callFunction << endl; out << "calls=" << action->called << " " << action->callFunctionLine /*action->line*/ << endl; } if (curLine == -1) { out << action->line; } else { if (action->line == curLine) out << "*"; if (action->line > curLine) out << "+" << action->line - curLine; if (action->line < curLine) out << "-" << curLine - action->line; } out << " " << action->cost << endl; curLine = action->line; } out << endl; } } }
void doit() { const auto& vm=mapGet(); auto& files=fileGet(); files.init(vm); files.loop([this](FileUnit&& fu) { if(fu.isExist()==false || fu.isDir()) return false; bf::ifstream in(fu.total.path(), std::ios::in | std::ios::binary); if(!in) return false; core::MD5Compute md5; std::vector<char> buf(4*1024); size_t totalSize = 0; for(;;) { in.read(buf.data(), buf.size()); auto const count=static_cast<int>(in.gcount()); if (count <= 0) break; totalSize += count; md5.append(reinterpret_cast<const uint8_t*>(buf.data()), count); } md5.finish(); const auto& md5sum=md5.sumGet(); stdOut() << fu.self << " " << md5sum.toString() << std::endl; return errorBreak()==false; } ); }
void AgrosSolver::runSuite() { // log stdout if (m_enableLog) m_log = new LogStdOut(); // silent mode setSilentMode(true); connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString))); QString testSuite = QString("from test_suite.scenario import run_suite; run_suite(test_suite.test_%1)").arg(m_suiteName); qDebug() << testSuite; bool successfulRun= currentPythonEngineAgros()->runScript(testSuite); if (successfulRun) { Agros2D::scene()->clear(); Agros2D::clear(); QApplication::exit(0); } else { ErrorResult result = currentPythonEngineAgros()->parseError(); Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n"). arg(result.error()). arg(result.line()). arg(result.traceback())); QApplication::exit(-1); } }
void AgrosSolver::runCommand() { // log stdout if (m_enableLog) m_log = new LogStdOut(); QTime time; time.start(); // silent mode setSilentMode(true); connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString))); connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString))); bool successfulRun= currentPythonEngineAgros()->runScript(m_command, m_fileName); if (successfulRun) { Agros2D::log()->printMessage(tr("Solver"), tr("Problem was solved in %1").arg(milisecondsToTime(time.elapsed()).toString("mm:ss.zzz"))); Agros2D::scene()->clear(); Agros2D::clear(); QApplication::exit(0); } else { ErrorResult result = currentPythonEngineAgros()->parseError(); Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n"). arg(result.error()). arg(result.line()). arg(result.traceback())); QApplication::exit(-1); } }
// Data available in the standard stream void OctaveBind::readyStdOut() { QByteArray aux; aux = octaveProcess.readAllStandardOutput(); stdOutput += aux; buffer += aux; // Search for end of output (OCTAVE_PROMPT) if(buffer.trimmed().endsWith(OCTAVE_PROMPT)) { // Remove prompt buffer = buffer.trimmed(); buffer.chop(QString(OCTAVE_PROMPT).length()); buffer = buffer.trimmed(); // What we want depends of the status QRegExp regExp; int pos; switch(status) { // Installation prefix case OctaveBind::WaitingPrefix | OctaveBind::Initializing: case OctaveBind::WaitingPrefix: // Get prefix regExp.setPattern("Installation prefix:\\s+(\\S+)"); if(regExp.indexIn(buffer) > -1) { installPath = regExp.cap(1); std::cout << "[OctaveBind::readyStdOut()] Installation prefix: '" << installPath.toLocal8Bit().constData() << "'" << std::endl; }else std::cerr << "[OctaveBind::readyStdOut()] Wrong prefix format" << std::endl; // If we are initializing, ask for installed packages if(status == (OctaveBind::WaitingPrefix | OctaveBind::Initializing)) { status = OctaveBind::Ready; getInstalledPackages(true); }else status = OctaveBind::Ready; break; // Waiting packages case OctaveBind::WaitingPackages: installedPackages.clear(); regExp.setPattern("\\s*(\\w+)\\s*\\*?\\|\\s*(\\d+)\\.(\\d+)\\.(\\d+)\\s*\\|\\s*(\\S+)"); pos = 0; while((pos = regExp.indexIn(buffer, pos)) != -1) { Package pack; pack.name = regExp.cap(1); pack.vMajor = regExp.cap(2).toInt(); pack.vMinor = regExp.cap(3).toInt(); pack.vRevision = regExp.cap(4).toInt(); pack.url = regExp.cap(5); pack.installed = true; installedPackages.append(pack); pos += regExp.matchedLength(); } status = OctaveBind::Ready; break; // Install or remove case OctaveBind::Removing: case OctaveBind::Installing: status = OctaveBind::Ready; getInstalledPackages(true); break; // Unknown default: std::cerr << "[OctaveBind::readyStdOut()] Unknow or invalid status" << std::endl; status = OctaveBind::Ready; } // Signals emit stdOut(); emit success(); // Clear buffer.clear(); stdOutput.clear(); }else { // Signals emit stdOut(); } }
/** Parses iperf output */ void MwtsIPerfThroughput::ParseOutput() { MWTS_ENTER; // Grab stdout and stderr QByteArray stdOutBytes = m_pProcess->readAllStandardOutput(); QByteArray stdErrBytes = m_pProcess->readAllStandardError(); qDebug() << "stdout: " << stdOutBytes; qDebug() << "stderr: " << stdErrBytes; double tempSpeed = 0; double downSpeed = 0; int iBidirectionalStep = 1; QString stdOut( stdOutBytes ); if ( stdOut.length() > 0 ) { // If we were running an iterative cases, measurements for iterations are on their own lines int i = 0; QStringList lines = stdOut.split("\n"); for (i = 0; i < lines.length(); i++ ) { // bidirectional troughputs have two results, upload and download if(m_pIperfRole == IPERF_BICLIENT) { qDebug() << "Measuring bidirectional troughput...."; // Output format will be one line of comma-separated values, in the order as follows // (Date and time),(Local IP),(Local port),(Remote IP),(Remote port),(ID),(Start time-End time),(Bytes transferred),(Speed, format depends on options) QStringList parts = lines[i].split( QChar( ',' ) ); if ( parts.size() < 9 ) { qDebug() << "Not enough data was outputted."; break; } QDateTime dateTime = QDateTime::fromString( parts.at( 0 ).trimmed(), QString( "yyyyMMddHHmmss" ) ); qDebug() << "Date & time: " << dateTime.toString( Qt::TextDate ); qDebug() << "Local IP & port: " << parts.at( 1 ).trimmed() << ":" << parts.at( 2 ).trimmed(); qDebug() << "Remote IP & port: " << parts.at( 3 ).trimmed() << ":" << parts.at( 4 ).trimmed(); qDebug() << "ID: " << parts.at( 5 ).trimmed(); qDebug() << "Time slice: " << parts.at( 6 ).trimmed(); qDebug() << "Bytes transferred: " << parts.at( 7 ).trimmed(); qDebug() << "Tranfer speed (bits/second): " << parts.at( 8 ).trimmed(); // Calculate the speed, (From bits/second to Mbits/second) bool ok = false; double speed = parts.at( 8 ).trimmed().toULong( &ok ); if ( ok == true ) { // step two means we have both upload and download troughputs if(iBidirectionalStep == 2) { iBidirectionalStep = 1; downSpeed = speed / 1000.0 / 1000.0; qDebug() << "speed up " << tempSpeed; qDebug() << "speed down " << downSpeed; g_pResult->AddMeasure( "Download", downSpeed, "Mbits per second" ); if( downSpeed == 0 ) { g_pResult->Write( "Download speed is 0, iperf probably not running in the other end" ); g_pResult->StepPassed( "Throughput", false ); m_pReturnValue = false; } else { g_pResult->StepPassed( "Throughput", true ); m_pReturnValue = true; } break; } // save this value for the step two tempSpeed = speed / 1000.0 / 1000.0; iBidirectionalStep++; } else { g_pResult->Write( "Failed to convert speed from string to double!" ); g_pResult->StepPassed( "Throughput", false ); m_pReturnValue = false; } } // normal case, not bidirectional else { // Output format will be one line of comma-separated values, in the order as follows // (Date and time),(Local IP),(Local port),(Remote IP),(Remote port),(ID),(Start time-End time),(Bytes transferred),(Speed, format depends on options) QStringList parts = lines[i].split( QChar( ',' ) ); if ( parts.size() < 9 ) { qDebug() << "Not enough data was outputted."; break; } QDateTime dateTime = QDateTime::fromString( parts.at( 0 ).trimmed(), QString( "yyyyMMddHHmmss" ) ); qDebug() << "Date & time: " << dateTime.toString( Qt::TextDate ); qDebug() << "Local IP & port: " << parts.at( 1 ).trimmed() << ":" << parts.at( 2 ).trimmed(); qDebug() << "Remote IP & port: " << parts.at( 3 ).trimmed() << ":" << parts.at( 4 ).trimmed(); qDebug() << "ID: " << parts.at( 5 ).trimmed(); qDebug() << "Time slice: " << parts.at( 6 ).trimmed(); qDebug() << "Bytes transferred: " << parts.at( 7 ).trimmed(); qDebug() << "Tranfer speed (bits/second): " << parts.at( 8 ).trimmed(); // Calculate the speed, (From bits/second to Mbits/second) bool ok = false; double speed = parts.at( 8 ).trimmed().toULong( &ok ); if ( ok == true ) { double speedMbits = speed / 1000.0 / 1000.0; qDebug() << "speed up " << speedMbits; g_pResult->AddMeasure( "Upload", speedMbits, "Mbits per second" ); if( speedMbits == 0 ) { g_pResult->Write( "Upload speed is 0, iperf probably not running in the other end" ); g_pResult->StepPassed( "Throughput", false ); m_pReturnValue = false; } else { g_pResult->StepPassed( "Throughput", true ); m_pReturnValue = true; } } else { g_pResult->Write( "Failed to convert speed from string to double!" ); g_pResult->StepPassed( "Throughput", false ); m_pReturnValue = false; } } } } else { g_pResult->Write( "Failed to measure throughput!" ); g_pResult->StepPassed( "Throughput", false ); m_pReturnValue = false; } MWTS_LEAVE; }