Skip to content
Snippets Groups Projects
Commit 58937676 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Define function display.

       This function is equivalent to print() under python,
       is equivalent to str() in dg-python.
parent 9309fd20
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
import wrap, signal_base import wrap, signal_base
entityClassNameList = [] entityClassNameList = []
if 'display' not in globals().keys():
def display(s):
print(s)
def commandMethod(name, docstring) : def commandMethod(name, docstring) :
def method(self, *arg): def method(self, *arg):
...@@ -80,10 +84,10 @@ class Entity (object) : ...@@ -80,10 +84,10 @@ class Entity (object) :
Print the list of signals into standard output: temporary. Print the list of signals into standard output: temporary.
""" """
signals = self.signals() signals = self.signals()
print "--- <" + self.name + "> signal list: " display ("--- <" + self.name + "> signal list: ")
for s in signals[:-1]: for s in signals[:-1]:
print " |-- <" + str(s) display(" |-- <" + str(s))
print " `-- <" + str(signals[-1]) display(" `-- <" + str(signals[-1]))
def signals(self) : def signals(self) :
""" """
...@@ -108,7 +112,7 @@ class Entity (object) : ...@@ -108,7 +112,7 @@ class Entity (object) :
ctitle+=' ' ctitle+=' '
for docstr in wrap.entity_get_command_docstring(self.obj,cstr).split('\n'): for docstr in wrap.entity_get_command_docstring(self.obj,cstr).split('\n'):
if (len(docstr)>0) and (not docstr.isspace()): if (len(docstr)>0) and (not docstr.isspace()):
print ctitle+"\t"+docstr display(ctitle+"\t"+docstr)
break break
def help( self,comm=None ): def help( self,comm=None ):
...@@ -119,7 +123,7 @@ class Entity (object) : ...@@ -119,7 +123,7 @@ class Entity (object) :
if comm is None: if comm is None:
self.globalHelp() self.globalHelp()
else: 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): def __getattr__(self, name):
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
// Python initialization commands // Python initialization commands
namespace dynamicgraph { namespace dynamicgraph {
namespace python { namespace python {
static const std::string pythonPrefix[4] = { static const std::string pythonPrefix[5] = {
"import sys\n", "import sys\n",
"import traceback\n", "import traceback\n",
"if '' not in sys.path: sys.path.append('')\n", "if '' not in sys.path: sys.path.append('')\n",
"sys.argv = ['']\n", "sys.argv = ['']\n",
"def display(s): return str(s) if not s is None else None"
}; };
} }
} }
...@@ -43,6 +44,7 @@ Interpreter::Interpreter() ...@@ -43,6 +44,7 @@ Interpreter::Interpreter()
PyRun_SimpleString(pythonPrefix[1].c_str()); PyRun_SimpleString(pythonPrefix[1].c_str());
PyRun_SimpleString(pythonPrefix[2].c_str()); PyRun_SimpleString(pythonPrefix[2].c_str());
PyRun_SimpleString(pythonPrefix[3].c_str()); PyRun_SimpleString(pythonPrefix[3].c_str());
PyRun_SimpleString(pythonPrefix[4].c_str());
traceback_format_exception_ = PyDict_GetItemString traceback_format_exception_ = PyDict_GetItemString
(PyModule_GetDict(PyImport_AddModule("traceback")), "format_exception"); (PyModule_GetDict(PyImport_AddModule("traceback")), "format_exception");
assert(PyCallable_Check(traceback_format_exception_)); assert(PyCallable_Check(traceback_format_exception_));
...@@ -51,9 +53,9 @@ Interpreter::Interpreter() ...@@ -51,9 +53,9 @@ Interpreter::Interpreter()
Interpreter::~Interpreter() Interpreter::~Interpreter()
{ {
Py_DECREF(mainmod_); //Py_DECREF(mainmod_);
Py_DECREF(globals_); //Py_DECREF(globals_);
Py_DECREF(traceback_format_exception_); //Py_DECREF(traceback_format_exception_);
Py_Finalize(); Py_Finalize();
} }
...@@ -103,6 +105,7 @@ void Interpreter::runPythonFile( std::string filename ) ...@@ -103,6 +105,7 @@ void Interpreter::runPythonFile( std::string filename )
PyRun_SimpleString(pythonPrefix[0].c_str()); PyRun_SimpleString(pythonPrefix[0].c_str());
PyRun_SimpleString(pythonPrefix[1].c_str()); PyRun_SimpleString(pythonPrefix[1].c_str());
PyRun_SimpleString(pythonPrefix[2].c_str()); PyRun_SimpleString(pythonPrefix[2].c_str());
PyRun_SimpleString(pythonPrefix[4].c_str());
PyRun_SimpleFile(NULL, filename.c_str()); PyRun_SimpleFile(NULL, filename.c_str());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment