Ejemplo n.º 1
0
    def from_function(cls, function, function_view_class=None, active_experiment=None):
        """ Create a FunctionCall object given a CallableInfo.  

            The bindings for inputs and outputs will default to Undefined.
            The location for the function will default to the file information
            for the function.           
            
            Note that this currently only works for PythonFunctionInfo and 
            LocalPythonFunctionInfo objects.
        """
    
        callable_object = PythonFunctionInfo.from_function(function)
        return cls.from_callable_object(callable_object, function_view_class, active_experiment)
Ejemplo n.º 2
0
    def from_function(cls, function, function_view_class=None, active_experiment=None):
        """ Create a FunctionCall object given a CallableInfo.  

            The bindings for inputs and outputs will default to Undefined.
            The location for the function will default to the file information
            for the function.           
            
            Note that this currently only works for PythonFunctionInfo and 
            LocalPythonFunctionInfo objects.
        """
    
        callable_object = PythonFunctionInfo.from_function(function)
        return cls.from_callable_object(callable_object, function_view_class, active_experiment)
Ejemplo n.º 3
0
    def set_function_help(self, function_name, module_name):
        """ Display Beautified version of a function doc-string.

            The function is specified as the name of the function and the
            module name for the function.
        """
        func = PythonFunctionInfo(name=function_name, module=module_name)

        if func.doc_string == "":
            self.set_text("No information about this function.")
        else:
            self._html = rest_html.convert_function_info(
                func.name, func.doc_string)
Ejemplo n.º 4
0
def python_function_info_from_function(python_func, **traits):
    """ Factory method for returning a CallableInfo given a python function.
    """
    from python_function_info import PythonFunctionInfo
    from extension_function_info import ExtensionFunctionInfo

    if isinstance(python_func, FunctionType):
        return PythonFunctionInfo.from_function(python_func, **traits)
    elif isinstance(python_func, BuiltinFunctionType) or \
         isinstance(python_func, ufunc):
        return ExtensionFunctionInfo.from_function(python_func, **traits)
    else:
        raise ValueError("%r not a function" % python_func)
Ejemplo n.º 5
0
def python_function_info_from_function(python_func, **traits):
    """ Factory method for returning a CallableInfo given a python function.
    """
    from python_function_info import PythonFunctionInfo
    from extension_function_info import ExtensionFunctionInfo

    if isinstance(python_func, FunctionType):
        return PythonFunctionInfo.from_function(python_func, **traits)
    elif isinstance(python_func, BuiltinFunctionType) or \
         isinstance(python_func, ufunc):
        return ExtensionFunctionInfo.from_function(python_func, **traits)
    else:
        raise ValueError("%r not a function" % python_func)
    def _get_description(self, function_info):
        """ Grab a short text description of the described function.

            The first line in the doc-string is returned if it is available.
            Otherwise, an empty string is returned.
        """
        # Create a PythonFunctionInfo for the function.
        # fixme: This seems a little heavy weight to just get the
        #        doc-string, but it is the shortest path between here
        #        and there...
        # fixme: We should likely do some error handling here...
        func = PythonFunctionInfo(module=function_info.module,
                                  name=function_info.name)

        if func.doc_string is "":
            short_description = "No information about this function."
        else:
            # Use the first line as the "short" function description.
            short_description = func.doc_string.splitlines()[0]

        return short_description
Ejemplo n.º 7
0
                                label_bg_color=WindowColor,
                                cell_bg_color='white',
                            ),
                            show_label=False,
                            resizable=True,
                        ),
                    ),
                ),
                label="Context Info",
            ),
        ),

        #            width=720, # about 80 columns wide on code view.
        #            height=700,
        resizable=True,
        buttons=menu.OKCancelButtons,
        close_result=False,
    )

    return view


if __name__ == "__main__":
    from python_function_info import PythonFunctionInfo
    from function_call import FunctionCall
    func = PythonFunctionInfo(
        module='cp.rockphysics.converge.fluids.brine_properties',
        name='brine_properties')
    func_call = FunctionCall.from_callable_object(func)
    func_call.configure_traits(view=create_view())