From e5f8dab5b800975b8aa13b4f40bf79b0a26f5f7e Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 6 Jan 2025 10:46:54 +0800 Subject: [PATCH] fix: [python] Package not updated when switching interpreter as title Log: fix bug Bug: https://pms.uniontech.com/bug-view-298501.html --- .../python/python/option/interpreterwidget.cpp | 11 +++++------ src/plugins/python/python/option/interpreterwidget.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/python/python/option/interpreterwidget.cpp b/src/plugins/python/python/option/interpreterwidget.cpp index c0f0d9f4c..8b88ecf1a 100644 --- a/src/plugins/python/python/option/interpreterwidget.cpp +++ b/src/plugins/python/python/option/interpreterwidget.cpp @@ -154,7 +154,7 @@ void InterpreterWidget::setupUi() d->interpreterComboBox = new DComboBox(); d->interpreterComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); QObject::connect(d->interpreterComboBox, &DComboBox::currentTextChanged, - this, &InterpreterWidget::setPackageData); + this, &InterpreterWidget::updatePackageData); d->selectCustomInterpreter = new DPushButton(tr("Browse"), this); d->removeCustomInterpreter = new DPushButton(tr("Remove"), this); @@ -253,12 +253,11 @@ void InterpreterWidget::updateUi() } } -void InterpreterWidget::setPackageData(const QString &text) +void InterpreterWidget::updatePackageData() { - QString cmd = "pip list"; - if (text.indexOf("python3") > -1) { - cmd = "pip3 list"; - } + auto param = qvariant_cast(d->interpreterComboBox->currentData(Qt::UserRole + 1)); + QString cmd = param.path + " -m pip list"; + QtConcurrent::run(this, &InterpreterWidget::findPackages, cmd); } diff --git a/src/plugins/python/python/option/interpreterwidget.h b/src/plugins/python/python/option/interpreterwidget.h index f8be7954a..b866ebb6e 100644 --- a/src/plugins/python/python/option/interpreterwidget.h +++ b/src/plugins/python/python/option/interpreterwidget.h @@ -68,7 +68,7 @@ public slots: bool getControlValue(QMap &map); void setControlValue(const QMap &map); - void setPackageData(const QString &text); + void updatePackageData(); void findPackages(const QString &cmd); InterpreterWidgetPrivate *const d;