Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [python] Python interpreter #1020

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DetailPropertyWidgetPrivate
friend class DetailPropertyWidget;
DComboBox *pyVersionComboBox { nullptr };
DComboBox *executeFileComboBox { nullptr };
DCheckBox *runInTerminal {nullptr};
DCheckBox *runInTerminal { nullptr };
};

DetailPropertyWidget::DetailPropertyWidget(QWidget *parent)
Expand Down Expand Up @@ -95,22 +95,22 @@ QList<QString> findAll(QString pattern, QString str, bool Greedy)
return strList;
}

QStringList getPythonAllVersion()
ToolChainData::Params getSystemPython()
{
QDir dir("/usr/bin");
QStringList filter { "Python*.*" };
dir.setNameFilters(filter);
QStringList pythonList = dir.entryList();

QString pattern = "((\\d)|(\\d+.\\d+))($|\\s)";
QStringList versions = findAll(pattern, pythonList.join(" "), true);
ToolChainData tcData;
QString retMsg;
if (!tcData.readToolChainData(retMsg)) {
qWarning() << retMsg;
return {};
}

return versions;
const auto &toolChains = tcData.getToolChanins();
return toolChains.value(kPython);
}

void DetailPropertyWidget::initData()
{
QVariant interpreterConfig = OptionManager::getInstance()->getValue(option::CATEGORY_PYTHON, {"Interpreter"});
QVariant interpreterConfig = OptionManager::getInstance()->getValue(option::CATEGORY_PYTHON, "Interpreter");
QVariantList variantList = interpreterConfig.toMap().value("customInterpreters").toList();
QList<ToolChainData::ToolChainParam> customInterpreters;

Expand All @@ -122,16 +122,13 @@ void DetailPropertyWidget::initData()
customInterpreters.append(interpreter);
}

auto systemPythonVersions = getPythonAllVersion();
const auto &systemPython = getSystemPython();
int index = 0;
for (auto version : systemPythonVersions) {
ToolChainData::ToolChainParam param;
param.name = QString("python%1").arg(version);
param.path = "/usr/bin/" + param.name;
QString text = param.name + "(" + param.path + ")";
for (const auto &python : systemPython) {
QString text = python.name + "(" + python.path + ")";
d->pyVersionComboBox->insertItem(index, text);
d->pyVersionComboBox->setItemData(index, QVariant::fromValue(param), Qt::UserRole + 1);
if (param.path == globalToolPath)
d->pyVersionComboBox->setItemData(index, QVariant::fromValue(python), Qt::UserRole + 1);
if (python.path == globalToolPath)
d->pyVersionComboBox->setCurrentIndex(index);
index++;
}
Expand Down
Loading