diff --git a/src/dynamic_graph/entity.py b/src/dynamic_graph/entity.py index 8360ea195b0fc592f5c53da7f80c1a3aea8dd210..7c488807a7e0dff6d8bc7e6a85bf6b1f2c4b1bba 100644 --- a/src/dynamic_graph/entity.py +++ b/src/dynamic_graph/entity.py @@ -6,6 +6,10 @@ import wrap, signal_base entityClassNameList = [] +if 'display' not in globals().keys(): + def display(s): + print(s) + def commandMethod(name, docstring) : def method(self, *arg): @@ -80,10 +84,10 @@ class Entity (object) : Print the list of signals into standard output: temporary. """ signals = self.signals() - print "--- <" + self.name + "> signal list: " + display ("--- <" + self.name + "> signal list: ") for s in signals[:-1]: - print " |-- <" + str(s) - print " `-- <" + str(signals[-1]) + display(" |-- <" + str(s)) + display(" `-- <" + str(signals[-1])) def signals(self) : """ @@ -108,7 +112,7 @@ class Entity (object) : ctitle+=' ' for docstr in wrap.entity_get_command_docstring(self.obj,cstr).split('\n'): if (len(docstr)>0) and (not docstr.isspace()): - print ctitle+"\t"+docstr + display(ctitle+"\t"+docstr) break def help( self,comm=None ): @@ -119,7 +123,7 @@ class Entity (object) : if comm is None: self.globalHelp() else: - print comm+":\n"+wrap.entity_get_command_docstring(self.obj,comm) + display(comm+":\n"+wrap.entity_get_command_docstring(self.obj,comm)) def __getattr__(self, name): diff --git a/src/interpreter.cc b/src/interpreter.cc index 98493825b636e44e6833c8208efc5ac83f0f5fc6..23c8b270e4a49d5fc529cdd09b49f6b1ce0ee3db 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -20,11 +20,12 @@ // Python initialization commands namespace dynamicgraph { namespace python { - static const std::string pythonPrefix[4] = { + static const std::string pythonPrefix[5] = { "import sys\n", "import traceback\n", "if '' not in sys.path: sys.path.append('')\n", "sys.argv = ['']\n", + "def display(s): return str(s) if not s is None else None" }; } } @@ -43,6 +44,7 @@ Interpreter::Interpreter() PyRun_SimpleString(pythonPrefix[1].c_str()); PyRun_SimpleString(pythonPrefix[2].c_str()); PyRun_SimpleString(pythonPrefix[3].c_str()); + PyRun_SimpleString(pythonPrefix[4].c_str()); traceback_format_exception_ = PyDict_GetItemString (PyModule_GetDict(PyImport_AddModule("traceback")), "format_exception"); assert(PyCallable_Check(traceback_format_exception_)); @@ -51,9 +53,9 @@ Interpreter::Interpreter() Interpreter::~Interpreter() { - Py_DECREF(mainmod_); - Py_DECREF(globals_); - Py_DECREF(traceback_format_exception_); + //Py_DECREF(mainmod_); + //Py_DECREF(globals_); + //Py_DECREF(traceback_format_exception_); Py_Finalize(); } @@ -103,6 +105,7 @@ void Interpreter::runPythonFile( std::string filename ) PyRun_SimpleString(pythonPrefix[0].c_str()); PyRun_SimpleString(pythonPrefix[1].c_str()); PyRun_SimpleString(pythonPrefix[2].c_str()); + PyRun_SimpleString(pythonPrefix[4].c_str()); PyRun_SimpleFile(NULL, filename.c_str()); }