scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

PythonScripting Class Reference

#include <PythonScripting.h>

Inheritance diagram for PythonScripting:
[legend]
Collaboration diagram for PythonScripting:
[legend]

Public Slots

virtual void clear ()
 Clear the global environment. What exactly happens depends on the implementation. More...
 
virtual void stopExecution ()
 If the implementation supports asynchronuos execution, deactivate it. More...
 
virtual void startExecution ()
 If the implementation supports asynchronuos execution, activate it. More...
 
void incref ()
 Increase the reference count. This should only be called by scripted and Script to avoid memory leaks. More...
 
void decref ()
 Decrease the reference count. This should only be called by scripted and Script to avoid segfaults. More...
 

Signals

void error (const QString &message, const QString &scriptName, int lineNumber)
 signal an error condition / exception More...
 
void print (const QString &output)
 output that is not handled by a Script More...
 

Public Member Functions

 PythonScripting (ApplicationWindow *parent, bool batch=false)
 
 ~PythonScripting ()
 
bool initialize () override
 Part of the initialization is deferred from the constructor until after the signals have been connected. More...
 
void redirectStdIO () override
 
void write (const QString &text)
 
QString toString (PyObject *object, bool decref=false)
 like str(object) in Python More...
 
PyObjecteval (const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>")
 evaluate a Python expression More...
 
bool exec (const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>")
 execute a sequence of Python statements More...
 
QString errorMsg ()
 
bool isRunning () const override
 whether asynchronuous execution is enabled (if supported by the implementation) More...
 
ScriptnewScript (const QString &code, QObject *context, const QString &name="<input>") override
 Instantiate the Script subclass matching the ScriptEnv subclass. More...
 
bool setQObject (QObject *, const char *, PyObject *dict)
 
bool setQObject (QObject *val, const char *name) override
 
bool setInt (int i, const char *s) override
 
bool setInt (int, const char *, PyObject *dict)
 
bool setDouble (double x, const char *s) override
 
bool setDouble (double, const char *, PyObject *dict)
 
const QStringList mathFunctions () const override
 Return a list of supported mathematical functions. These should be imported into the global namespace. More...
 
const QString mathFunctionDoc (const QString &name) const override
 Return a documentation string for the given mathematical function. More...
 
const QStringList fileExtensions () const override
 Return a list of file extensions commonly used for this language. More...
 
PyObjectglobalDict ()
 
PyObjectsysDict ()
 
bool initialized () const
 initialization of the interpreter may fail; or there could be other errors setting up the environment More...
 
virtual QString stackTraceString ()
 If an exception / error occured, return a nicely formated stack backtrace. More...
 
const QString fileFilter () const
 Construct a filter expression from fileExtension(), suitable for QFileDialog. More...
 

Static Public Member Functions

static ScriptingEnvconstructor (ApplicationWindow *parent, bool batch=false)
 

Static Public Attributes

static const char * langName = "Python"
 

Protected Attributes

bool d_initialized
 whether the interpreter has been successfully initialized More...
 
ApplicationWindowd_parent
 the context in which we are running More...
 

Private Member Functions

bool loadInitFile (const QString &path)
 

Private Attributes

PyObjectglobals
 
PyObjectmath
 
PyObjectsys
 
int d_refcount
 the reference counter More...
 

Detailed Description

Definition at line 40 of file PythonScripting.h.

Constructor & Destructor Documentation

◆ PythonScripting()

PythonScripting::PythonScripting ( ApplicationWindow parent,
bool  batch = false 
)

Definition at line 190 of file PythonScripting.cpp.

191  : ScriptingEnv(parent, langName)
192 {
193  Q_UNUSED(batch)
194  PyObject *mainmod=NULL, *scidavismod=NULL, *sysmod=NULL;
195  math = NULL;
196  sys = NULL;
197  d_initialized = false;
198  if (Py_IsInitialized())
199  {
200  // PyEval_AcquireLock();
201  mainmod = PyImport_ImportModule("__main__");
202  if (!mainmod)
203  {
204  PyErr_Print();
205  // PyEval_ReleaseLock();
206  return;
207  }
208  globals = PyModule_GetDict(mainmod);
209  Py_DECREF(mainmod);
210  } else {
211  // if we need to bundle Python libraries with the executable,
212  // specify the library location here
213 #ifdef PYTHONHOME
214  Py_SetPythonHome(const_cast<char*>(str(PYTHONHOME)));
215 #endif
216  // PyEval_InitThreads ();
217 #if PY_MAJOR_VERSION >= 3
218  PyImport_AppendInittab("scidavis", &PyInit_scidavis);
219 #endif
220  Py_Initialize ();
221  if (!Py_IsInitialized ())
222  return;
223 
224 
225 #if PY_MAJOR_VERSION < 3
226 #ifdef SIP_STATIC_MODULE
227  initsip();
228  initQtCore();
229  initQtGui();
230 #endif
231  initscidavis();
232 #endif
233  mainmod = PyImport_AddModule("__main__");
234  if (!mainmod)
235  {
236  // PyEval_ReleaseLock();
237  PyErr_Print();
238  return;
239  }
240  globals = PyModule_GetDict(mainmod);
241  }
242 
243  if (!globals)
244  {
245  PyErr_Print();
246  // PyEval_ReleaseLock();
247  return;
248  }
249  Py_INCREF(globals);
250 
251  math = PyDict_New();
252  if (!math)
253  PyErr_Print();
254 
255  scidavismod = PyImport_ImportModule("scidavis");
256  if (scidavismod)
257  {
258  PyDict_SetItemString(globals, "scidavis", scidavismod);
259  PyObject *scidavisDict = PyModule_GetDict(scidavismod);
260  if (!setQObject(d_parent, "app", scidavisDict))
261  QMessageBox::warning
262  (d_parent, tr("Failed to export SciDAVis API"),
263  tr("Accessing SciDAVis functions or objects from Python code won't work."
264  "Probably your version of SIP differs from the one SciDAVis was compiled against;"
265  "try updating SIP or recompiling SciDAVis."));
266  PyDict_SetItemString(scidavisDict, "mathFunctions", math);
267  Py_DECREF(scidavismod);
268  } else
269  PyErr_Print();
270 
271  sysmod = PyImport_ImportModule("sys");
272  if (sysmod)
273  {
274  sys = PyModule_GetDict(sysmod);
275  Py_INCREF(sys);
276  } else
277  PyErr_Print();
278 
279  // PyEval_ReleaseLock();
280  d_initialized = true;
281 }

References ScriptingEnv::d_initialized, ScriptingEnv::d_parent, globals, initQtCore(), initQtGui(), initscidavis(), initsip(), math, setQObject(), str, and sys.

Referenced by constructor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~PythonScripting()

PythonScripting::~PythonScripting ( )

Definition at line 320 of file PythonScripting.cpp.

321 {
322  Py_XDECREF(globals);
323  Py_XDECREF(math);
324  Py_XDECREF(sys);
325 }

References globals, math, and sys.

Member Function Documentation

◆ clear

virtual void ScriptingEnv::clear ( )
inlinevirtualslotinherited

Clear the global environment. What exactly happens depends on the implementation.

Definition at line 91 of file ScriptingEnv.h.

91 {}

◆ constructor()

static ScriptingEnv* PythonScripting::constructor ( ApplicationWindow parent,
bool  batch = false 
)
inlinestatic

Definition at line 48 of file PythonScripting.h.

48 { return new PythonScripting(parent, batch); }

References PythonScripting().

Here is the call graph for this function:

◆ decref

void ScriptingEnv::decref ( )
slotinherited

Decrease the reference count. This should only be called by scripted and Script to avoid segfaults.

Definition at line 65 of file ScriptingEnv.cpp.

66 {
67  d_refcount--;
68  if (d_refcount==0)
69  delete this;
70 }

References ScriptingEnv::d_refcount.

Referenced by scripted::scriptingChangeEvent(), toString(), Script::~Script(), and scripted::~scripted().

Here is the caller graph for this function:

◆ error

void ScriptingEnv::error ( const QString &  message,
const QString &  scriptName,
int  lineNumber 
)
signalinherited

signal an error condition / exception

◆ errorMsg()

QString PythonScripting::errorMsg ( )

Definition at line 136 of file PythonScripting.cpp.

137 {
138  PyObject *exception=0, *value=0, *traceback=0;
139  PyTracebackObject *excit=0;
140  PyFrameObject *frame;
141  const char *fname;
142  QString msg;
143  if (!PyErr_Occurred()) return "";
144 
145  PyErr_Fetch(&exception, &value, &traceback);
146  PyErr_NormalizeException(&exception, &value, &traceback);
147  if(PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError))
148  {
149  QString text = toString(PyObject_GetAttrString(value, "text"), true);
150  msg.append(text + "\n");
151  PyObject *offset = PyObject_GetAttrString(value, "offset");
152  for (int i=0; i<(PYLong_AsLong(offset)-1); i++)
153  if (text[i] == '\t')
154  msg.append("\t");
155  else
156  msg.append(" ");
157  msg.append("^\n");
158  Py_DECREF(offset);
159  msg.append("SyntaxError: ");
160  msg.append(toString(PyObject_GetAttrString(value, "msg"), true) + "\n");
161  msg.append("at ").append(toString(PyObject_GetAttrString(value, "filename"), true));
162  msg.append(":").append(toString(PyObject_GetAttrString(value, "lineno"), true));
163  msg.append("\n");
164  Py_DECREF(exception);
165  Py_DECREF(value);
166  } else {
167  msg.append(toString(exception,true)).remove("exceptions.").append(": ");
168  msg.append(toString(value,true));
169  msg.append("\n");
170  }
171 
172  if (traceback) {
173  excit = (PyTracebackObject*)traceback;
174  while (excit && (PyObject*)excit != Py_None)
175  {
176  frame = excit->tb_frame;
177  msg.append("at ").append(PYUNICODE_AsUTF8(frame->f_code->co_filename));
178  msg.append(":").append(QString::number(excit->tb_lineno));
179  if (frame->f_code->co_name && *(fname = PYUNICODE_AsUTF8(frame->f_code->co_name)) != '?')
180  msg.append(" in ").append(fname);
181  msg.append("\n");
182  excit = excit->tb_next;
183  }
184  Py_DECREF(traceback);
185  }
186 
187  return msg;
188 }

References PYLong_AsLong, PYUNICODE_AsUTF8, _traceback::tb_frame, _traceback::tb_lineno, _traceback::tb_next, and toString().

Referenced by PythonScript::compile(), and PythonScript::exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eval()

PyObject * PythonScripting::eval ( const QString &  code,
PyObject argDict = NULL,
const char *  name = "<scidavis>" 
)

evaluate a Python expression

Evaluates code, using argDict (borrowed reference) as local dictionary or an empty one if argDict==NULL. name is the filename Python uses when reporting errors. Returns a new reference; NULL means caller has to do exception handling.

Definition at line 100 of file PythonScripting.cpp.

101 {
102  PyObject *args;
103  if (argDict)
104  args = argDict;
105  else
106  args = globals;
107  PyObject *ret=NULL;
108  PyObject *co = Py_CompileString(code.toUtf8().constData(), name, Py_eval_input);
109  if (co)
110  {
111  ret = PyEval_EvalCode(PYCodeObject_cast co, globals, args);
112  Py_DECREF(co);
113  }
114  return ret;
115 }

References globals, name(), and PYCodeObject_cast.

Here is the call graph for this function:

◆ exec()

bool PythonScripting::exec ( const QString &  code,
PyObject argDict = NULL,
const char *  name = "<scidavis>" 
)

execute a sequence of Python statements

Executes code, using argDict (borrowed reference) as local dictionary or an empty one if argDict==NULL. name is the filename Python uses when reporting errors. A false return value means caller has to do exception handling.

Definition at line 117 of file PythonScripting.cpp.

118 {
119  PyObject *args;
120  if (argDict)
121  args = argDict;
122  else
123  args = globals;
124  PyObject *tmp = NULL;
125  PyObject *co = Py_CompileString(code.toUtf8().constData(), name, Py_file_input);
126  if (co)
127  {
128  tmp = PyEval_EvalCode(PYCodeObject_cast co, globals, args);
129  Py_DECREF(co);
130  }
131  if (!tmp) return false;
132  Py_DECREF(tmp);
133  return true;
134 }

References globals, name(), and PYCodeObject_cast.

Here is the call graph for this function:

◆ fileExtensions()

const QStringList PythonScripting::fileExtensions ( ) const
overridevirtual

Return a list of file extensions commonly used for this language.

Reimplemented from ScriptingEnv.

Definition at line 462 of file PythonScripting.cpp.

463 {
464  QStringList extensions;
465  extensions << "py" << "PY";
466  return extensions;
467 }

◆ fileFilter()

const QString ScriptingEnv::fileFilter ( ) const
inherited

Construct a filter expression from fileExtension(), suitable for QFileDialog.

Definition at line 51 of file ScriptingEnv.cpp.

52 {
53  QStringList extensions = fileExtensions();
54  if (extensions.isEmpty())
55  return "";
56  else
57  return tr("%1 Source (*.%2);;").arg(objectName()).arg(extensions.join(" *."));
58 }

References ScriptingEnv::fileExtensions().

Referenced by ScriptEdit::exportASCII(), and ScriptEdit::importASCII().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalDict()

PyObject* PythonScripting::globalDict ( )
inline

Definition at line 95 of file PythonScripting.h.

95 { return globals; }

References globals.

Referenced by PythonScript::eval(), and PythonScript::exec().

Here is the caller graph for this function:

◆ incref

void ScriptingEnv::incref ( )
slotinherited

Increase the reference count. This should only be called by scripted and Script to avoid memory leaks.

Definition at line 60 of file ScriptingEnv.cpp.

61 {
62  d_refcount++;
63 }

References ScriptingEnv::d_refcount.

Referenced by Script::Script(), scripted::scripted(), and scripted::scriptingChangeEvent().

Here is the caller graph for this function:

◆ initialize()

bool PythonScripting::initialize ( )
overridevirtual

Part of the initialization is deferred from the constructor until after the signals have been connected.

Reimplemented from ScriptingEnv.

Definition at line 292 of file PythonScripting.cpp.

293 {
294  if (!d_initialized) return false;
295  // PyEval_AcquireLock();
296 
297  if (!d_parent->batchMode())
298  {
299  // Redirect output to the print(const QString&) signal.
300  // Also see method write(const QString&) and Python documentation on
301  // sys.stdout and sys.stderr.
302  setQObject(this, "stdout", sys);
303  setQObject(this, "stderr", sys);
304  }
305  bool initialized;
306  initialized = loadInitFile(QDir::homePath()+"/scidavisrc");
307  if(!initialized) initialized = loadInitFile(QDir::homePath()+"/.scidavisrc");
308 #ifdef PYTHON_CONFIG_PATH
309  if(!initialized) initialized = loadInitFile(PYTHON_CONFIG_PATH"/scidavisrc");
310  if(!initialized) initialized = loadInitFile(PYTHON_CONFIG_PATH"/.scidavisrc");
311 #endif
312  if(!initialized) initialized = loadInitFile(QDir::rootPath()+"etc/scidavisrc");
313  if(!initialized) initialized = loadInitFile(QCoreApplication::instance()->applicationDirPath()+"/scidavisrc");
314  if(!initialized) initialized = loadInitFile("scidavisrc");
315 
316  // PyEval_ReleaseLock();
317  return true;
318 }

References ApplicationWindow::batchMode(), ScriptingEnv::d_initialized, ScriptingEnv::d_parent, ScriptingEnv::initialized(), loadInitFile(), setQObject(), and sys.

Here is the call graph for this function:

◆ initialized()

bool ScriptingEnv::initialized ( ) const
inlineinherited

initialization of the interpreter may fail; or there could be other errors setting up the environment

Definition at line 61 of file ScriptingEnv.h.

61 { return d_initialized; }

References ScriptingEnv::d_initialized.

Referenced by initialize().

Here is the caller graph for this function:

◆ isRunning()

bool PythonScripting::isRunning ( ) const
overridevirtual

whether asynchronuous execution is enabled (if supported by the implementation)

Reimplemented from ScriptingEnv.

Definition at line 383 of file PythonScripting.cpp.

384 {
385  return Py_IsInitialized();
386 }

◆ loadInitFile()

bool PythonScripting::loadInitFile ( const QString &  path)
private

Definition at line 331 of file PythonScripting.cpp.

332 {
333  PyRun_SimpleString("import sys\nsys.path.append('" PYTHON_UTIL_PATH "')");
334  QFileInfo pyFile(path+".py"), pycFile(path+".pyc");
335  bool success = false;
336  if (pycFile.isReadable() && (pycFile.lastModified() >= pyFile.lastModified())) {
337  // if we have a recent pycFile, use it
338  FILE *f = fopen(pycFile.filePath().toLocal8Bit(), "rb");
339  success = PyRun_SimpleFileEx(f, pycFile.filePath().toLocal8Bit(), false) == 0;
340  fclose(f);
341  } else if (pyFile.isReadable() && pyFile.exists()) {
342  // try to compile pyFile to pycFile
343  PyObject *compileModule = PyImport_ImportModule("py_compile");
344  if (compileModule) {
345  PyObject *compile = PyDict_GetItemString(PyModule_GetDict(compileModule), "compile");
346  if (compile) {
347  PyObject *tmp = PyObject_CallFunctionObjArgs(compile,
348  PYUNICODE_FromString(pyFile.filePath().toUtf8().constData()),
349  PYUNICODE_FromString(pycFile.filePath().toUtf8().constData()),
350  NULL);
351  if (tmp)
352  Py_DECREF(tmp);
353  else
354  PyErr_Print();
355  } else
356  PyErr_Print();
357  Py_DECREF(compileModule);
358  } else
359  PyErr_Print();
360  pycFile.refresh();
361  if (pycFile.isReadable() && (pycFile.lastModified() >= pyFile.lastModified())) {
362  // run the newly compiled pycFile
363  FILE *f = fopen(pycFile.filePath().toLocal8Bit(), "rb");
364  success = PyRun_SimpleFileEx(f, pycFile.filePath().toLocal8Bit(), false) == 0;
365  fclose(f);
366  } else {
367  // fallback: just run pyFile
368  /*FILE *f = fopen(pyFile.filePath(), "r");
369  success = PyRun_SimpleFileEx(f, pyFile.filePath(), false) == 0;
370  fclose(f);*/
371  //TODO: code above crashes on Windows - bug in Python?
372  QFile f(pyFile.filePath());
373  if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
374  QByteArray data = f.readAll();
375  success = PyRun_SimpleString(data.data());
376  f.close();
377  }
378  }
379  }
380  return success;
381 }

References PYTHON_UTIL_PATH, and PYUNICODE_FromString.

Referenced by initialize().

Here is the caller graph for this function:

◆ mathFunctionDoc()

const QString PythonScripting::mathFunctionDoc ( const QString &  ) const
overridevirtual

Return a documentation string for the given mathematical function.

Reimplemented from ScriptingEnv.

Definition at line 452 of file PythonScripting.cpp.

453 {
454  PyObject *mathf = PyDict_GetItemString(math,name.toLocal8Bit()); // borrowed
455  if (!mathf) return "";
456  PyObject *pydocstr = PyObject_GetAttrString(mathf, "__doc__"); // new
457  QString qdocstr = PYUNICODE_AsUTF8(pydocstr);
458  Py_XDECREF(pydocstr);
459  return qdocstr;
460 }

References math, name(), and PYUNICODE_AsUTF8.

Here is the call graph for this function:

◆ mathFunctions()

const QStringList PythonScripting::mathFunctions ( ) const
overridevirtual

Return a list of supported mathematical functions. These should be imported into the global namespace.

Reimplemented from ScriptingEnv.

Definition at line 436 of file PythonScripting.cpp.

437 {
438  QStringList flist;
439  PyObject *key, *value;
440 #if PY_VERSION_HEX >= 0x02050000
441  Py_ssize_t i=0;
442 #else
443  int i=0;
444 #endif
445  while(PyDict_Next(math, &i, &key, &value))
446  if (PyCallable_Check(value))
447  flist << PYUNICODE_AsUTF8(key);
448  flist.sort();
449  return flist;
450 }

References math, and PYUNICODE_AsUTF8.

◆ newScript()

Script* PythonScripting::newScript ( const QString &  ,
QObject *  ,
const QString &  = "<input>" 
)
inlineoverridevirtual

Instantiate the Script subclass matching the ScriptEnv subclass.

Implements ScriptingEnv.

Definition at line 79 of file PythonScripting.h.

80  {
81  return new PythonScript(this, code, context, name);
82  }

References name().

Here is the call graph for this function:

◆ print

void ScriptingEnv::print ( const QString &  output)
signalinherited

output that is not handled by a Script

Referenced by write().

Here is the caller graph for this function:

◆ redirectStdIO()

void PythonScripting::redirectStdIO ( )
overridevirtual

Reimplemented from ScriptingEnv.

Definition at line 283 of file PythonScripting.cpp.

284 {
285  // Redirect output to the print(const QString&) signal.
286  // Also see method write(const QString&) and Python documentation on
287  // sys.stdout and sys.stderr.
288  setQObject(this, "stdout", sys);
289  setQObject(this, "stderr", sys);
290 }

References setQObject(), and sys.

Here is the call graph for this function:

◆ setDouble() [1/2]

bool PythonScripting::setDouble ( double  x,
const char *  s 
)
inlineoverridevirtual

Reimplemented from ScriptingEnv.

Definition at line 88 of file PythonScripting.h.

88 {return setDouble(x,s,nullptr);}

References setDouble().

Referenced by setDouble().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDouble() [2/2]

bool PythonScripting::setDouble ( double  val,
const char *  name,
PyObject dict 
)

Definition at line 424 of file PythonScripting.cpp.

425 {
426  PyObject *pyobj = Py_BuildValue("d",val);
427  if (!pyobj) return false;
428  if (dict)
429  PyDict_SetItemString(dict,name,pyobj);
430  else
431  PyDict_SetItemString(globals,name,pyobj);
432  Py_DECREF(pyobj);
433  return true;
434 }

References globals, and name().

Here is the call graph for this function:

◆ setInt() [1/2]

bool PythonScripting::setInt ( int  i,
const char *  s 
)
inlineoverridevirtual

Reimplemented from ScriptingEnv.

Definition at line 86 of file PythonScripting.h.

86 {return setInt(i,s,nullptr);}

References setInt().

Referenced by setInt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInt() [2/2]

bool PythonScripting::setInt ( int  val,
const char *  name,
PyObject dict 
)

Definition at line 412 of file PythonScripting.cpp.

413 {
414  PyObject *pyobj = Py_BuildValue("i",val);
415  if (!pyobj) return false;
416  if (dict)
417  PyDict_SetItemString(dict,name,pyobj);
418  else
419  PyDict_SetItemString(globals,name,pyobj);
420  Py_DECREF(pyobj);
421  return true;
422 }

References globals, and name().

Here is the call graph for this function:

◆ setQObject() [1/2]

bool PythonScripting::setQObject ( QObject *  val,
const char *  name,
PyObject dict 
)

Definition at line 388 of file PythonScripting.cpp.

389 {
390  if(!val) return false;
391  PyObject *pyobj=NULL;
392 
393  PyGILState_STATE state = PyGILState_Ensure();
394 
395  //sipWrapperType * klass = sipFindClass(val->className());
396  const sipTypeDef* klass=sipFindType(val->metaObject()->className());
397  if (!klass) return false;
398  //pyobj = sipConvertFromInstance(val, klass, NULL);
399  pyobj = sipConvertFromType(val, klass, NULL);
400  if (!pyobj) return false;
401 
402  if (dict)
403  PyDict_SetItemString(dict,name,pyobj);
404  else
405  PyDict_SetItemString(globals,name,pyobj);
406  Py_DECREF(pyobj);
407 
408  PyGILState_Release(state);
409  return true;
410 }

References globals, and name().

Referenced by PythonScript::beginStdoutRedirect(), initialize(), PythonScripting(), and redirectStdIO().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setQObject() [2/2]

bool PythonScripting::setQObject ( QObject *  val,
const char *  name 
)
inlineoverridevirtual

Reimplemented from ScriptingEnv.

Definition at line 85 of file PythonScripting.h.

85 { return setQObject(val,name,NULL); }

References name(), and setQObject().

Referenced by setQObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stackTraceString()

virtual QString ScriptingEnv::stackTraceString ( )
inlinevirtualinherited

If an exception / error occured, return a nicely formated stack backtrace.

Definition at line 69 of file ScriptingEnv.h.

69 { return {}; }

◆ startExecution

virtual void ScriptingEnv::startExecution ( )
inlinevirtualslotinherited

If the implementation supports asynchronuos execution, activate it.

Definition at line 95 of file ScriptingEnv.h.

95 {}

◆ stopExecution

virtual void ScriptingEnv::stopExecution ( )
inlinevirtualslotinherited

If the implementation supports asynchronuos execution, deactivate it.

Definition at line 93 of file ScriptingEnv.h.

93 {}

◆ sysDict()

PyObject* PythonScripting::sysDict ( )
inline

Definition at line 96 of file PythonScripting.h.

96 { return sys; }

References sys.

◆ toString()

QString PythonScripting::toString ( PyObject object,
bool  decref = false 
)

like str(object) in Python

Convert object to a string. Steals a reference to object if decref is true; borrows otherwise.

Definition at line 88 of file PythonScripting.cpp.

89 {
90  QString ret;
91  if (!object) return "";
92  PyObject *repr = PyObject_Str(object);
93  if (decref) Py_DECREF(object);
94  if (!repr) return "";
95  ret = PYUNICODE_AsUTF8(repr);
96  Py_DECREF(repr);
97  return ret;
98 }

References ScriptingEnv::decref(), and PYUNICODE_AsUTF8.

Referenced by errorMsg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

void PythonScripting::write ( const QString &  text)
inline

Definition at line 52 of file PythonScripting.h.

52 { emit print(text); }

References ScriptingEnv::print().

Member Data Documentation

◆ d_initialized

bool ScriptingEnv::d_initialized
protectedinherited

whether the interpreter has been successfully initialized

Definition at line 110 of file ScriptingEnv.h.

Referenced by initialize(), ScriptingEnv::initialized(), MuParserScripting::MuParserScripting(), PythonScripting(), and ScriptingEnv::ScriptingEnv().

◆ d_parent

ApplicationWindow* ScriptingEnv::d_parent
protectedinherited

the context in which we are running

Definition at line 112 of file ScriptingEnv.h.

Referenced by initialize(), and PythonScripting().

◆ d_refcount

int ScriptingEnv::d_refcount
privateinherited

the reference counter

Definition at line 116 of file ScriptingEnv.h.

Referenced by ScriptingEnv::decref(), ScriptingEnv::incref(), and ScriptingEnv::ScriptingEnv().

◆ globals

PyObject* PythonScripting::globals
private

◆ langName

const char * PythonScripting::langName = "Python"
static

Definition at line 45 of file PythonScripting.h.

Referenced by ScriptingLangManager::newEnv().

◆ math

PyObject* PythonScripting::math
private

◆ sys

PyObject* PythonScripting::sys
private

The documentation for this class was generated from the following files:
PythonScripting::math
PyObject * math
Definition: PythonScripting.h:102
_traceback
Definition: PythonScripting.cpp:45
PythonScripting::setQObject
bool setQObject(QObject *, const char *, PyObject *dict)
Definition: PythonScripting.cpp:388
_traceback::tb_frame
PyFrameObject * tb_frame
Definition: PythonScripting.cpp:48
data
Definition: exp_saturation.c:37
str
#define str(x)
Definition: PythonScripting.cpp:41
ScriptingEnv::fileExtensions
virtual const QStringList fileExtensions() const
Return a list of file extensions commonly used for this language.
Definition: ScriptingEnv.h:76
PythonScripting::setInt
bool setInt(int i, const char *s) override
Definition: PythonScripting.h:86
PythonScripting::toString
QString toString(PyObject *object, bool decref=false)
like str(object) in Python
Definition: PythonScripting.cpp:88
PythonScripting::globals
PyObject * globals
Definition: PythonScripting.h:101
ScriptingEnv::decref
void decref()
Decrease the reference count. This should only be called by scripted and Script to avoid segfaults.
Definition: ScriptingEnv.cpp:65
initQtGui
void initQtGui()
ScriptingEnv::d_parent
ApplicationWindow * d_parent
the context in which we are running
Definition: ScriptingEnv.h:112
ScriptingEnv::initialized
bool initialized() const
initialization of the interpreter may fail; or there could be other errors setting up the environment
Definition: ScriptingEnv.h:61
initscidavis
void initscidavis()
PythonScript
Definition: PythonScript.h:42
PYLong_AsLong
#define PYLong_AsLong
Definition: PythonScripting.cpp:75
ScriptingEnv::d_initialized
bool d_initialized
whether the interpreter has been successfully initialized
Definition: ScriptingEnv.h:110
PythonScripting::langName
static const char * langName
Definition: PythonScripting.h:45
initsip
void initsip()
PythonScripting::setDouble
bool setDouble(double x, const char *s) override
Definition: PythonScripting.h:88
PythonScripting::PythonScripting
PythonScripting(ApplicationWindow *parent, bool batch=false)
Definition: PythonScripting.cpp:190
PythonScripting::loadInitFile
bool loadInitFile(const QString &path)
Definition: PythonScripting.cpp:331
ScriptingEnv::d_refcount
int d_refcount
the reference counter
Definition: ScriptingEnv.h:116
ApplicationWindow::batchMode
bool batchMode() const
running a python batch script
Definition: ApplicationWindow.h:156
_traceback::tb_next
PyObject_HEAD struct _traceback * tb_next
Definition: PythonScripting.cpp:47
ScriptingEnv::print
void print(const QString &output)
output that is not handled by a Script
PYCodeObject_cast
#define PYCodeObject_cast
Definition: PythonScripting.cpp:76
ScriptingEnv::ScriptingEnv
ScriptingEnv(ApplicationWindow *parent, const char *langName)
Definition: ScriptingEnv.cpp:43
name
char * name()
Definition: exp_saturation.c:45
PYUNICODE_AsUTF8
#define PYUNICODE_AsUTF8
Definition: PythonScripting.cpp:73
initQtCore
void initQtCore()
PYUNICODE_FromString
#define PYUNICODE_FromString
Definition: PythonScripting.cpp:74
PythonScripting::sys
PyObject * sys
Definition: PythonScripting.h:103
_traceback::tb_lineno
int tb_lineno
Definition: PythonScripting.cpp:50
PyObject
struct _object PyObject
Definition: PythonScript.h:37
PYTHON_UTIL_PATH
#define PYTHON_UTIL_PATH
Definition: PythonScripting.cpp:328