From 4677b3775dce4c0b2580f070db4ba75253db79f9 Mon Sep 17 00:00:00 2001 From: Mansard <nmansard@laas.fr> Date: Tue, 25 Jan 2011 14:58:18 +0100 Subject: [PATCH] Added a method to bound new commands dynamically. --- src/dynamic_graph/entity.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dynamic_graph/entity.py b/src/dynamic_graph/entity.py index 7c48880..d1d1829 100644 --- a/src/dynamic_graph/entity.py +++ b/src/dynamic_graph/entity.py @@ -3,7 +3,7 @@ Author: Florent Lamiraux """ -import wrap, signal_base +import wrap, signal_base, new entityClassNameList = [] if 'display' not in globals().keys(): @@ -132,6 +132,16 @@ class Entity (object) : except: object.__getattr__(self, name) + def boundNewCommand(self,cmdName): + """ + At construction, all existing commands are bound directly in the class. + This method enables to bound new commands dynamically. These new bounds + are not made with the class, but directly with the object instance. + """ + docstring = wrap.entity_get_command_docstring(self.obj, cmdName) + cmd = commandMethod(cmdName,docstring) + setattr(self,cmdName,new.instancemethod( cmd, self,self.__class__)) + # Script short-cuts: don't use this syntaxt in python coding, # use it for debuging online only! @property -- GitLab