'Set a parent for this item, base method for tree construction
@param p: the parent
@param i: the list index where to insert the item'

def set_parent(self, p=None, i=None):

    if (p is None):
        p = self.parent
    if (p is None):
        return
    parent = self.parent
    if ((parent is not None) and (parent != p)):
        while (self in parent.components):
            parent.components.remove(self)
    if (i is not None):
        p.component.insert(i, self)
    else:
        p.components.append(self)
    self.parent = p
    return
