Skip to content
GitLab
Menu
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
fe65b989
Commit
fe65b989
authored
Feb 05, 2019
by
Jan Möbius
Browse files
Introduced openflipper command line python scripts with extension ofp
parent
470f345e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Core/Core.hh
View file @
fe65b989
...
...
@@ -1318,7 +1318,17 @@ private slots:
void
showReducedMenuBar
(
bool
reduced
);
/** \brief Open the given file and execute its contents as a python script
*
* @param _filename Name of the python script
*/
void
executePythonScriptFile
(
QString
_filename
);
/** \brief execute the given string as a python script
*
* @param _script Python script
*/
void
executePythonScript
(
QString
_script
);
private
:
/// Core scripting engine
...
...
Core/openFunctions.cc
View file @
fe65b989
...
...
@@ -149,10 +149,14 @@ void Core::slotExecuteAfterStartup() {
QStringList
scriptFiles
=
scriptDir
.
entryList
(
QDir
::
Files
,
QDir
::
Name
);
// Execute all files ending with ofs
for
(
int
i
=
0
;
i
<
scriptFiles
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
scriptFiles
.
size
();
++
i
)
{
if
(
scriptFiles
[
i
].
endsWith
(
"ofs"
,
Qt
::
CaseInsensitive
)
)
emit
executeFileScript
(
scriptDir
.
path
()
+
"/"
+
scriptFiles
[
i
]);
if
(
scriptFiles
[
i
].
endsWith
(
"ofp"
,
Qt
::
CaseInsensitive
)
)
executePythonScriptFile
(
scriptDir
.
path
()
+
"/"
+
scriptFiles
[
i
]);
}
// Clear scripting window afterexecuting the coresubdir scripts
bool
ok
=
false
;
slotCall
(
"scripting"
,
"clearEditor()"
,
ok
);
...
...
@@ -165,7 +169,7 @@ void Core::slotExecuteAfterStartup() {
// Skip scripts here as they will be handled by a different function
QString
tmp
=
commandLineFileNames_
[
i
].
first
;
if
(
tmp
.
endsWith
(
"ofs"
,
Qt
::
CaseInsensitive
)
)
{
if
(
tmp
.
endsWith
(
"
.
ofs"
,
Qt
::
CaseInsensitive
)
||
tmp
.
endsWith
(
".ofp"
,
Qt
::
CaseInsensitive
)
)
{
commandLineScriptNames_
.
push_back
(
commandLineFileNames_
[
i
].
first
);
continue
;
}
...
...
@@ -185,8 +189,14 @@ void Core::slotExecuteAfterStartup() {
// If we have scripting support, execute the scripts given at the commandline.
if
(
scriptingSupport
)
for
(
uint
i
=
0
;
i
<
commandLineScriptNames_
.
size
()
;
++
i
)
{
emit
executeFileScript
(
commandLineScriptNames_
[
i
]);
for
(
unsigned
int
i
=
0
;
i
<
commandLineScriptNames_
.
size
()
;
++
i
)
{
if
(
commandLineScriptNames_
[
i
].
endsWith
(
"ofs"
,
Qt
::
CaseInsensitive
)
)
emit
executeFileScript
(
commandLineScriptNames_
[
i
]);
if
(
commandLineScriptNames_
[
i
].
endsWith
(
"ofp"
,
Qt
::
CaseInsensitive
)
)
executePythonScriptFile
(
commandLineScriptNames_
[
i
]);
}
// If we don't have a gui and we are not under remote control,
...
...
@@ -249,8 +259,11 @@ int Core::loadObject ( QString _filename ) {
return
-
2
;
}
else
if
(
_filename
.
endsWith
(
".ofs"
,
Qt
::
CaseInsensitive
))
{
emit
log
(
LOGINFO
,
tr
(
"Starting script execution of %1."
).
arg
(
_filename
))
;
emit
log
(
LOGINFO
,
tr
(
"Starting script execution of
OpenFlipper Script
%1."
).
arg
(
_filename
))
;
emit
executeFileScript
(
_filename
);
}
else
if
(
_filename
.
endsWith
(
".ofp"
,
Qt
::
CaseInsensitive
))
{
emit
log
(
LOGINFO
,
tr
(
"Starting script execution of Python script %1."
).
arg
(
_filename
))
;
executePythonScriptFile
(
_filename
);
}
else
{
QFileInfo
fi
(
_filename
);
...
...
Core/scripting.cc
View file @
fe65b989
...
...
@@ -56,6 +56,9 @@
#include "Core.hh"
#include <QUiLoader>
#ifdef PYTHON_ENABLED
#include <PythonInterpreter/PythonInterpreter.hh>
#endif
//== IMPLEMENTATION ==========================================================
...
...
@@ -410,3 +413,35 @@ QScriptValue helpFunction(QScriptContext *context, QScriptEngine *engine)
return
engine
->
undefinedValue
();
}
void
Core
::
executePythonScriptFile
(
QString
_filename
){
QFile
file
(
_filename
);
if
(
!
file
.
exists
())
{
emit
scriptLog
(
"Unable to load file "
+
_filename
+
" as python script. File not found!"
);
return
;
}
file
.
open
(
QIODevice
::
ReadOnly
|
QFile
::
Text
);
QTextStream
in
(
&
file
);
QString
script
=
in
.
readAll
();
std
::
cerr
<<
"Script : "
<<
std
::
endl
;
std
::
cerr
<<
script
.
toStdString
()
<<
std
::
endl
;
executePythonScript
(
script
);
}
void
Core
::
executePythonScript
(
QString
_script
)
{
#ifdef PYTHON_ENABLED
PythonInterpreter
*
interpreter
=
PythonInterpreter
::
getInstance
();
interpreter
->
runScript
(
_script
);
#else
emit
scriptLog
(
"Python scripting Error! No build in python support. Unable to execute script. Build OpenFlipper with Python support to enable Python based scripting."
);
#endif
}
PythonInterpreter/PythonInterpreter.cc
View file @
fe65b989
...
...
@@ -311,6 +311,8 @@ PYBIND11_EMBEDDED_MODULE(openflipper, m) {
core
.
def
(
"updateView"
,
&
Core
::
updateView
);
core
.
def
(
"clearAll"
,
&
Core
::
clearAll
);
core
.
def
(
"fullscreen"
,
&
Core
::
fullscreen
);
core
.
def
(
"writeVersionNumbers"
,
&
Core
::
writeVersionNumbers
);
...
...
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