Exemple #1
0
 def test_all_instantiable(self):
     """Test if all the TVTK classes are instantiable."""
     # This is a comprehensive test that instantiates every single
     # non-abstract tvtk class.  This takes a while.
     ok = True
     # Turn off VTK warnings.
     vtk.vtkObject.GlobalWarningDisplayOff()
     for name in dir(vtk):
         klass = getattr(vtk, name)
         if hasattr(klass, '__bases__') \
                 and not issubclass(klass, object):
             try:
                 obj = klass()
             except TypeError:
                 # These classes are abstract and can't/shouldn't
                 # be instantiated.
                 pass
             else:
                 t_name = get_tvtk_name(name)
                 skip = ['ObjectBase']
                 if t_name not in skip:
                     k = getattr(tvtk, t_name)
                     try:
                         obj = k()
                     except TraitError, msg:
                         print "class:", t_name, msg
                         ok = False
Exemple #2
0
    def test_tvtk_name(self):
        """Test VTK to TVTK class name conversion."""
        v_name = ['vtkFooBar', 'vtkXMLDataReader',
                  'vtk3DSReader', 'vtk2000Bug']
        t_name = ['FooBar', 'XMLDataReader',
                  'ThreeDSReader', 'Two000Bug']
        for i, vn in enumerate(v_name):
            tn = get_tvtk_name(vn)
            self.assertEqual(tn, t_name[i])

        num = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five',
               'Six', 'Seven', 'Eight', 'Nine']
        for i in range(10):
            vn = 'vtk%dA'%i
            tn = get_tvtk_name(vn)
            self.assertEqual(tn, '%sA'%num[i])
Exemple #3
0
 def test_all_instantiable(self):
     """Test if all the TVTK classes are instantiable."""
     # This is a comprehensive test that instantiates every single
     # non-abstract tvtk class.  This takes a while.
     ok = True
     # Turn off VTK warnings.
     vtk.vtkObject.GlobalWarningDisplayOff()
     for name in dir(vtk):
         klass = getattr(vtk, name)
         if hasattr(klass, '__bases__') \
                 and not issubclass(klass, object):
             try:
                 obj = klass()
             except TypeError:
                 # These classes are abstract and can't/shouldn't
                 # be instantiated.
                 pass
             else:
                 t_name = get_tvtk_name(name)
                 skip = ['ObjectBase']
                 if t_name not in skip:
                     k = getattr(tvtk, t_name)
                     try:
                         obj = k()
                     except TraitError, msg:
                         print "class:", t_name, msg
                         ok = False
Exemple #4
0
    def test_tvtk_name(self):
        """Test VTK to TVTK class name conversion."""
        v_name = [
            'vtkFooBar', 'vtkXMLDataReader', 'vtk3DSReader', 'vtk2000Bug'
        ]
        t_name = ['FooBar', 'XMLDataReader', 'ThreeDSReader', 'Two000Bug']
        for i, vn in enumerate(v_name):
            tn = get_tvtk_name(vn)
            self.assertEqual(tn, t_name[i])

        num = [
            'Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven',
            'Eight', 'Nine'
        ]
        for i in range(10):
            vn = 'vtk%dA' % i
            tn = get_tvtk_name(vn)
            self.assertEqual(tn, '%sA' % num[i])
Exemple #5
0
def get_tvtk_class_names():
    """Returns 4 lists:

     1. A list of all the TVTK class names that are not abstract.

     2. A list of the TVTK sources (have only outputs and no inputs)

     3. A list of the TVTK filters (both inputs and outputs)

     4. A list of the TVTK sinks (only inputs and no outputs)

    """
    # Shut of VTK warnings for the time being.
    o = vtk.vtkObject
    w = o.GetGlobalWarningDisplay()
    o.SetGlobalWarningDisplay(0) # Turn it off.

    all = []
    src = []
    filter = []
    sink = []
    for name in dir(vtk):
        if name.startswith('vtk'):
            klass = getattr(vtk, name)
            try:
                c = klass()
            except TypeError:
                continue

            tvtk_name = get_tvtk_name(name)
            all.append(tvtk_name)
            has_input = has_output = False
            if hasattr(klass, 'GetNumberOfInputPorts'):
                if c.GetNumberOfInputPorts() > 0:
                    has_input = True
            if hasattr(klass, 'GetNumberOfOutputPorts'):
                if c.GetNumberOfOutputPorts() > 0:
                    has_output = True

            if has_input:
                if has_output:
                    filter.append(tvtk_name)
                else:
                    sink.append(tvtk_name)
            elif has_output:
                src.append(tvtk_name)

    o.SetGlobalWarningDisplay(w)

    result = (all, src, filter, sink)
    for x in result:
        x.sort()

    return result
Exemple #6
0
    def search(self, word):
        """ Search for word in class documentation and return matching
        classes.  This is also case insensitive.  The searching
        supports the 'and' and 'or' keywords that allow for fairly
        complex searches.  A space between words assumes that the two
        words appear one after the other.

        Parameters
        ----------
            word -- name to search for.
        """
        assert type(word) in types.StringTypes, \
               "Sorry, passed argument, %s is not a string."%word
        if len(word.strip()) == 0:
            return []

        lword = word.lower().strip()
        tmp_list = lword.split()
        wlist = []
        prev = ""
        for w in tmp_list:
            z = w.strip()
            if z in ('and', 'or'):
                if prev and prev not in ('and', 'or'):
                    wlist.append(prev)
                    wlist.append(z)
                    prev = z
            else:
                if prev and prev not in ('and', 'or'):
                    prev = prev + ' ' + z
                else:
                    prev = z

        if prev in ('and', 'or'):
            del wlist[-1]
        elif prev:
            wlist.append(prev)

        ret = []
        i = 0
        vtk_classes = self.vtk_classes
        vtk_c_doc = self.vtk_c_doc
        N = len(vtk_classes)
        while i < N:
            stored_test = 0
            do_test = ''
            for w in wlist:
                if w == 'and':
                    do_test = 'and'
                elif w == 'or':
                    do_test = 'or'
                else:
                    test = (vtk_c_doc[i].find(w) > -1)
                    if do_test == 'and':
                        stored_test = stored_test and test
                    elif do_test == 'or':
                        stored_test = stored_test or test
                    elif do_test == '':              
                        stored_test = test
            if stored_test:
                ret.append(vtk_classes[i])
            i = i + 1

        return [get_tvtk_name(x) for x in ret]