Skip to content

Commit

Permalink
Refactor terminal command execution in visMainWindow to use startComm…
Browse files Browse the repository at this point in the history
…and for improved readability
  • Loading branch information
dongzgh committed Feb 15, 2025
1 parent 7f1844d commit da711ca
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/visMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,29 +648,31 @@ void visMainWindow::sendToPython() {
QString command = QString("%1 %2").arg(startFileName).arg(pyFileName);
QString script = QString("osascript -e 'tell application \"Terminal\" to do script \"" + command + "\"'");
qDebug() << script;
process.start("osascript", QStringList() << "-e" << "tell application \"Terminal\" to do script \"" + command + "\"");
process.startCommand(script);
}
else {
// Run Python script.
QString command = "python " + pyFileName;
QString script = "osascript -e 'tell application \"Terminal\" to do script \"" + command + "\"'";
qDebug() << script;
process.start("osascript", QStringList() << "-e" << "tell application \"Terminal\" to do script \"" + command + "\"");
process.startCommand(script);
}
#elif defined(__linux__)
// Check if virtual environment exists.
QString startFileName = QDir(dir).absoluteFilePath("scripts/run-python.sh");
if (QFileInfo(startFileName).exists()) {
// Activate virtual environment and run Python script.
QString command = QString("%1 %2").arg(startFileName).arg(pyFileName);
qDebug() << "gnome-terminal -- bash -c \"" << command << "; exec bash\"";
process.start("gnome-terminal", QStringList() << "--" << "bash" << "-c" << command + "; exec bash");
QString script = QString("gnome-terminal -- bash -c \"") + command + "; exec bash\"";
qDebug() << script;
process.startCommand(script);
}
else {
// Run Python script.
QString command = "python3 " + pyFileName;
qDebug() << "gnome-terminal -- bash -c \"" << command << "; exec bash\"";
process.start("gnome-terminal", QStringList() << "--" << "bash" << "-c" << command + "; exec bash");
QString script = QString("gnome-terminal -- bash -c \"") + command + "; exec bash\"";
qDebug() << script;
process.startCommand(script);
}
#endif

Expand Down

0 comments on commit da711ca

Please sign in to comment.