Skip to content

Commit

Permalink
fix: [python] Python interpreter
Browse files Browse the repository at this point in the history
Some python interpreters are not visible in the `Project Properties Dialog`

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Dec 17, 2024
1 parent a7c4512 commit d6bffe8
Showing 1 changed file with 16 additions and 19 deletions.
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

0 comments on commit d6bffe8

Please sign in to comment.