| 28 | } |
| 29 | |
| 30 | QString PathUtils::GetPythonExecutablePath() { |
| 31 | // Try to find Python in NDK first |
| 32 | if (!ndkPath_.isEmpty() && QFile::exists(ndkPath_)) { |
| 33 | QString pythonPath; |
| 34 | #if defined(Q_OS_WIN) |
| 35 | pythonPath = ndkPath_ + "/prebuilt/windows-x86_64/bin/python.exe"; |
| 36 | #elif defined(Q_OS_MACOS) |
| 37 | pythonPath = ndkPath_ + "/prebuilt/darwin-x86_64/bin/python"; |
| 38 | #elif defined(Q_OS_LINUX) |
| 39 | pythonPath = ndkPath_ + "/prebuilt/linux-x86_64/bin/python"; |
| 40 | #endif |
| 41 | if (QFile::exists(pythonPath)) |
| 42 | return pythonPath; |
| 43 | } |
| 44 | |
| 45 | // Fallback to user-specified Python path |
| 46 | if (!pythonPath_.isEmpty() && QFile::exists(pythonPath_)) { |
| 47 | return pythonPath_; |
| 48 | } |
| 49 | |
| 50 | #ifndef NO_GUI_MODE |
| 51 | // If fallback path doesn't exist or is not set, prompt user to select Python 2.x |
| 52 | QMessageBox msgBox; |
| 53 | msgBox.setIcon(QMessageBox::Warning); |
| 54 | msgBox.setWindowTitle("Python Not Found"); |
| 55 | msgBox.setText("Python executable not found in NDK."); |
| 56 | msgBox.setInformativeText("Please select a Python 2.x (e.g., Python 2.7) executable for the application to use."); |
| 57 | msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
| 58 | msgBox.setDefaultButton(QMessageBox::Ok); |
| 59 | |
| 60 | if (msgBox.exec() == QMessageBox::Ok) { |
| 61 | QString selectedPath = QFileDialog::getOpenFileName( |
| 62 | nullptr, |
| 63 | "Select Python 2.x Executable", |
| 64 | QString(), |
| 65 | #if defined(Q_OS_WIN) |
| 66 | "Executable Files (*.exe);;All Files (*.*)" |
| 67 | #else |
| 68 | "All Files (*)" |
| 69 | #endif |
| 70 | ); |
| 71 | |
| 72 | if (!selectedPath.isEmpty() && QFile::exists(selectedPath)) { |
| 73 | pythonPath_ = selectedPath; |
| 74 | SavePythonPathSettings(); |
| 75 | return pythonPath_; |
| 76 | } |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | return QString(); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | namespace { |