Ejemplo n.º 1
0
 def convert(_module):
     if _module.__class__ == Module:
         return
     _module.__class__ = Module
     for _port_spec in _module.db_portSpecs:
         PortSpec.convert(_port_spec)
     if _module.db_location:
         Location.convert(_module.db_location)
     for _function in _module.db_functions:
         ModuleFunction.convert(_function)
     for _annotation in _module.db_get_annotations():
         Annotation.convert(_annotation)
     _module.set_defaults()
    def convert(_module):
        if _module.__class__ == Module:
            return
	_module.__class__ = Module
        for _port_spec in _module.db_portSpecs:
            PortSpec.convert(_port_spec)
        if _module.db_location:
            Location.convert(_module.db_location)
	for _function in _module.db_functions:
	    ModuleFunction.convert(_function)
        for _annotation in _module.db_get_annotations():
            Annotation.convert(_annotation)
        _module.set_defaults()
Ejemplo n.º 3
0
    def convert(_module):
	_module.__class__ = Module
	_module.registry = None
        for _port_spec in _module.db_portSpecs:
            PortSpec.convert(_port_spec)
            _module.add_port_to_registry(_port_spec)
        if _module.db_location:
            Location.convert(_module.db_location)
	for _function in _module.db_functions:
	    ModuleFunction.convert(_function)
        for _annotation in _module.db_get_annotations():
            Annotation.convert(_annotation)

        _module.portVisible = set()
Ejemplo n.º 4
0
    def convert(_desc):
        if _desc.__class__ == ModuleDescriptor:
            return
        _desc.__class__ = ModuleDescriptor
        
        for port_spec in _desc.db_portSpecs:
            PortSpec.convert(port_spec)

        # do more init stuff
        _desc.children = []
        _desc.module = None
        _desc._base_descriptor = None
        _desc._port_count = 0
        _desc.set_defaults()
Ejemplo n.º 5
0
    def get_spec(self, port_type):
        """ get_spec(port_type) -> PortSpec

        Returns a PortSpec corresponding to the function parameter
        types set.  This is useful to make module functions look more
        like they are 'regular' modules and connections (which is what
        they get compiled down to in execution).

        port_type is either 'input' or 'output', as strings, which
        simply gets set on the spec being returned.
        """
        assert port_type == 'input' or port_type == 'output'
        result = PortSpec(signature=self.sigstring)
        result.type = port_type
        return result
    def get_spec(self, port_type):
        """ get_spec(port_type) -> PortSpec

        Returns a PortSpec corresponding to the function parameter
        types set.  This is useful to make module functions look more
        like they are 'regular' modules and connections (which is what
        they get compiled down to in execution).

        port_type is either 'input' or 'output', as strings, which
        simply gets set on the spec being returned.
        """
        assert port_type == "input" or port_type == "output"
        result = PortSpec(signature=self.sigstring)
        result.type = port_type
        return result
Ejemplo n.º 7
0
 def new_port_spec(self, name, type, signature=None, sigstring=None,
                   optional=False, sort_key=-1):
     # DEPRECATED: create using ModuleRegistry
     if signature is None and sigstring is None:
         raise VistrailsInternalError("new_port_spec: signature and "
                                      "sigstring cannot both be None")
     if sigstring is not None:
         return PortSpec(id=-1,
                         name=name,
                         type=type,
                         sigstring=sigstring,
                         optional=optional,
                         sort_key=sort_key)
     return PortSpec(id=-1,
                     name=name,
                     type=type,
                     signature=signature,
                     optional=optional,
                     sort_key=sort_key)
Ejemplo n.º 8
0
    def compare(self, port_spec, v_module, port):
        """
        Function used to compare two port specs.
        """
        port_spec1 = port_spec

        reg = get_module_registry()

        v_module = self.createSignature(v_module)
        port_spec2 = PortSpec(**{'signature': v_module})
        matched = reg.are_specs_matched(port_spec1, port_spec2)
                
        return matched
Ejemplo n.º 9
0
    def _update_func(self, port_spec, *args, **kwargs):
        # print 'running _update_func', port_spec.name
        # print args

        if port_spec.type != 'input':
            if self._module.has_port_spec(port_spec.name, 'input'):
                port_spec = \
                    self._module.get_port_spec(port_spec.name, 'input')
            else:
                raise Exception("cannot update an output port spec")

        # FIXME deal with kwargs
        num_ports = 0
        num_params = 0
        for value in args:
            # print 'processing', type(value), value
            if isinstance(value, vistrails_port):
                # make connection to specified output port
                # print 'updating port'
                num_ports += 1
            elif isinstance(value, vistrails_module):
                # make connection to 'self' output port of value
                # print 'updating module'
                num_ports += 1
            else:
                # print 'update literal', type(value), value
                num_params += 1
        if num_ports > 1 or (num_ports == 1 and num_params > 0):
            reg = core.modules.module_registry.get_module_registry()
            tuple_desc = \
                reg.get_descriptor_by_name('edu.utah.sci.vistrails.basic',
                                           'Tuple', '')

            d = {
                '_module_desc': tuple_desc,
                '_package': self._package,
            }
            tuple = type('module', (vistrails_module, ), d)()

            output_port_spec = PortSpec(id=-1,
                                        name='value',
                                        type='output',
                                        sigstring=port_spec.sigstring)
            api.add_port_spec(tuple._module.id, output_port_spec)
            self._update_func(port_spec, *[tuple.value()])
            assert len(port_spec.descriptors()) == len(args)
            for i, descriptor in enumerate(port_spec.descriptors()):
                arg_name = 'arg%d' % i
                sigstring = "(" + descriptor.sigstring + ")"
                tuple_port_spec = PortSpec(id=-1,
                                           name=arg_name,
                                           type='input',
                                           sigstring=sigstring)
                api.add_port_spec(tuple._module.id, tuple_port_spec)
                tuple._process_attr_value(arg_name, args[i])

            # create tuple object
            pass
        elif num_ports == 1:
            other = args[0]
            if isinstance(other, vistrails_port):
                if other._port_spec.type != 'output':
                    other_module = other._vistrails_module._module
                    if other_module.has_port_spec(port_spec.name, 'output'):
                        other_port_spec = \
                            other_module.get_port_spec(port_spec.name,
                                                        'output')
                    else:
                        raise Exception("cannot update an input " "port spec")
                else:
                    other_port_spec = other._port_spec

                api.add_connection(other._vistrails_module._module.id,
                                   other_port_spec, self._module.id, port_spec)
            elif isinstance(other, vistrails_module):
                other_port_spec = \
                    other._module.get_port_spec('self', 'output')
                api.add_connection(other._module.id, other_port_spec,
                                   self._module.id, port_spec)
        else:
            api.change_parameter(self._module.id, port_spec.name,
                                 [str(x) for x in args])
Ejemplo n.º 10
0
    def update_module(self, module):
        """ update_module(module: Module) -> None        
        Setup this tree widget to show functions of module
        
        """
        # this is strange but if you try to clear the widget when the focus is 
        # in one of the items (after setting a parameter for example), 
        # VisTrails crashes on a Mac (Emanuele) This is probably a Qt bug
        w =  QtGui.QApplication.focusWidget()
        if self.isAncestorOf(w):
            w.clearFocus()
        self.clear()
        self.module = module
        self.port_spec_items = {}
        self.function_map = {}
        if module and module.is_valid:
            reg = get_module_registry()
            descriptor = module.module_descriptor
            if self.port_type == 'input':
                port_specs = module.destinationPorts()
                connected_ports = module.connected_input_ports
                visible_ports = module.visible_input_ports
            elif self.port_type == 'output':
                port_specs = module.sourcePorts()
                connected_ports = module.connected_output_ports
                visible_ports = module.visible_output_ports
            else:
                raise Exception("Unknown port type: '%s'" % self.port_type)
            
            for port_spec in sorted(port_specs, key=lambda x: x.name):
                connected = port_spec.name in connected_ports and \
                    connected_ports[port_spec.name] > 0
                item = PortItem(port_spec, 
                                connected,
                                port_spec.optional,
                                port_spec.name in visible_ports)
                self.addTopLevelItem(item)
                self.port_spec_items[port_spec.name] = (port_spec, item)

            if self.port_type == 'input':
                for function in module.functions:
                    if not function.is_valid:
                        debug.critical("function '%s' not valid", function.name)
                        continue
                    port_spec, item = self.port_spec_items[function.name]
                    subitem = self.entry_klass(port_spec, function)
                    self.function_map[function.real_id] = subitem
                    item.addChild(subitem)
                    subitem.setFirstColumnSpanned(True)
                    self.setItemWidget(subitem, 0, subitem.get_widget())
                    item.setExpanded(True)
                
                    # self.setItemWidget(item, 0, item.get_visible())
                    # self.setItemWidget(item, 1, item.get_connected())

                    # i = QTreeWidgetItem(self)
                    # self.addTopLevelItem(i)
                    # i.setText(2, port_spec.name)
                    # visible_checkbox = QtGui.QCheckBox()
                    # self.setItemWidget(i, 0, visible_checkbox)
                    # connceted_checkbox = QtGui.QCheckBox()
                    # connected_checkbox.setEnabled(False)
                    # self.setItemWidget(i, 1, connected_checkbox)
                

            # base_items = {}
            # # Create the base widget item for each descriptor
            # for descriptor in moduleHierarchy:
            #     baseName = descriptor.name
            #     base_package = descriptor.identifier
            #     baseItem = QMethodTreeWidgetItem(None,
            #                                      None,
            #                                      self,
            #                                      (QtCore.QStringList()
            #                                       <<  baseName
            #                                       << ''))
            #     base_items[descriptor] = baseItem

            # method_specs = {}
            # # do this in reverse to ensure proper overloading
            # # !!! NOTE: we have to use ***all*** input ports !!!
            # # because a subclass can overload a port with a 
            # # type that isn't a method
            # for descriptor in reversed(moduleHierarchy):
            #     method_specs.update((name, (descriptor, spec))
            #                         for name, spec in \
            #                             registry.module_ports('input', 
            #                                                   descriptor))

            # # add local registry last so that it takes precedence
            # method_specs.update((spec.name, (descriptor, spec))
            #                     for spec in module.port_spec_list
            #                     if spec.type == 'input')

            # for _, (desc, method_spec) in sorted(method_specs.iteritems()):
            #     if registry.is_method(method_spec):
            #         baseItem = base_items[desc]
            #         sig = method_spec.short_sigstring
            #         QMethodTreeWidgetItem(module,
            #                               method_spec,
            #                               baseItem,
            #                               (QtCore.QStringList()
            #                                << method_spec.name
            #                                << sig))

            # self.expandAll()
            # self.resizeColumnToContents(2) 
        # show invalid module attributes
        if module and not module.is_valid and self.port_type == 'input':
            for function in module.functions:
                if function.name in self.port_spec_items:
                    port_spec, item = self.port_spec_items[function.name]
                else:
                    sigstring = "(" + ",".join(
                        ['edu.utah.sci.vistrails.basic:String'
                         for i in xrange(len(function.parameters))]) + ")"
                    port_spec = PortSpec(name=function.name, type='input',
                                         sigstring=sigstring)
                    item = PortItem(port_spec,  False, False, False)
                self.addTopLevelItem(item)
                self.port_spec_items[port_spec.name] = (port_spec, item)
                subitem = self.entry_klass(port_spec, function)
                self.function_map[function.real_id] = subitem
                item.addChild(subitem)
                subitem.setFirstColumnSpanned(True)
                self.setItemWidget(subitem, 0, subitem.get_widget())
                item.setExpanded(True)