File: PythonInterpreter.cpp

package info (click to toggle)
tulip 3.7.0dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 39,428 kB
  • sloc: cpp: 231,403; php: 11,023; python: 1,128; sh: 671; yacc: 522; makefile: 315; xml: 63; lex: 55
file content (678 lines) | stat: -rwxr-xr-x 18,839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */

#include "PythonIncludes.h"
#include "PythonInterpreter.h"
#include "ConsoleOutputModule.h"
#include "TulipUtilsModule.h"

#include <iostream>
#include <sstream>

#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtCore/QTime>

#include <sip.h>

#include <cstdio>
#ifndef WIN32
#include <dlfcn.h>
#endif

using namespace std;

#ifndef WIN32
static PyThreadState*  mainThreadState;
#endif

static PyGILState_STATE gilState;

static const string printObjectDictFunction =
  "def printObjectDict(obj):\n"
  "	if hasattr(obj, \"__dict__\"):\n"
  "		for k in obj.__dict__.keys():\n"
  "			print k\n"
  "	if hasattr(obj, \"__class__\"):\n"
  "		for k in obj.__class__.__dict__.keys():\n"
  "			print k\n"
  ""
  ;

static const string printObjectClassFunction =
  "def printObjectClass(obj):\n"
  "	type = \"\"\n"
  "	if obj and hasattr(obj, \"__class__\"):\n"
  "		if hasattr(obj.__class__, \"__module__\"):\n"
  "			mod = obj.__class__.__module__\n"
  "			if mod == \"tulip\":"
  "				mod = \"tlp\"\n"
  "			type = mod + \".\"\n"
  "		if hasattr(obj.__class__, \"__name__\"):\n"
  "			type = type + obj.__class__.__name__\n"
  "		print type\n"
  ""
  ;

const sipAPIDef *get_sip_api() {
#if defined(SIP_USE_PYCAPSULE)
  return (const sipAPIDef *)PyCapsule_Import("sip._C_API", 0);
#else
  PyObject *sip_module;
  PyObject *sip_module_dict;
  PyObject *c_api;

  /* Import the SIP module. */
  sip_module = PyImport_ImportModule("sip");

  if (sip_module == NULL)
    return NULL;

  /* Get the module's dictionary. */
  sip_module_dict = PyModule_GetDict(sip_module);

  /* Get the "_C_API" attribute. */
  c_api = PyDict_GetItemString(sip_module_dict, "_C_API");

  if (c_api == NULL)
    return NULL;

  /* Sanity check that it is the right type. */
  if (!PyCObject_Check(c_api))
    return NULL;

  /* Get the actual pointer from the object. */
  return (const sipAPIDef *)PyCObject_AsVoidPtr(c_api);
#endif
}

ConsoleOutputDialog::ConsoleOutputDialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint) {
  setWindowTitle("Python Interpreter Output");
  consoleWidget = new QPlainTextEdit(this);
  QHBoxLayout *hLayout = new QHBoxLayout();
  QPushButton *clearButton = new QPushButton("Clear");
  connect(clearButton, SIGNAL(clicked()), consoleWidget, SLOT(clear()));
  QPushButton *closeButton = new QPushButton("Close");
  connect(closeButton, SIGNAL(clicked()), this, SLOT(hideConsoleOutputDialog()));
  hLayout->addItem(new QSpacerItem(100, 20, QSizePolicy::Expanding));
  hLayout->addWidget(clearButton);
  hLayout->addWidget(closeButton);
  QVBoxLayout *layout = new QVBoxLayout();
  layout->addWidget(consoleWidget);
  layout->addLayout(hLayout);
  setLayout(layout);
  connect(consoleWidget, SIGNAL(textChanged()), this, SLOT(showOnOutputWrite()));
  resize(400,300);
}


void ConsoleOutputDialog::showOnOutputWrite() {
  if (!isVisible()) {
    move(lastPos);
    show();
  }
}

void ConsoleOutputDialog::hideConsoleOutputDialog() {
  lastPos = pos();
  hide();
}

static bool scriptPaused = false;
static bool processQtEvents = false;

QTime timer;

int tracefunc(PyObject *, PyFrameObject *, int what, PyObject *) {

  if (what == PyTrace_LINE) {
    if (!scriptPaused && timer.elapsed() >= 50) {
      if (processQtEvents && QApplication::hasPendingEvents())
        QApplication::processEvents();

      timer.start();
    }

    while (scriptPaused) {
      if (timer.elapsed() >= 50) {
        if (processQtEvents && QApplication::hasPendingEvents())
          QApplication::processEvents();

        timer.start();
      }
    }

  }

  return 0;
}

PythonInterpreter PythonInterpreter::instance;

#ifdef _MSC_VER
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  switch (ul_reason_for_call) {
  case DLL_PROCESS_ATTACH:

    if (QApplication::instance()) {
      PythonInterpreter::getInstance()->initConsoleOutput();
      PythonInterpreter::getInstance()->loadTulipPythonPlugins();
    }

    break;

  case DLL_THREAD_ATTACH:
  case DLL_THREAD_DETACH:
    break;

  case DLL_PROCESS_DETACH:
    break;
  }

  return TRUE;
}
#endif

PythonInterpreter::PythonInterpreter() : runningScript(false), consoleDialog(NULL) {

  int argc=1;
  char *argv[1];
  argv[0] = const_cast<char *>("");
  Py_OptimizeFlag = 1;
  Py_NoSiteFlag = 1;
  Py_InitializeEx(0);

  PyEval_InitThreads();
#ifndef WIN32
  mainThreadState = PyEval_SaveThread();
#else
  PyThreadState* tcur = PyThreadState_Get() ;
  PyThreadState_Swap(NULL);
  PyThreadState_Clear(tcur);
  PyThreadState_Delete(tcur);
#endif
  PyEval_ReleaseLock();

  holdGIL();

  PySys_SetArgv(argc, argv);

  runString("import sys");
  PyObject *pName = PyString_FromString("__main__");
  PyObject *pMainModule = PyImport_Import(pName);
  Py_DECREF(pName);
  PyObject *pMainDict = PyModule_GetDict(pMainModule);
  PyObject *pVersion = PyRun_String("str(sys.version_info[0])+\".\"+str(sys.version_info[1])", Py_eval_input, pMainDict, pMainDict);
  pythonVersion = string(PyString_AsString(pVersion));

  // checking if a QApplication is instanced before instancing any QWidget
  // allow to avoid segfaults when trying to instantiate the plugin outside the Tulip GUI (for instance, with tulip_check_pl)
  if (QApplication::instance()) {

    // hack for linux in order to be able to load dynamic python modules installed on the system (like numpy, matplotlib and other cool stuffs)
#ifndef WIN32
    string libPythonName = string("libpython") + pythonVersion;
#ifdef __APPLE__
    libPythonName += string(".dylib");
#else
    libPythonName += string(".so.1.0");
#endif
    dlopen(libPythonName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
#endif

#if !defined(_MSC_VER)
    initConsoleOutput();
#endif

    if (interpreterInit()) {

      addModuleSearchPath(pythonPluginsPath, true);
      addModuleSearchPath(pythonPluginsPathHome);

#ifdef __APPLE__
      addModuleSearchPath(tlp::TulipLibDir + "../Frameworks", true);
#else
      addModuleSearchPath(tlp::TulipLibDir, true);
#endif

      initscriptengine();
      _PyImport_FixupExtension(const_cast<char *>("scriptengine"), const_cast<char *>("scriptengine"));

      inittuliputils();
      _PyImport_FixupExtension(const_cast<char *>("tuliputils"), const_cast<char *>("tuliputils"));

      runString("import sys; import scriptengine ; import tuliputils ; sys.stdout = scriptengine.ConsoleOutput(False); sys.stderr = scriptengine.ConsoleOutput(True);\n");

      // Try to import site package manually otherwise Py_InitializeEx can crash if Py_NoSiteFlag is not set
      // and if the site module is not present on the host system
      // Disable output while trying to import the module to not confuse the user
      outputActivated = false;
      runString("import site");
      outputActivated = true;

      runString("from tulip import *");

#ifndef _MSC_VER
      loadTulipPythonPlugins();
#endif

      runString(printObjectDictFunction);
      runString(printObjectClassFunction);
    }
  }

  PyEval_SetTrace(tracefunc, NULL);

  releaseGIL();


}

PythonInterpreter::~PythonInterpreter() {
  processQtEvents = false;

  if (interpreterInit()) {
#ifndef WIN32
    PyEval_ReleaseLock();
    PyEval_RestoreThread(mainThreadState);
#else
    holdGIL();
#endif
    Py_Finalize();
  }

  delete consoleDialog;
  delete consoleOuputEmitter;
  consoleOuputEmitter = NULL;
  delete consoleOuputHandler;
  consoleOuputHandler = NULL;
}

PythonInterpreter *PythonInterpreter::getInstance() {
  return &instance;
}

void PythonInterpreter::initConsoleOutput() {
  consoleOuputHandler = new ConsoleOutputHandler();
  consoleOuputEmitter = new ConsoleOutputEmitter();
  consoleDialog = new ConsoleOutputDialog();
  setDefaultConsoleWidget();
}

void PythonInterpreter::loadTulipPythonPlugins() {
  loadTulipPythonPlugins(pythonPluginsPath);
  loadTulipPythonPlugins(pythonPluginsPathHome);
}

void PythonInterpreter::loadTulipPythonPlugins(const std::string &pluginsPath) {
  QDir pythonPluginsDir(pluginsPath.c_str());
  QStringList nameFilter;
  nameFilter << "*.py";
  QFileInfoList fileList = pythonPluginsDir.entryInfoList(nameFilter);

  for (int i = 0 ; i < fileList.size() ; ++i) {
    QFileInfo fileInfo = fileList.at(i);
    QString moduleName = fileInfo.fileName();
    moduleName.replace(".py", "");
    runString("import " + moduleName.toStdString());
  }

  // some external modules (like numpy) overrides the SIGINT handler at import
  // reinstall the default one, otherwise Tulip can not be interrupted by hitting Ctrl-C in a console
  setDefaultSIGINTHandler();
}

bool PythonInterpreter::interpreterInit() {
  holdGIL();
  bool ret = Py_IsInitialized();
  releaseGIL();
  return ret;
}

bool PythonInterpreter::registerNewModuleFromString(const std::string &moduleName, const std::string &moduleSrcCode) {
  bool ret = true;
  holdGIL();
  ostringstream oss;
  oss << moduleName << ".py";
  PyObject *pycomp = Py_CompileString(moduleSrcCode.c_str(),oss.str().c_str(), Py_file_input);

  if (pycomp == NULL) {
    PyErr_Print();
    PyErr_Clear();
    ret = false;
  }

  PyObject *pmod = PyImport_ExecCodeModule(const_cast<char *>(moduleName.c_str()),pycomp);

  if (pmod == NULL) {
    PyErr_Print();
    PyErr_Clear();
    ret = false;
  }

  releaseGIL();
  return ret;
}

bool PythonInterpreter::functionExists(const string &moduleName, const string &functionName) {
  holdGIL();
  PyObject *pName = PyString_FromString(moduleName.c_str());
  PyObject *pModule = PyImport_Import(pName);
  Py_DECREF(pName);
  PyObject *pDict = PyModule_GetDict(pModule);
  PyObject *pFunc = PyDict_GetItemString(pDict, functionName.c_str());
  bool ret = (pFunc != NULL && PyCallable_Check(pFunc));
  releaseGIL();
  return ret;
}

bool PythonInterpreter::runString(const string &pyhtonCode, const std::string &scriptFilePath) {
  if (consoleOuputHandler)
    consoleOuputHandler->setMainScriptFileName(scriptFilePath.c_str());

  timer.start();
  int ret = 0;
  holdGIL();
  ret = PyRun_SimpleString(pyhtonCode.c_str());

  if (PyErr_Occurred()) {
    PyErr_Print();
    PyErr_Clear();
  }

  releaseGIL();
  return  ret != -1;
}

void PythonInterpreter::addModuleSearchPath(const std::string &path, const bool beforeOtherPaths) {
  if (currentImportPaths.find(path) == currentImportPaths.end()) {
    ostringstream oss;
    oss << "import sys" << endl;

    if (beforeOtherPaths) {
      oss << "sys.path.insert(0, \"" << path << "\")" << endl;
    }
    else {
      oss << "sys.path.append(\"" << path << "\")" << endl;
    }

    runString(oss.str());
    currentImportPaths.insert(path);
  }
}

bool PythonInterpreter::runGraphScript(const string &module, const string &function, tlp::Graph *graph, const std::string &scriptFilePath) {

  if (consoleOuputHandler)
    consoleOuputHandler->setMainScriptFileName(scriptFilePath.c_str());

  timer.start();

  holdGIL();

  bool ret = true;
  scriptPaused = false;

  // Build the name object
  PyObject *pName = PyString_FromString(module.c_str());

  // Load the module object
  PyObject *pModule = PyImport_Import(pName);
  Py_DECREF(pName);

  // pDict is a borrowed reference
  PyObject *pDict = PyModule_GetDict(pModule);

  // pFunc is also a borrowed reference
  PyObject *pFunc = PyDict_GetItemString(pDict, function.c_str());

  if (PyCallable_Check(pFunc)) {
    const sipAPIDef *sisApi = get_sip_api();

    // Getting proper sipWrapperType
    const sipTypeDef* kpTypeDef     = sisApi->api_find_type("tlp::Graph");

    // Wrapping up C++ instance
    PyObject* pArgs = sisApi->api_convert_from_type(graph, kpTypeDef, NULL);

    // Finally calling 'process'
    PyObject* argTup = Py_BuildValue ("(O)", pArgs);
    runningScript = true;

    try {
      PyObject_CallObject(pFunc, argTup);
    }
    catch (exception &e) {
      ostringstream oss;
      oss << "A C++ exception (" << e.what() << ") has been thrown while executing the script";
      PyErr_SetString(PyExc_Exception, oss.str().c_str());
    }
    catch(...) {
      PyErr_SetString(PyExc_Exception, "A C++ exception has been thrown while executing the script");
    }

    runningScript = false;
    Py_DECREF(argTup);
    Py_DECREF(pArgs);

    if (PyErr_Occurred()) {
      PyErr_Print();
      ret = false;
    }

  }
  else {
    PyErr_Print();
    ret =  false;
  }

  releaseGIL();

  return ret;
}

int stopScript(void *) {
  PyErr_SetString(PyExc_Exception, "Script execution terminated by user");
  return -1;
}

void PythonInterpreter::stopCurrentScript() {
  holdGIL();
  Py_AddPendingCall(&stopScript, NULL);
  releaseGIL();
  scriptPaused = false;
}

void PythonInterpreter::deleteModule(const std::string &moduleName) {
  ostringstream oss;
  oss << "import sys" << endl;
  oss << "if \"" << moduleName << "\" in sys.modules:" << endl;
  oss << "\tdel sys.modules[\"" << moduleName << "\"]" << endl;
  runString(oss.str());
}

bool PythonInterpreter::reloadModule(const std::string &moduleName) {
  ostringstream oss;
  oss << "import " << moduleName << endl;
  oss << "reload(" << moduleName << ")" << endl;
  return runString(oss.str());
}

void PythonInterpreter::setConsoleWidget(QPlainTextEdit *console) {
  if (consoleOuputHandler) {
    consoleOuputEmitter->setOutputActivated(true);
    consoleOuputEmitter->setConsoleWidget(console);
    QObject::disconnect(consoleOuputEmitter, SIGNAL(consoleOutput(QPlainTextEdit*, const QString &, bool)), consoleOuputHandler, SLOT(writeToConsole(QPlainTextEdit*, const QString &, bool)));
    QObject::connect(consoleOuputEmitter, SIGNAL(consoleOutput(QPlainTextEdit*, const QString &, bool)), consoleOuputHandler, SLOT(writeToConsole(QPlainTextEdit*, const QString &, bool)));
  }
}

void PythonInterpreter::setDefaultConsoleWidget() {
  if (consoleDialog) {
    consoleOuputEmitter->setOutputActivated(true);
    consoleOuputEmitter->setConsoleWidget(consoleDialog->consoleWidget);
    QObject::disconnect(consoleOuputEmitter, SIGNAL(consoleOutput(QPlainTextEdit*, const QString &, bool)), consoleOuputHandler, SLOT(writeToConsole(QPlainTextEdit*, const QString &, bool)));
    QObject::connect(consoleOuputEmitter, SIGNAL(consoleOutput(QPlainTextEdit*, const QString &, bool)), consoleOuputHandler, SLOT(writeToConsole(QPlainTextEdit*, const QString &, bool)), Qt::QueuedConnection);
  }
}

void PythonInterpreter::setDefaultSIGINTHandler() {
  if (consoleOuputEmitter) {
    consoleOuputEmitter->setOutputActivated(false);
  }

  if (runString("import signal")) {
    runString("signal.signal(signal.SIGINT, signal.SIG_DFL)");
  }

  if (consoleOuputEmitter) {
    consoleOuputEmitter->setOutputActivated(true);
  }
}

std::string PythonInterpreter::getPythonShellBanner() {
  holdGIL();
  string ret = string("Python ") + string(Py_GetVersion()) + string(" on ") + string(Py_GetPlatform());
  releaseGIL();
  return ret;
}

std::vector<std::string> PythonInterpreter::getGlobalDictEntries(const std::string &prefixFilter) {
  std::vector<std::string> ret;
  std::set<std::string> publicMembersSorted;
  outputActivated = false;
  consoleOuputString = "";
  runString("import __main__;printObjectDict(__main__)");
  QStringList objectDictList = QString(consoleOuputString.c_str()).split("\n");

  for (int i = 0 ; i < objectDictList.count() ; ++i) {
    if (objectDictList[i] != "") {
      if (objectDictList[i].startsWith("_")) {
        continue;
      }
      else {
        if (prefixFilter != "") {
          if (objectDictList[i].startsWith(QString(prefixFilter.c_str()))) {
            publicMembersSorted.insert(objectDictList[i].toStdString());
          }
        }
        else {
          publicMembersSorted.insert(objectDictList[i].toStdString());
        }
      }

    }
  }

  set<string>::iterator it;

  for (it = publicMembersSorted.begin() ; it != publicMembersSorted.end() ; ++it) {
    ret.push_back(*it);
  }

  outputActivated = true;
  return ret;
}

std::string PythonInterpreter::getVariableType(const std::string &varName) {
  outputActivated = false;
  consoleOuputString = "";
  runString("printObjectClass("+varName+")");
  outputActivated = true;
  return consoleOuputString.substr(0, consoleOuputString.size() - 1);
}

std::vector<std::string> PythonInterpreter::getObjectDictEntries(const std::string &objectName, const std::string &prefixFilter) {
  std::vector<std::string> ret;
  std::set<std::string> publicMembersSorted;
  outputActivated = false;
  consoleOuputString = "";

  if (runString(objectName)) {
    ostringstream oss;
    oss << "printObjectDict(" << objectName << ")";
    runString(oss.str());
    QStringList objectDictList = QString(consoleOuputString.c_str()).split("\n");

    for (int i = 0 ; i < objectDictList.count() ; ++i) {
      if (objectDictList[i] != "") {
        if (objectDictList[i].startsWith("_")) {
          continue;
        }
        else {
          if (prefixFilter != "") {
            if (objectDictList[i].startsWith(QString(prefixFilter.c_str()))) {
              publicMembersSorted.insert(objectDictList[i].toStdString());
            }
          }
          else {
            publicMembersSorted.insert(objectDictList[i].toStdString());
          }
        }

      }
    }

    set<string>::iterator it;

    for (it = publicMembersSorted.begin() ; it != publicMembersSorted.end() ; ++it) {
      ret.push_back(*it);
    }
  }

  outputActivated = true;
  return ret;
}

void PythonInterpreter::holdGIL() {
  gilState = PyGILState_Ensure();
}

void PythonInterpreter::releaseGIL() {
  PyGILState_Release(gilState);
}

std::string PythonInterpreter::getStandardOutput() const {
  return consoleOuputString;
}

std::string PythonInterpreter::getStandardErrorOutput() const {
  return consoleErrorOuputString;
}

void PythonInterpreter::clearOutputBuffers() {
  consoleOuputString = "";
  consoleErrorOuputString = "";
}

void PythonInterpreter::pauseCurrentScript(const bool pause) {
  scriptPaused = pause;
}

bool PythonInterpreter::isScriptPaused() const {
  return scriptPaused;
}

void PythonInterpreter::setProcessQtEventsDuringScriptExecution(bool processEvents) {
  processQtEvents = processEvents;
}