diff options
| author | David Schulz <david.schulz@qt.io> | 2023-11-01 15:05:03 +0100 |
|---|---|---|
| committer | David Schulz <david.schulz@qt.io> | 2023-11-28 12:17:14 +0000 |
| commit | 09e94ae4ac040ad313b7b86e62489dee7cd3804a (patch) | |
| tree | 1e907c076ba18b326b413ed5ac551db4a3e5e380 /src/plugins/python/pythonwizardpage.cpp | |
| parent | 12428bf1d67bd282c5276383c91d968451b44036 (diff) | |
Python: use kits page in python wizards
Change-Id: I1f7aaf145443481546abb868c8c167186600b848
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonwizardpage.cpp')
| -rw-r--r-- | src/plugins/python/pythonwizardpage.cpp | 108 |
1 files changed, 2 insertions, 106 deletions
diff --git a/src/plugins/python/pythonwizardpage.cpp b/src/plugins/python/pythonwizardpage.cpp index 8b631e2c414..dc4895eb3e0 100644 --- a/src/plugins/python/pythonwizardpage.cpp +++ b/src/plugins/python/pythonwizardpage.cpp @@ -4,6 +4,7 @@ #include "pythonwizardpage.h" #include "pythonconstants.h" +#include "pythonkitaspect.h" #include "pythonsettings.h" #include "pythontr.h" @@ -14,6 +15,7 @@ #include <utils/mimeutils.h> #include <utils/qtcassert.h> +#include <projectexplorer/kitmanager.h> #include <projectexplorer/project.h> #include <projectexplorer/projectmanager.h> #include <projectexplorer/target.h> @@ -86,11 +88,6 @@ PythonWizardPage::PythonWizardPage(const QList<QPair<QString, QVariant>> &pySide const int defaultPyside) { using namespace Layouting; - m_interpreter.setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID); - connect(PythonSettings::instance(), - &PythonSettings::interpretersChanged, - this, - &PythonWizardPage::updateInterpreters); m_pySideVersion.setLabelText(Tr::tr("PySide version:")); m_pySideVersion.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox); @@ -99,49 +96,13 @@ PythonWizardPage::PythonWizardPage(const QList<QPair<QString, QVariant>> &pySide if (defaultPyside >= 0) m_pySideVersion.setDefaultValue(defaultPyside); - m_createVenv.setLabelText(Tr::tr("Create new virtual environment")); - - m_venvPath.setLabelText(Tr::tr("Path to virtual environment:")); - m_venvPath.setEnabler(&m_createVenv); - m_venvPath.setExpectedKind(PathChooser::Directory); - - m_stateLabel = new InfoLabel(); - m_stateLabel->setWordWrap(true); - m_stateLabel->setFilled(true); - m_stateLabel->setType(InfoLabel::Error); - connect(&m_venvPath, &FilePathAspect::validChanged, this, &PythonWizardPage::updateStateLabel); - connect(&m_createVenv, &BaseAspect::changed, this, &PythonWizardPage::updateStateLabel); - Form { m_pySideVersion, st, br, - m_interpreter, st, br, - m_createVenv, st, br, - m_venvPath, br, - m_stateLabel, br }.attachTo(this); } -void PythonWizardPage::initializePage() -{ - auto wiz = qobject_cast<JsonWizard *>(wizard()); - QTC_ASSERT(wiz, return); - connect(wiz, &JsonWizard::filesPolished, - this, &PythonWizardPage::setupProject, - Qt::UniqueConnection); - - const FilePath projectDir = FilePath::fromString(wiz->property("ProjectDirectory").toString()); - m_createVenv.setValue(!projectDir.isEmpty()); - if (m_venvPath().isEmpty()) - m_venvPath.setValue(projectDir.isEmpty() ? FilePath{} : projectDir / "venv"); - - updateInterpreters(); - updateStateLabel(); -} - bool PythonWizardPage::validatePage() { - if (m_createVenv() && !m_venvPath.pathChooser()->isValid()) - return false; auto wiz = qobject_cast<JsonWizard *>(wizard()); const QMap<QString, QVariant> data = m_pySideVersion.itemValue().toMap(); for (auto it = data.begin(), end = data.end(); it != end; ++it) @@ -149,70 +110,5 @@ bool PythonWizardPage::validatePage() return true; } -void PythonWizardPage::setupProject(const JsonWizard::GeneratorFiles &files) -{ - for (const JsonWizard::GeneratorFile &f : files) { - if (f.file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { - Interpreter interpreter = m_interpreter.currentInterpreter(); - Project *project = ProjectManager::openProject(Utils::mimeTypeForFile(f.file.filePath()), - f.file.filePath().absoluteFilePath()); - if (m_createVenv()) { - auto openProjectWithInterpreter = [f](const std::optional<Interpreter> &interpreter) { - if (!interpreter) - return; - Project *project = ProjectManager::projectWithProjectFilePath(f.file.filePath()); - if (!project) - return; - if (Target *target = project->activeTarget()) { - if (RunConfiguration *rc = target->activeRunConfiguration()) { - if (auto interpreters = rc->aspect<InterpreterAspect>()) - interpreters->setCurrentInterpreter(*interpreter); - } - } - }; - PythonSettings::createVirtualEnvironment(m_venvPath(), - interpreter, - openProjectWithInterpreter, - project ? project->displayName() - : QString{}); - } - - if (project) { - project->addTargetForDefaultKit(); - if (Target *target = project->activeTarget()) { - if (RunConfiguration *rc = target->activeRunConfiguration()) { - if (auto interpreters = rc->aspect<InterpreterAspect>()) { - interpreters->setCurrentInterpreter(interpreter); - project->saveSettings(); - } - } - } - delete project; - } - } - } -} - -void PythonWizardPage::updateInterpreters() -{ - m_interpreter.setDefaultInterpreter(PythonSettings::defaultInterpreter()); - m_interpreter.updateInterpreters(PythonSettings::interpreters()); -} - -void PythonWizardPage::updateStateLabel() -{ - QTC_ASSERT(m_stateLabel, return); - if (m_createVenv()) { - if (PathChooser *pathChooser = m_venvPath.pathChooser()) { - if (!pathChooser->isValid()) { - m_stateLabel->show(); - m_stateLabel->setText(pathChooser->errorMessage()); - return; - } - } - } - m_stateLabel->hide(); -} - } // namespace Python::Internal |
