Example #1
0
 def getModuleClassByName(self,package,moduleName,namespace=""):
     """getModuleClassByName(package: Str, moduleName: Str) -> Class
     Returns the actual python class of a module; this is done by accessing
     the registry to get the descriptor, and then getting the 'module'
     attribute of the descriptor, which returns the class of that module.
     Notice that it returns a *CLASS*, and not an instance of that class"""
     return registry.get_descriptor_by_name(package,moduleName,namespace).module
Example #2
0
 def inspect_spreadsheet_cells(self, pipeline):
     """ inspect_spreadsheet_cells(pipeline: Pipeline) -> None
     Inspect the pipeline to see how many cells is needed
     
     """        
     self.spreadsheet_cells = []
     if not pipeline: return
     # Sometimes we run without the spreadsheet!
     if registry.has_module('edu.utah.sci.vistrails.spreadsheet', 'SpreadsheetCell'):
         # First pass to check cells types
         cellType = registry.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet',
                                                    'SpreadsheetCell').module
         for mId, module in pipeline.modules.iteritems():
             desc = registry.get_descriptor_by_name(module.package, module.name, module.namespace)
             if issubclass(desc.module, cellType):
                 self.spreadsheet_cells.append(mId)
Example #3
0
 def getModuleClassByName(self, package, moduleName, namespace=""):
     """getModuleClassByName(package: Str, moduleName: Str) -> Class
     Returns the actual python class of a module; this is done by accessing
     the registry to get the descriptor, and then getting the 'module'
     attribute of the descriptor, which returns the class of that module.
     Notice that it returns a *CLASS*, and not an instance of that class"""
     return registry.get_descriptor_by_name(package, moduleName, namespace).module
Example #4
0
 def wrapperModule(classname, instance):
     """ wrapperModule(classname: str, instance: vtk class) -> Module
     Create a wrapper module in VisTrails with a vtk instance
     
     """
     result = registry.get_descriptor_by_name('edu.utah.sci.vistrails.vtk',
                                              classname).module()
     result.vtkInstance = instance
     return result
 def view_documentation(self):
     descriptor = registry.get_descriptor_by_name(self.module.package,
                                                  self.module.name,
                                                  self.module.namespace)
     widget = QPortDocumentation(descriptor,
                                 PortEndPoint.Destination,
                                 self.port.name)
     widget.setAttribute(QtCore.Qt.WA_DeleteOnClose)
     widget.exec_()
Example #6
0
 def wrapperModule(classname, instance):
     """ wrapperModule(classname: str, instance: vtk class) -> Module
     Create a wrapper module in VisTrails with a vtk instance
     
     """
     result = registry.get_descriptor_by_name(
         'edu.utah.sci.vistrails.vtksnl',
         classname).module()
     result.vtkInstance = instance
     return result
Example #7
0
 def testSummonModule(self):
     """Check that summon creates a correct module"""
     
     x = Module()
     x.name = "String"
     x.package = 'edu.utah.sci.vistrails.basic'
     try:
         c = x.summon()
         m = registry.get_descriptor_by_name('edu.utah.sci.vistrails.basic',
                                             'String').module
         assert type(c) == m
     except NoSummon:
         msg = "Expected to get a String object, got a NoSummon exception"
         self.fail(msg)
 def make_registry(self):
     reg_module = \
         registry.get_descriptor_by_name('edu.utah.sci.vistrails.basic', 
                                         self.name).module
     self._registry = ModuleRegistry()
     self._registry.add_hierarchy(registry, self)
     for module in self.pipeline.module_list:
         if module.name == 'OutputPort':
             port = self.make_port_from_module(module, 'source')
             self._registry.add_port(reg_module, PortEndPoint.Source, port)
         elif module.name == 'InputPort':
             port = self.make_port_from_module(module, 'destination')
             self._registry.add_port(reg_module, PortEndPoint.Destination, 
                                     port)
 def make_port_from_module(module, port_type):
     for function in module.functions:
         if function.name == 'name':
             port_name = function.params[0].strValue
         if function.name == 'spec':
             port_spec = function.params[0].strValue
     port = Port(id=-1,
                 name=port_name,
                 type=port_type)
     portSpecs = port_spec[1:-1].split(',')
     signature = []
     for s in portSpecs:
         spec = s.split(':', 2)
         signature.append(registry.get_descriptor_by_name(*spec).module)
     port.spec = core.modules.module_registry.PortSpec(signature)
     return port
Example #10
0
    def add_port_to_registry(self, port_spec):
        module = \
            registry.get_descriptor_by_name(self.package, self.name, self.namespace).module
        if self.registry is None:
            self.registry = ModuleRegistry()
            self.registry.add_hierarchy(registry, self)

        if port_spec.type == 'input':
            endpoint = PortEndPoint.Destination
        else:
            endpoint = PortEndPoint.Source
        portSpecs = port_spec.spec[1:-1].split(',')
        signature = [registry.get_descriptor_from_name_only(spec).module
                     for spec in portSpecs]
        port = Port()
        port.name = port_spec.name
        port.spec = core.modules.module_registry.PortSpec(signature)
        self.registry.add_port(module, endpoint, port)        
    def updateModule(self, module):
        """ updateModule(module: Module) -> None        
        Setup this tree widget to show functions of module
        
        """
        self.clear()

        if module:
            try:
                descriptor = registry.get_descriptor_by_name(module.package,
                                                             module.name,
                                                             module.namespace)
            except registry.MissingModulePackage, e:
                # FIXME handle this the same way as
                # vistrail_controller:change_selected_version
                raise
            moduleHierarchy = registry.get_module_hierarchy(descriptor)
            for baseModule in moduleHierarchy:
                baseName = registry.get_descriptor(baseModule).name
                base_package = registry.get_descriptor(baseModule).identifier
                # Create the base widget item
                baseItem = QMethodTreeWidgetItem(None,
                                                 None,
                                                 None,
                                                 self,
                                                 (QtCore.QStringList()
                                                  <<  baseName
                                                  << ''))
                methods = registry.method_ports(baseModule)
                # Also check the local registry
                if module.registry and module.registry.has_module(base_package,
                                                                  baseName):
                    methods += module.registry.method_ports(baseModule)
                for method in methods:
                    sig = method.spec.create_sigstring(short=True)
                    QMethodTreeWidgetItem(module,
                                          method,
                                          method.spec,
                                          baseItem,
                                          (QtCore.QStringList()
                                           << method.name
                                           << sig))
            self.expandAll()
            self.resizeColumnToContents(0)
Example #12
0
    def delete_port_from_registry(self, id):
        if not id in self.port_specs:
            raise VistrailsInternalError("id missing in port_specs")
        portSpec = self.port_specs[id]
        portSpecs = portSpec.spec[1:-1].split(',')
        signature = [registry.get_descriptor_from_name_only(spec).module
                     for spec in portSpecs]
        port = Port(signature)
        port.name = portSpec.name
        port.spec = core.modules.module_registry.PortSpec(signature)

        module = \
            registry.get_descriptor_by_name(self.package, self.name, self.namespace).module
        assert isinstance(self.registry, ModuleRegistry)

        if portSpec.type == 'input':
            self.registry.delete_input_port(module, port.name)
        else:
            self.registry.delete_output_port(module, port.name)
Example #13
0
class vtkBaseModule(Module):
    """
    vtkBaseModule is the base class for all VTK modules in VisTrails, it acts
    as a wrapper to direct all input/output ports to appropriate VTK function
    calls
    
    """
    def __init__(self):
        """ vtkBaseModule() -> vtkBaseModule
        Instantiate an emptt VTK Module with real VTK instance
        
        """
        Module.__init__(self)
        self.vtkInstance = None

    def is_cacheable(self):
        # VTK objects are by default cacheable only if they're subclasses
        # of vtkAlgorithm
        return (issubclass(self.vtkClass, vtk.vtkAlgorithm)
                and (not issubclass(self.vtkClass, vtk.vtkAbstractMapper)))

    def call_input_function(self, function, params):
        """self.call_input_function(function, params) -> None
        Calls the input function on the vtkInstance, or a special
        input function if one exists in the class."""
        if hasattr(self, '_special_input_function_' + function):
            attr = getattr(self, '_special_input_function_' + function)
        else:
            try:
                attr = getattr(self.vtkInstance, function)
            except AttributeError:
                # Compensates for overload by exploiting the fact that
                # no VTK method has underscores.
                f = function.find('_')
                if f != -1:
                    function = function[:f]
                attr = getattr(self.vtkInstance, function)
        attr(*params)
        # print "Called ",attr,function,params

    @classmethod
    def _provide_doc(cls, port_name):
        f = port_name.find('_')
        if f != -1:
            name = port_name[:f]
        else:
            name = port_name
        return getattr(cls.vtkClass, name).__doc__

    @classmethod
    def provide_input_port_documentation(cls, port_name):
        return cls._provide_doc(port_name)

    @classmethod
    def provide_output_port_documentation(cls, port_name):
        return cls._provide_doc(port_name)

    def compute(self):
        """ compute() -> None
        Actually perform real VTK task by directing all input/output ports
        to VTK function calls
        
        """
        def call_it(function, p):
            # Translate between VisTrails objects and VTK objects
            if p is None:
                # None indicates a call with no parameters
                params = []
            elif type(p) == tuple:
                # A tuple indicates a call with many parameters
                params = list(p)
            else:
                # Otherwise, it's a single parameter
                params = [p]

            # Unwraps VTK objects
            for i in xrange(len(params)):
                if hasattr(params[i], 'vtkInstance'):
                    params[i] = params[i].vtkInstance
            try:
                self.call_input_function(function, params)
            except Exception, e:
                msg = 'VTK Exception: '
                raise ModuleError(self, msg + str(type(e)) + ': ' + str(e))

        # Always re-create vtkInstance module, no caching here
        if self.vtkInstance:
            del self.vtkInstance
        self.vtkInstance = self.vtkClass()

        # We need to call method ports before anything else, and in
        # the right order.

        # FIXME: This does not belong here, it belongs in the main class
        # No time for that now
        methods = self.is_method.values()
        methods.sort()
        for value in methods:
            (_, port) = value
            conn = self.is_method.inverse[value]
            p = conn()
            call_it(port, p)

        # Make sure all input ports are called correctly
        for (function, connector_list) in self.inputPorts.iteritems():
            paramList = self.forceGetInputListFromPort(function)
            if function[:18] == 'SetInputConnection':
                paramList = zip([int(function[18:])] * len(paramList),
                                paramList)
                function = 'SetInputConnection'
            if function == 'AddInputConnection':
                desc = registry.get_descriptor_by_name(
                    'edu.utah.sci.vistrails.vtk', 'vtkAlgorithmOutput')
                for i in xrange(len(paramList)):
                    if type(paramList[i]) == desc.module:
                        paramList[i] = (0, paramList[i])
            for p, connector in izip(paramList, connector_list):
                # Don't call method
                if connector in self.is_method:
                    continue
                call_it(function, p)

        # Call update if appropriate
        if hasattr(self.vtkInstance, 'Update'):

            def ProgressEvent(obj, event):
                self.logging.update_progress(self, obj.GetProgress())

            isAlgorithm = issubclass(self.vtkClass, vtk.vtkAlgorithm)
            if isAlgorithm:
                cbId = self.vtkInstance.AddObserver('ProgressEvent',
                                                    ProgressEvent)
            self.vtkInstance.Update()
            if isAlgorithm:
                self.vtkInstance.RemoveObserver(cbId)

        # Then update the output ports also with appropriate function calls
        for function in self.outputPorts.keys():
            if function[:13] == 'GetOutputPort':
                i = int(function[13:])
                vtkOutput = self.vtkInstance.GetOutputPort(i)
                output = vtkBaseModule.wrapperModule('vtkAlgorithmOutput',
                                                     vtkOutput)
                self.setResult(function, output)
            elif hasattr(self.vtkInstance, function):
                retValues = getattr(self.vtkInstance, function)()
                if issubclass(retValues.__class__, vtk.vtkObject):
                    className = retValues.GetClassName()
                    output = vtkBaseModule.wrapperModule(className, retValues)
                    self.setResult(function, output)
                elif (type(retValues) in [tuple, list]):
                    result = list(retValues)
                    for i in xrange(len(result)):
                        if issubclass(result[i].__class__, vtk.vtkObject):
                            className = result[i].GetClassName()
                            result[i] = vtkBaseModule.wrapperModule(
                                className, result[i])
                    self.setResult(function, type(retValues)(result))
                else:
                    self.setResult(function, retValues)
Example #14
0
 def getModuleClassByModule(self,module):
     """getModuleClassByModule(module: Module) -> Class
     Does the same thing as the above, only it returns the class from a given module
     instead of its name and package"""
     return registry.get_descriptor_by_name(module.package, module.name, module.namespace).module
Example #15
0
 def getModuleClassByModule(self, module):
     """getModuleClassByModule(module: Module) -> Class
     Does the same thing as the above, only it returns the class from a given module
     instead of its name and package"""
     return registry.get_descriptor_by_name(module.package, module.name, module.namespace).module