コード例 #1
0
 def help( self,comm=None ):
     """
     With no arg, print the global help. With arg the name of
     a specific command, print the help associated to the command.
     """
     if comm is None:
         self.globalHelp()
     else:
         display(comm+":\n"+wrap.entity_get_command_docstring(self.obj,comm))
コード例 #2
0
 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.
     """
     if (cmdName in self.__dict__) | (cmdName in self.__class__.__dict__):
         print("Warning: command ",cmdName," will overwrite an object attribute.")
     docstring = wrap.entity_get_command_docstring(self.obj, cmdName)
     cmd = Entity.createCommandBind(cmdName,docstring)
     # Limitation (todo): does not handle for path attribute name (see setattrpath).
     setattr(self,cmdName,new.instancemethod( cmd, self,self.__class__))
コード例 #3
0
 def boundClassCommands(self):
     """
     This static function has to be called from a class heritating from Entity.
     It should be called only once. It parses the list of commands obtained from
     c++, and bind each of them to a python class method.
     """
     # Get list of commands of the Entity object
     commands = wrap.entity_list_commands(self.obj)
     # for each command, add a method with the name of the command
     for cmdstr in commands:
         docstr = wrap.entity_get_command_docstring(self.obj, cmdstr)
         cmdpy = Entity.createCommandBind(cmdstr, docstr)
         setattrpath(self.__class__, cmdstr, cmdpy)
コード例 #4
0
 def globalHelp(self):
     """
     Print a short description of each command.
     """
     if self.__doc__ :
         print self.__doc__
     print "List of commands:"
     print "-----------------"
     for cstr in self.commands():
         ctitle=cstr+':'
         for i in range(len(cstr),15):
             ctitle+=' '
         for docstr in wrap.entity_get_command_docstring(self.obj,cstr).split('\n'):
             if (len(docstr)>0) and (not docstr.isspace()):
                 display(ctitle+"\t"+docstr)
                 break