/
pythonsupportplugin.cpp
182 lines (127 loc) · 5.34 KB
/
pythonsupportplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
//==============================================================================
// Python support plugin
//==============================================================================
#include "pythonsupportplugin.h"
//==============================================================================
#include <QCoreApplication>
#ifdef Q_OS_WIN
#include <QDir>
#endif
//==============================================================================
#ifdef Q_OS_WIN
#include <Windows.h>
#endif
//==============================================================================
#include "pythonbegin.h"
#include "PythonQt/PythonQtPythonInclude.h"
#include "pythonend.h"
//==============================================================================
namespace OpenCOR {
namespace PythonSupport {
//==============================================================================
PLUGININFO_FUNC PythonSupportPluginInfo()
{
Descriptions descriptions;
descriptions.insert("en", QString::fromUtf8(R"(a plugin to support <a href="https://www.python.org/">Python</a>.)"));
descriptions.insert("fr", QString::fromUtf8(R"(une extension pour supporter <a href="https://www.python.org/">Python</a>.)"));
return new PluginInfo(PluginInfo::Category::Support, false, false,
QStringList() << "Python" << "PythonPackages",
descriptions);
}
//==============================================================================
// Plugin interface
//==============================================================================
bool PythonSupportPlugin::definesPluginInterfaces()
{
// We don't handle this interface...
return false;
}
//==============================================================================
bool PythonSupportPlugin::pluginInterfacesOk(const QString &pFileName,
QObject *pInstance)
{
Q_UNUSED(pFileName)
Q_UNUSED(pInstance)
// We don't handle this interface...
return false;
}
//==============================================================================
void PythonSupportPlugin::initializePlugin()
{
// Set the environment variable PYTHONHOME to the location of our copy of
// Python
// Note: to call Py_SetPythonHome() doesn't work since Py_Initialize() first
// checks the environment and, if PYTHONHOME isn't set, uses the
// installation path compiled in at Python build time...
QString pythonHome = QCoreApplication::applicationDirPath()+"/../";
#if defined(Q_OS_WIN)
pythonDir += "Python";
#elif defined(Q_OS_LINUX)
pythonDir += "python";
#elif defined(Q_OS_MAC)
pythonHome += "Frameworks/Python";
#endif
qputenv("PYTHONHOME", pythonHome.toUtf8());
// Update our system PATH by prepending our Python script directories to it
#ifdef Q_OS_WIN
static const char PathSeparator = ';';
#else
static const char PathSeparator = ':';
#endif
QByteArray path = (pythonHome+"/bin").toUtf8()+PathSeparator+qgetenv("PATH");
#ifdef Q_OS_WIN
path = (pythonHome+"/Scripts").toUtf8()+PathSeparator+path;
#endif
qputenv("PATH", path);
// Ensure that the user's Python site directory (in ~/.local, etc.) isn't
// used
Py_NoUserSiteDirectory = 1;
}
//==============================================================================
void PythonSupportPlugin::finalizePlugin()
{
// We don't handle this interface...
}
//==============================================================================
void PythonSupportPlugin::pluginsInitialized(const Plugins &pLoadedPlugins)
{
Q_UNUSED(pLoadedPlugins)
// We don't handle this interface...
}
//==============================================================================
void PythonSupportPlugin::loadSettings(QSettings &pSettings)
{
Q_UNUSED(pSettings)
// We don't handle this interface...
}
//==============================================================================
void PythonSupportPlugin::saveSettings(QSettings &pSettings) const
{
Q_UNUSED(pSettings)
// We don't handle this interface...
}
//==============================================================================
void PythonSupportPlugin::handleUrl(const QUrl &pUrl)
{
Q_UNUSED(pUrl)
// We don't handle this interface...
}
//==============================================================================
} // namespace PythonSupport
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================