forked from qt-creator/qt-creator
Python: add interpreter selector to the python project wizard
Change-Id: I7ea1df34fa0096a84a0d611b401f991508c826c1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -26,20 +26,28 @@
|
|||||||
{
|
{
|
||||||
"trDisplayName": "Define Project Details",
|
"trDisplayName": "Define Project Details",
|
||||||
"trShortTitle": "Details",
|
"trShortTitle": "Details",
|
||||||
"typeId": "Fields",
|
"typeId": "PythonConfiguration",
|
||||||
"data" :
|
"data":
|
||||||
[
|
{
|
||||||
{
|
"index": 0,
|
||||||
"name": "PySideVersion",
|
"items":
|
||||||
"trDisplayName": "PySide version:",
|
[
|
||||||
"type": "ComboBox",
|
|
||||||
"data":
|
|
||||||
{
|
{
|
||||||
"index": 1,
|
"trKey": "PySide 6",
|
||||||
"items": [ "PySide2", "PySide6" ]
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"trKey": "PySide 2",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"trDisplayName": "Project Management",
|
"trDisplayName": "Project Management",
|
||||||
|
|||||||
@@ -30,16 +30,6 @@
|
|||||||
"typeId": "Fields",
|
"typeId": "Fields",
|
||||||
"data" :
|
"data" :
|
||||||
[
|
[
|
||||||
{
|
|
||||||
"name": "PySideVersion",
|
|
||||||
"trDisplayName": "PySide version:",
|
|
||||||
"type": "ComboBox",
|
|
||||||
"data":
|
|
||||||
{
|
|
||||||
"index": 1,
|
|
||||||
"items": [ "PySide2", "PySide6" ]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Class",
|
"name": "Class",
|
||||||
"trDisplayName": "Class name:",
|
"trDisplayName": "Class name:",
|
||||||
@@ -77,6 +67,32 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"trDisplayName": "Define Project Details",
|
||||||
|
"trShortTitle": "Details",
|
||||||
|
"typeId": "PythonConfiguration",
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"items":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"trKey": "PySide 6",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"trKey": "PySide 2",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"trDisplayName": "Project Management",
|
"trDisplayName": "Project Management",
|
||||||
"trShortTitle": "Summary",
|
"trShortTitle": "Summary",
|
||||||
|
|||||||
@@ -30,67 +30,59 @@
|
|||||||
{
|
{
|
||||||
"trDisplayName": "Define Project Details",
|
"trDisplayName": "Define Project Details",
|
||||||
"trShortTitle": "Details",
|
"trShortTitle": "Details",
|
||||||
"typeId": "Fields",
|
"typeId": "PythonConfiguration",
|
||||||
"data":
|
"data":
|
||||||
[
|
{
|
||||||
{
|
"index": 0,
|
||||||
"name": "QtVersion",
|
"items":
|
||||||
"trDisplayName": "PySide version:",
|
[
|
||||||
"type": "ComboBox",
|
|
||||||
"data":
|
|
||||||
{
|
{
|
||||||
"index": 0,
|
"trKey": "PySide 6",
|
||||||
"items":
|
"value":
|
||||||
[
|
{
|
||||||
{
|
"QtQuickVersion": "",
|
||||||
"trKey": "PySide 6",
|
"QtQuickWindowVersion": "",
|
||||||
"value":
|
"PySideVersion": "PySide6"
|
||||||
{
|
}
|
||||||
"QtQuickVersion": "",
|
},
|
||||||
"QtQuickWindowVersion": "",
|
{
|
||||||
"PySideVersion": "PySide6"
|
"trKey": "PySide 5.15",
|
||||||
}
|
"value":
|
||||||
},
|
{
|
||||||
{
|
"QtQuickVersion": "2.15",
|
||||||
"trKey": "PySide 5.15",
|
"QtQuickWindowVersion": "2.15",
|
||||||
"value":
|
"PySideVersion": "PySide2"
|
||||||
{
|
}
|
||||||
"QtQuickVersion": "2.15",
|
},
|
||||||
"QtQuickWindowVersion": "2.15",
|
{
|
||||||
"PySideVersion": "PySide2"
|
"trKey": "PySide 5.14",
|
||||||
}
|
"value":
|
||||||
},
|
{
|
||||||
{
|
"QtQuickVersion": "2.14",
|
||||||
"trKey": "PySide 5.14",
|
"QtQuickWindowVersion": "2.14",
|
||||||
"value":
|
"PySideVersion": "PySide2"
|
||||||
{
|
}
|
||||||
"QtQuickVersion": "2.14",
|
},
|
||||||
"QtQuickWindowVersion": "2.14",
|
{
|
||||||
"PySideVersion": "PySide2"
|
"trKey": "PySide 5.13",
|
||||||
}
|
"value":
|
||||||
},
|
{
|
||||||
{
|
"QtQuickVersion": "2.13",
|
||||||
"trKey": "PySide 5.13",
|
"QtQuickWindowVersion": "2.13",
|
||||||
"value":
|
"PySideVersion": "PySide2"
|
||||||
{
|
}
|
||||||
"QtQuickVersion": "2.13",
|
},
|
||||||
"QtQuickWindowVersion": "2.13",
|
{
|
||||||
"PySideVersion": "PySide2"
|
"trKey": "PySide 5.12",
|
||||||
}
|
"value":
|
||||||
},
|
{
|
||||||
{
|
"QtQuickVersion": "2.12",
|
||||||
"trKey": "PySide 5.12",
|
"QtQuickWindowVersion": "2.12",
|
||||||
"value":
|
"PySideVersion": "PySide2"
|
||||||
{
|
}
|
||||||
"QtQuickVersion": "2.12",
|
|
||||||
"QtQuickWindowVersion": "2.12",
|
|
||||||
"PySideVersion": "PySide2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"trDisplayName": "Project Management",
|
"trDisplayName": "Project Management",
|
||||||
|
|||||||
@@ -30,16 +30,6 @@
|
|||||||
"typeId": "Fields",
|
"typeId": "Fields",
|
||||||
"data" :
|
"data" :
|
||||||
[
|
[
|
||||||
{
|
|
||||||
"name": "PySideVersion",
|
|
||||||
"trDisplayName": "PySide version:",
|
|
||||||
"type": "ComboBox",
|
|
||||||
"data":
|
|
||||||
{
|
|
||||||
"index": 1,
|
|
||||||
"items": [ "PySide2", "PySide6" ]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Class",
|
"name": "Class",
|
||||||
"trDisplayName": "Class name:",
|
"trDisplayName": "Class name:",
|
||||||
@@ -77,6 +67,32 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"trDisplayName": "Define Python Interpreter",
|
||||||
|
"trShortTitle": "Interpreter",
|
||||||
|
"typeId": "PythonConfiguration",
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"items":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"trKey": "PySide 6",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"trKey": "PySide 2",
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"PySideVersion": "PySide2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"trDisplayName": "Project Management",
|
"trDisplayName": "Project Management",
|
||||||
"trShortTitle": "Summary",
|
"trShortTitle": "Summary",
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ add_qtc_plugin(Python
|
|||||||
pythonscanner.cpp pythonscanner.h
|
pythonscanner.cpp pythonscanner.h
|
||||||
pythonsettings.cpp pythonsettings.h
|
pythonsettings.cpp pythonsettings.h
|
||||||
pythonutils.cpp pythonutils.h
|
pythonutils.cpp pythonutils.h
|
||||||
|
pythonwizardpage.cpp pythonwizardpage.h
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ QtcPlugin {
|
|||||||
"pythontr.h",
|
"pythontr.h",
|
||||||
"pythonutils.cpp",
|
"pythonutils.cpp",
|
||||||
"pythonutils.h",
|
"pythonutils.h",
|
||||||
|
"pythonwizardpage.cpp",
|
||||||
|
"pythonwizardpage.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@
|
|||||||
#include "pysidebuildconfiguration.h"
|
#include "pysidebuildconfiguration.h"
|
||||||
#include "pythoneditor.h"
|
#include "pythoneditor.h"
|
||||||
#include "pythonproject.h"
|
#include "pythonproject.h"
|
||||||
#include "pythonsettings.h"
|
|
||||||
#include "pythonrunconfiguration.h"
|
#include "pythonrunconfiguration.h"
|
||||||
|
#include "pythonsettings.h"
|
||||||
|
#include "pythonwizardpage.h"
|
||||||
|
|
||||||
#include <projectexplorer/buildtargetinfo.h>
|
#include <projectexplorer/buildtargetinfo.h>
|
||||||
|
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
||||||
#include <projectexplorer/localenvironmentaspect.h>
|
#include <projectexplorer/localenvironmentaspect.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
@@ -57,6 +59,7 @@ void PythonPlugin::initialize()
|
|||||||
d = new PythonPluginPrivate;
|
d = new PythonPluginPrivate;
|
||||||
|
|
||||||
ProjectManager::registerProjectType<PythonProject>(PythonMimeType);
|
ProjectManager::registerProjectType<PythonProject>(PythonMimeType);
|
||||||
|
JsonWizardFactory::registerPageFactory(new PythonWizardPageFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonPlugin::extensionsInitialized()
|
void PythonPlugin::extensionsInitialized()
|
||||||
|
|||||||
167
src/plugins/python/pythonwizardpage.cpp
Normal file
167
src/plugins/python/pythonwizardpage.cpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "pythonwizardpage.h"
|
||||||
|
|
||||||
|
#include "pythonconstants.h"
|
||||||
|
#include "pythonsettings.h"
|
||||||
|
#include "pythontr.h"
|
||||||
|
|
||||||
|
#include <coreplugin/generatedfile.h>
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <utils/mimeutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/projectmanager.h>
|
||||||
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace Python::Internal {
|
||||||
|
|
||||||
|
PythonWizardPageFactory::PythonWizardPageFactory()
|
||||||
|
{
|
||||||
|
setTypeIdsSuffix("PythonConfiguration");
|
||||||
|
}
|
||||||
|
|
||||||
|
WizardPage *PythonWizardPageFactory::create(JsonWizard *wizard, Id typeId, const QVariant &data)
|
||||||
|
{
|
||||||
|
Q_UNUSED(wizard)
|
||||||
|
|
||||||
|
QTC_ASSERT(canCreate(typeId), return nullptr);
|
||||||
|
|
||||||
|
auto page = new PythonWizardPage;
|
||||||
|
for (const QVariant &item : data.toMap().value("items").toList()) {
|
||||||
|
const QMap<QString, QVariant> map = item.toMap();
|
||||||
|
const QVariant name = map.value("trKey");
|
||||||
|
if (name.isValid())
|
||||||
|
page->addPySideVersions(name.toString(), map.value("value"));
|
||||||
|
}
|
||||||
|
bool validIndex = false;
|
||||||
|
const int index = data.toMap().value("index").toInt(&validIndex);
|
||||||
|
if (validIndex)
|
||||||
|
page->setDefaultPySideVersions(index);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validItem(const QVariant &item)
|
||||||
|
{
|
||||||
|
QMap<QString, QVariant> map = item.toMap();
|
||||||
|
if (!map.value("trKey").canConvert<QString>())
|
||||||
|
return false;
|
||||||
|
map = map.value("value").toMap();
|
||||||
|
return map.value("PySideVersion").canConvert<QString>();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PythonWizardPageFactory::validateData(Id typeId, const QVariant &data, QString *errorMessage)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(canCreate(typeId), return false);
|
||||||
|
const QList<QVariant> items = data.toMap().value("items").toList();
|
||||||
|
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
if (errorMessage) {
|
||||||
|
*errorMessage = Tr::tr("'data' of a Python wizard page expects a map with 'items' "
|
||||||
|
"containing a list of objects");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils::allOf(items, &validItem)) {
|
||||||
|
if (errorMessage) {
|
||||||
|
*errorMessage = Tr::tr(
|
||||||
|
"An item of Python wizard page data expects a 'trKey' field containing the ui "
|
||||||
|
"visible string for that python version and an field 'value' containing an object "
|
||||||
|
"with a 'PySideVersion' field used for import statements in the python files.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
if (!items.isEmpty() && Utils::allOf(items, &validItem))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PythonWizardPage::PythonWizardPage()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PythonWizardPage::initializePage()
|
||||||
|
{
|
||||||
|
using namespace Utils::Layouting;
|
||||||
|
|
||||||
|
auto wiz = qobject_cast<JsonWizard *>(wizard());
|
||||||
|
QTC_ASSERT(wiz, return);
|
||||||
|
|
||||||
|
updateInterpreters();
|
||||||
|
|
||||||
|
connect(wiz, &JsonWizard::filesPolished, this, &PythonWizardPage::setupProject);
|
||||||
|
|
||||||
|
Grid {
|
||||||
|
m_pySideVersion, br,
|
||||||
|
m_interpreter, br
|
||||||
|
}.attachTo(this, WithoutMargins);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PythonWizardPage::validatePage()
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
wiz->setValue(it.key(), it.value());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PythonWizardPage::addPySideVersions(const QString &name, const QVariant &data)
|
||||||
|
{
|
||||||
|
m_pySideVersion.addOption(SelectionAspect::Option(name, {}, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PythonWizardPage::setDefaultPySideVersions(int index)
|
||||||
|
{
|
||||||
|
m_pySideVersion.setDefaultValue(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PythonWizardPage::setupProject(const JsonWizard::GeneratorFiles &files)
|
||||||
|
{
|
||||||
|
for (const JsonWizard::GeneratorFile &f : files) {
|
||||||
|
if (f.file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
|
||||||
|
Project *project = ProjectManager::openProject(Utils::mimeTypeForFile(f.file.filePath()),
|
||||||
|
f.file.filePath().absoluteFilePath());
|
||||||
|
if (project) {
|
||||||
|
project->addTargetForDefaultKit();
|
||||||
|
if (Target *target = project->activeTarget()) {
|
||||||
|
if (RunConfiguration *rc = target->activeRunConfiguration()) {
|
||||||
|
if (auto interpreters = rc->aspect<InterpreterAspect>()) {
|
||||||
|
interpreters->setCurrentInterpreter(m_interpreter.currentInterpreter());
|
||||||
|
project->saveSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete project;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PythonWizardPage::updateInterpreters()
|
||||||
|
{
|
||||||
|
m_interpreter.setDefaultInterpreter(PythonSettings::defaultInterpreter());
|
||||||
|
m_interpreter.updateInterpreters(PythonSettings::interpreters());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Python::Internal
|
||||||
|
|
||||||
42
src/plugins/python/pythonwizardpage.h
Normal file
42
src/plugins/python/pythonwizardpage.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include <projectexplorer/jsonwizard/jsonwizard.h>
|
||||||
|
#include <projectexplorer/jsonwizard/jsonwizardpagefactory.h>
|
||||||
|
#include <projectexplorer/runconfigurationaspects.h>
|
||||||
|
|
||||||
|
#include <utils/aspects.h>
|
||||||
|
#include <utils/wizardpage.h>
|
||||||
|
|
||||||
|
namespace Python::Internal {
|
||||||
|
|
||||||
|
class PythonWizardPageFactory : public ProjectExplorer::JsonWizardPageFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PythonWizardPageFactory();
|
||||||
|
|
||||||
|
Utils::WizardPage *create(ProjectExplorer::JsonWizard *wizard,
|
||||||
|
Utils::Id typeId,
|
||||||
|
const QVariant &data) override;
|
||||||
|
bool validateData(Utils::Id typeId, const QVariant &data, QString *errorMessage) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PythonWizardPage : public Utils::WizardPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PythonWizardPage();
|
||||||
|
void initializePage() override;
|
||||||
|
bool validatePage() override;
|
||||||
|
|
||||||
|
void addPySideVersions(const QString &name, const QVariant &data);
|
||||||
|
void setDefaultPySideVersions(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupProject(const ProjectExplorer::JsonWizard::GeneratorFiles &files);
|
||||||
|
void updateInterpreters();
|
||||||
|
|
||||||
|
ProjectExplorer::InterpreterAspect m_interpreter;
|
||||||
|
Utils::SelectionAspect m_pySideVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Python::Internal
|
||||||
Reference in New Issue
Block a user