Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
5b390585
Commit
5b390585
authored
Mar 07, 2019
by
Jan Möbius
Browse files
Correctly log output from python interpreter via core to widget, file and console
parent
355f0b97
Changes
3
Hide whitespace changes
Inline
Side-by-side
Core/Core.cc
View file @
5b390585
...
...
@@ -87,6 +87,10 @@
#include
<ACG/Scenegraph/MaterialNode.hh>
#include
<ACG/Scenegraph/SeparatorNode.hh>
#ifdef PYTHON_ENABLED
#include
<PythonInterpreter/PythonInterpreter.hh>
#endif
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800
...
...
@@ -694,6 +698,33 @@ Core::init() {
OpenFlipper
::
Options
::
finishedStartup
();
QTimer
::
singleShot
(
100
,
this
,
SLOT
(
slotExecuteAfterStartup
()));
// Initialize and connect the logging of the Python interpreter to the core logging facilities
#ifdef PYTHON_ENABLED
PythonInterpreter
*
interpreter
=
PythonInterpreter
::
getInstance
();
PluginLogger
*
pythonLog
=
new
PluginLogger
(
"PythonInterpreter"
);
loggers_
.
push_back
(
pythonLog
);
// Connect input from python interpreter to wrapping logger
connect
(
interpreter
,
SIGNAL
(
log
(
Logtype
,
QString
)),
pythonLog
,
SLOT
(
slotLog
(
Logtype
,
QString
)),
Qt
::
DirectConnection
);
// connect output to file logger
connect
(
pythonLog
,
SIGNAL
(
log
(
Logtype
,
QString
)),
this
,
SLOT
(
slotLogToFile
(
Logtype
,
QString
)),
Qt
::
DirectConnection
);
// Connect output to the Master loggers
if
(
OpenFlipper
::
Options
::
gui
())
connect
(
pythonLog
,
SIGNAL
(
log
(
Logtype
,
QString
)),
coreWidget_
,
SLOT
(
slotLog
(
Logtype
,
QString
)),
Qt
::
DirectConnection
);
connect
(
pythonLog
,
SIGNAL
(
log
(
Logtype
,
QString
)),
this
,
SLOT
(
slotLog
(
Logtype
,
QString
)),
Qt
::
DirectConnection
);
std
::
cerr
<<
"Connected logger!!! "
<<
std
::
endl
;
#endif
}
...
...
Core/scripting.cc
View file @
5b390585
...
...
@@ -419,6 +419,11 @@ void Core::executePythonScriptFile(QString _filename){
if
(
!
file
.
exists
())
{
emit
scriptLog
(
"Unable to load file "
+
_filename
+
" as python script. File not found!"
);
// Fail when in batch mode
if
(
OpenFlipper
::
Options
::
nogui
())
exit
(
1
);
return
;
}
...
...
@@ -428,9 +433,6 @@ void Core::executePythonScriptFile(QString _filename){
QString
script
=
in
.
readAll
();
std
::
cerr
<<
"Script : "
<<
std
::
endl
;
std
::
cerr
<<
script
.
toStdString
()
<<
std
::
endl
;
executePythonScript
(
script
);
}
...
...
PythonInterpreter/PythonInterpreter.cc
View file @
5b390585
...
...
@@ -87,7 +87,7 @@ PythonInterpreter* PythonInterpreter::getInstance() {
}
PythonInterpreter
::
PythonInterpreter
()
:
externalLogging_
(
fals
e
)
externalLogging_
(
tru
e
)
{
}
...
...
@@ -320,8 +320,7 @@ QString PythonInterpreter::runScriptOutput(QString _script) {
void
PythonInterpreter
::
pyOutput
(
const
char
*
w
)
{
if
(
externalLogging_
)
{
std
::
cerr
<<
"Python output: "
<<
w
<<
std
::
endl
;
Q_EMIT
log
(
LOGOUT
,
QString
(
w
));
emit
log
(
LOGOUT
,
QString
(
w
));
}
else
{
LogOut
+=
QString
::
fromUtf8
(
w
);
}
...
...
@@ -330,8 +329,7 @@ void PythonInterpreter::pyOutput(const char* w)
void
PythonInterpreter
::
pyError
(
const
char
*
w
)
{
if
(
externalLogging_
)
{
std
::
cerr
<<
"Python error: "
<<
w
<<
std
::
endl
;
Q_EMIT
log
(
LOGERR
,
QString
(
w
));
emit
log
(
LOGERR
,
QString
(
w
));
}
else
{
LogErr
+=
QString
::
fromUtf8
(
w
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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