| 73 | # child class, then that class will be preserved rather than replaced with a new instance |
| 74 | # of the same thing. |
| 75 | def setClasses( self, classes ) : |
| 76 | |
| 77 | # validate arguments and figure out what child parameter names we need |
| 78 | |
| 79 | assert( isinstance( classes, list ) ) |
| 80 | |
| 81 | neededNames = set() |
| 82 | for c in classes : |
| 83 | assert( isinstance( c, tuple ) ) |
| 84 | assert( len( c ) == 3 ) |
| 85 | assert( isinstance( c[0], str ) ) |
| 86 | assert( isinstance( c[1], str ) ) |
| 87 | assert( isinstance( c[2], int ) ) |
| 88 | if c[0] in neededNames : |
| 89 | raise ValueError( "Duplicate parameter name \"%s\"" % c[0] ) |
| 90 | neededNames.add( c[0] ) |
| 91 | |
| 92 | # first remove any existing parameters which we don't need |
| 93 | |
| 94 | for parameterName in self.keys() : |
| 95 | if parameterName not in neededNames : |
| 96 | self.removeClass( parameterName ) |
| 97 | |
| 98 | # and then create any new ones we need and reload and reorder existing |
| 99 | # ones as necessary |
| 100 | |
| 101 | for i in range( 0, len( classes ) ) : |
| 102 | |
| 103 | # modify or add a parameter for this class |
| 104 | |
| 105 | self.setClass( classes[i][0], classes[i][1], classes[i][2] ) |
| 106 | parameter = self[classes[i][0]] |
| 107 | |
| 108 | # make sure the parameter has the right order within the whole |
| 109 | |
| 110 | self.removeParameter( parameter ) |
| 111 | if len( self ) == i : |
| 112 | self.addParameter( parameter ) |
| 113 | else : |
| 114 | keys = self.keys() |
| 115 | self.insertParameter( parameter, self[keys[i]] ) |
| 116 | |
| 117 | ## Returns the class instance that the named parameter represents, |
| 118 | # or if withClassLoaderArgs is True, then returns a tuple of the |