-----------------------------------------------------------------------------
| 133 | |
| 134 | //----------------------------------------------------------------------------- |
| 135 | void ctkAbstractPythonManager::initPythonQt(int flags) |
| 136 | { |
| 137 | Q_D(ctkAbstractPythonManager); |
| 138 | |
| 139 | PythonQt::init(flags); |
| 140 | |
| 141 | // Python maps SIGINT (control-c) to its own handler. We will remap it |
| 142 | // to the default so that control-c works. |
| 143 | #ifdef SIGINT |
| 144 | signal(SIGINT, SIG_DFL); |
| 145 | #endif |
| 146 | |
| 147 | // Forward signal from PythonQt::self() to this instance of ctkAbstractPythonManager |
| 148 | this->connect(PythonQt::self(), SIGNAL(systemExitExceptionRaised(int)), |
| 149 | SIGNAL(systemExitExceptionRaised(int))); |
| 150 | |
| 151 | this->connect(PythonQt::self(), SIGNAL(pythonStdOut(QString)), |
| 152 | SLOT(printStdout(QString))); |
| 153 | this->connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)), |
| 154 | SLOT(printStderr(QString))); |
| 155 | |
| 156 | PythonQt_init_QtBindings(); |
| 157 | |
| 158 | QStringList initCode; |
| 159 | |
| 160 | // Update 'sys.path' |
| 161 | initCode << "import sys"; |
| 162 | foreach (const QString& path, this->pythonPaths()) |
| 163 | { |
| 164 | initCode << QString("sys.path.append(%1)").arg(QDir::fromNativeSeparators(path)); |
| 165 | } |
| 166 | |
| 167 | PythonQtObjectPtr _mainContext = PythonQt::self()->getMainModule(); |
| 168 | _mainContext.evalScript(initCode.join("\n")); |
| 169 | |
| 170 | this->preInitialization(); |
| 171 | if (d->InitFunction) |
| 172 | { |
| 173 | (*d->InitFunction)(); |
| 174 | } |
| 175 | emit this->pythonPreInitialized(); |
| 176 | |
| 177 | this->executeInitializationScripts(); |
| 178 | emit this->pythonInitialized(); |
| 179 | } |
| 180 | |
| 181 | //----------------------------------------------------------------------------- |
| 182 | bool ctkAbstractPythonManager::isPythonInitialized()const |
no test coverage detected