void PythonConsole::initPython(PythonHandler *pythonHandler) { try { mp_mainThreadState = pythonHandler->getMainThreadState(); PyGILState_STATE gstate = PyGILState_Ensure(); boost::python::object main_module(boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))); boost::python::object main_namespace = main_module.attr("__dict__"); // import code boost::python::object code = boost::python::import("code"); main_namespace["code"] = code; // import __main__ main_namespace["__main__"] = main_namespace; // get ref to code.InteractiveConsole().push() m_console = eval("code.InteractiveConsole(__main__)", main_namespace, main_namespace); m_pushFunc = m_console.attr("push"); m_sys = main_namespace["sys"]; PyGILState_Release(gstate); } catch(...) { PyErr_Print(); } }
python_persistency() { // changed to skip installation of signal handlers [PS] // Py_InitializeEx(0); // Py_Initialize(); // char string_main[]="__main__"; boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule(string_main))))); main_namespace = main_module.attr("__dict__"); };
void m_assembly(FILE *fp, FILE *sfp, int op1, int op2) { char _Tmp[255]; char *_Ptr; if( fp != NULL ) { while( !feof(fp) ) { _Ptr = fgets(_Tmp, sizeof(_Tmp), fp); main_module(sfp, _Ptr); } fclose(fp); } }
python_persistency(std::string file_name) { // changed to skip installation of signal handlers [PS] // Py_InitializeEx(0); // Py_Initialize(); // char string_main[]="__main__"; boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule(string_main))))); main_namespace = main_module.attr("__dict__"); FILE* file = fopen(file_name.c_str(),"r"); if (file == 0) { std::cerr << "no file of name: " << file_name << std::endl; exit(-1); } PyRun_SimpleFile(file, file_name.c_str()); };
interpreter_t::interpreter_t() { PyImport_AppendInittab(( char *) "_ramen", &init_ramen); Py_Initialize(); bpy::object main_module( bpy::handle<>( bpy::borrowed( PyImport_AddModule( "__main__")))); main_namespace_ = main_module.attr( "__dict__"); setup_python_paths( main_namespace_); init_pyside(); // default import our module. bpy::object module(( bpy::handle<>( PyImport_ImportModule( "ramen")))); main_namespace_[ "ramen"] = module; exec( "from ramen import *"); // execute startup files bfs::path exec_path = app().system().executable_path(); bfs::path py_path = exec_path.parent_path() / "../python"; exec_file( py_path / "app/init.py"); exec_file( app().system().home_path() / "ramen/python/init.py"); }