46 #include <pybind11/include/pybind11/pybind11.h> 47 #include <pybind11/include/pybind11/embed.h> 48 #include <OpenFlipper/PythonInterpreter/PythonInterpreter.hh> 51 #include "pythonWidget.hh" 52 #include "PythonSyntaxHighlighter.hh" 54 #include <OpenFlipper/BasePlugin/PythonFunctionsCore.hh> 59 PythonWidget::PythonWidget(QWidget *parent )
66 connect (RunButton, SIGNAL( clicked() ),
this, SLOT( runScript()) );
69 icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"window-close.png");
70 actionClose->setIcon(icon);
71 closeButton->setIcon(icon);
74 iconRun.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"arrow-right.png");
75 RunButton->setIcon(iconRun);
77 setWindowTitle(tr(
"%1 Python Interpreter").arg(
TOSTRING(PRODUCT_NAME)));
79 connect( actionClose , SIGNAL(triggered() ) ,
this, SLOT(hide()) );
80 connect( closeButton , SIGNAL(clicked() ) ,
this, SLOT(hide()) );
81 closeButton->setFocus();
84 pythonInfo->setAlignment(Qt::AlignLeft);
87 pythonInfo->append(
"Each module is automatically loaded by the core with the name given below.");
88 pythonInfo->append(
"An instance for each plugin is automatically generated with a lower case name of the module (E.g. the plugin Move will provide an instance move).\n");
89 pythonInfo->append(
"Available plugins with Python support:\n");
91 QStringList pythonPlugins = getPythonPlugins();
93 for (
int i = 0 ; i < pythonPlugins.size() ; ++i ) {
94 pythonInfo->append(
"Module " + pythonPlugins[i] +
"\t\t providing instance " + pythonPlugins[i].toLower());
98 if ( OpenFlipper::Options::gui() )
99 connect(interpreter,SIGNAL(log(
Logtype,QString)) ,
this, SLOT(slotLocalLog(
Logtype,QString)));
102 QTextEdit* coreInfo =
new QTextEdit( infoTab );
103 infoTab->addTab(coreInfo,
"Core");
104 QString coreDoc = interpreter->
runScriptOutput(
"import pydoc ;import openflipper;html = pydoc.HTMLDoc();object, name = pydoc.resolve(openflipper);page = html.page(pydoc.describe(object), html.document(object, name));print(page)");
105 coreInfo->setHtml(coreDoc);
108 for (
int i = 0 ; i < pythonPlugins.size() ; ++i ) {
109 QTextEdit* edit =
new QTextEdit( infoTab );
110 infoTab->addTab(edit,pythonPlugins[i]);
111 QString data = interpreter->
runScriptOutput(
"import pydoc ;import "+pythonPlugins[i]+
";html = pydoc.HTMLDoc();object, name = pydoc.resolve("+pythonPlugins[i]+
");page = html.page(pydoc.describe(object), html.document(object, name));print(page)");
121 void PythonWidget::runScript() {
123 #ifdef PYTHON_ENABLED 125 interpreter->
runScript(scriptWidget->toPlainText());
127 std::cerr <<
"OpenFlipper is not compiled with python support. Unable to execute script!" << std::endl;
132 void PythonWidget::slotLocalLog(
Logtype _type ,QString _logString) {
136 pythonOutput->setTextColor( QColor(Qt::darkGreen) );
139 pythonOutput->setTextColor( QPalette{}.windowText().color() );
142 pythonOutput->setTextColor( QColor(160,160,0) );
145 pythonOutput->setTextColor( QColor(Qt::red) );
148 pythonOutput->setTextColor( QColor(Qt::blue) );
152 pythonOutput->append(_logString);
QString runScriptOutput(QString _script)
static PythonInterpreter * getInstance()
Creates or returns an instance of the interpreter.
Logtype
Log types for Message Window.
Implementation of highlighting for Python code.
bool runScript(QString _script)
Run a script. Output is passed to the standard logging facilities of OpenFlipper. ...
#define TOSTRING(x)
QSettings object containing all program settings of OpenFlipper.
This class provides OpenFlippers Python interpreter.