Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
a9350f69
Commit
a9350f69
authored
Feb 26, 2019
by
Jan Möbius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically import python modules for openflipper plugins
parent
7d032d02
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
17 deletions
+71
-17
Documentation/DeveloperHelpSources/python-scripting.docu
Documentation/DeveloperHelpSources/python-scripting.docu
+8
-7
PythonInterpreter/PythonInterpreter.cc
PythonInterpreter/PythonInterpreter.cc
+62
-9
widgets/pythonWidget/pythonWidget.cc
widgets/pythonWidget/pythonWidget.cc
+1
-1
No files found.
Documentation/DeveloperHelpSources/python-scripting.docu
View file @
a9350f69
...
...
@@ -10,15 +10,16 @@
or graphical functionality will be loaded. You can see on the command line (when "-c" is given),
which plugins are activated and which are skipped in batch mode.
\section python_scripting_datattypes DataTypes
\subsection python_scripting_matrixtype Matrix4x4 data type
The Matrix4x4T type used in the C++ code is mapped from python. Details can be found here:
\subpage python_scripting_matrix4x4_type
\section python_scripting_datattypes DataTypes
\subsection python_scripting_matrixtype Matrix4x4 data type
The Matrix4x4T type used in the C++ code is mapped from python. Details can be found here:
\subpage python_scripting_matrix4x4_type
\subsection python_scripting_vectortype 3 Dimensional vector type
The Vector type used in the C++ code is mapped from python. Details can be found here:
\subpage python_scripting_vector_type
\subsection python_scripting_vectortype 3 Dimensional vector type
The Vector type used in the C++ code is mapped from python. Details can be found here:
\subpage python_scripting_vector_type
*/
PythonInterpreter/PythonInterpreter.cc
View file @
a9350f69
...
...
@@ -39,6 +39,7 @@
* *
\*===========================================================================*/
#define PYTHON_DEBUG true
#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
...
...
@@ -54,6 +55,8 @@
#include "PythonTypeConversions.hh"
#include <OpenFlipper/BasePlugin/PythonFunctionsCore.hh>
namespace
py
=
pybind11
;
static
Core
*
core_
;
...
...
@@ -112,40 +115,90 @@ void PythonInterpreter::initPython() {
std
::
cerr
<<
"C"
<<
std
::
endl
;
if
(
!
modulesInitialized
())
{
std
::
cerr
<<
"D"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Import __main__"
;
#endif
//dlopen("libpython3.5m.so.1.0", RTLD_LAZY | RTLD_GLOBAL);
py
::
module
main
{
py
::
module
::
import
(
"__main__"
)
};
// redirect python output
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
std
::
cerr
<<
" Redirect Outputs ..."
;
#endif
// Redirect python output to integrated logger functions
tyti
::
pylog
::
redirect_stderr
([
this
](
const
char
*
w
)
{
this
->
pyError
(
w
);
});
tyti
::
pylog
::
redirect_stdout
([
this
](
const
char
*
w
)
{
this
->
pyOutput
(
w
);
});
std
::
cerr
<<
"E"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
std
::
cerr
<<
" Get __dict__ from main namespace ..."
;
#endif
// add openflipper module
// =========================================================
// Add OpenFlipper Core module to main namespace
// =========================================================
py
::
object
main_namespace
=
main
.
attr
(
"__dict__"
);
std
::
cerr
<<
"F"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
std
::
cerr
<<
"Importing OpenFlipper core module ..."
;
#endif
py
::
module
of_module
(
py
::
module
::
import
(
"openflipper"
));
main_namespace
[
"openflipper"
]
=
of_module
;
std
::
cerr
<<
"G"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
#endif
// =========================================================
// Import with python interface to main namespace
// =========================================================
QStringList
pythonPlugins
=
getPythonPlugins
();
for
(
int
i
=
0
;
i
<
pythonPlugins
.
size
()
;
++
i
)
{
#ifdef PYTHON_DEBUG
std
::
cerr
<<
"Importing "
+
pythonPlugins
[
i
].
toStdString
()
+
" module ..."
;
#endif
py
::
module
om_module
(
py
::
module
::
import
(
pythonPlugins
[
i
].
toStdString
().
c_str
()));
main_namespace
[
pythonPlugins
[
i
].
toStdString
().
c_str
()]
=
om_module
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
#endif
}
#ifdef PYTHON_DEBUG
std
::
cerr
<<
"Copy dict ..."
;
#endif
global_dict_clean_
=
PyDict_Copy
(
PyModule_GetDict
(
main
.
ptr
()));
std
::
cerr
<<
"H"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
std
::
cerr
<<
"Set to validate state ..."
;
#endif
// set the main module member to a validate state, shows, that all modules are successfully initialized
mainModule_
=
std
::
move
(
main
);
std
::
cerr
<<
"I"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
std
::
cerr
<<
"Save thread ..."
;
#endif
// Do not release the GIL until all modules are initalzed
PyEval_SaveThread
();
std
::
cerr
<<
"J"
<<
std
::
endl
;
#ifdef PYTHON_DEBUG
std
::
cerr
<<
" Done"
<<
std
::
endl
;
#endif
}
...
...
widgets/pythonWidget/pythonWidget.cc
View file @
a9350f69
...
...
@@ -83,7 +83,7 @@ PythonWidget::PythonWidget(QWidget *parent )
#ifdef PYTHON_ENABLED
pythonInfo
->
setAlignment
(
Qt
::
AlignLeft
);
pythonInfo
->
append
(
"Plugins with Python support (
use import to load the corresponding module!
):
\n
"
);
pythonInfo
->
append
(
"Plugins with Python support (
The plugin modules will be imported with their name shown below.
):
\n
"
);
QStringList
pythonPlugins
=
getPythonPlugins
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment