X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUITApp%2FSUITApp_init_python.cxx;h=3724dd562f3ecacc73f235f0909820712faed73c;hb=refs%2Fheads%2Fngr%2Fpython3_dev_pv5.4;hp=b7bab9def6fc5a4e67321fa3b861099511a47a73;hpb=c4b058d18583af7f94042eb55d4b933dd222d2e6;p=modules%2Fgui.git diff --git a/src/SUITApp/SUITApp_init_python.cxx b/src/SUITApp/SUITApp_init_python.cxx index b7bab9def..3724dd562 100644 --- a/src/SUITApp/SUITApp_init_python.cxx +++ b/src/SUITApp/SUITApp_init_python.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,20 @@ // Date : 22/06/2007 // #include "SUITApp_init_python.hxx" +#include + +#if PY_VERSION_HEX < 0x03050000 +static char* +Py_EncodeLocale(const wchar_t *arg, size_t *size) +{ + return _Py_wchar2char(arg, size); +} +static wchar_t* +Py_DecodeLocale(const char *arg, size_t *size) +{ + return _Py_char2wchar(arg, size); +} +#endif bool SUIT_PYTHON::initialized = false; @@ -30,14 +44,34 @@ void SUIT_PYTHON::init_python(int argc, char **argv) { return; } - Py_SetProgramName(argv[0]); + + wchar_t **changed_argv = new wchar_t*[argc]; // Setting arguments + for (int i = 0; i < argc; i++) + { + changed_argv[i] = Py_DecodeLocale(argv[i], NULL); + } + + Py_SetProgramName(changed_argv[0]); Py_Initialize(); // Initialize the interpreter - PySys_SetArgv(argc, argv); - PyEval_InitThreads(); // Create (and acquire) the interpreter lock - can be called many times + PySys_SetArgv(argc, changed_argv); + PyRun_SimpleString("import threading\n"); + // VSR (22/09/2016): This is a workaround to prevent invoking qFatal() from PyQt5 + // causing application aborting + QString script; + script += "def _custom_except_hook(exc_type, exc_value, exc_traceback):\n"; + script += " import sys\n"; + script += " sys.__excepthook__(exc_type, exc_value, exc_traceback)\n"; + script += " pass\n"; + script += "\n"; + script += "import sys\n"; + script += "sys.excepthook = _custom_except_hook\n"; + script += "del _custom_except_hook, sys\n"; + int res = PyRun_SimpleString(qPrintable(script)); + // VSR (22/09/2016): end of workaround + PyEval_InitThreads(); // Create (and acquire) the interpreter lock - can be called many times // Py_InitThreads acquires the GIL PyThreadState *pts = PyGILState_GetThisThreadState(); PyEval_ReleaseThread(pts); SUIT_PYTHON::initialized = true; } -