def _add_element(self, pid, element):

        # Get the tree item image index and text.
        image_index = self._get_image_index(element)
        text = self._get_text(element)

        # Add the element.
        if pid is None:
            wxid = self.control.AddRoot(text, image_index, image_index)

        else:
            wxid = self.control.AppendItem(pid, text, image_index, image_index)

        # If we are adding the root element but the root is hidden, get its
        # children.
        if pid is None and not self.show_root:
            children = self.content_provider.get_children(element)
            for child in children:
                self._add_element(wxid, child)

        # Does the element have any children?
        has_children = self.content_provider.has_children(element)
        self.control.SetItemHasChildren(wxid, has_children)

        # The item data is a tuple. The first element indicates whether or not
        # we have already populated the item with its children. The second
        # element is the actual item data.
        if pid is None:
            if self.show_root:
                self.control.SetPyData(wxid,  (False, element))

        else:
            self.control.SetPyData(wxid,  (False, element))

        # Make sure that we can find the element's Id later.
        self._element_to_id_map[self._get_key(element)] = wxid

        # If we are adding the root item then automatically expand it.
        if pid is None and self.show_root:
            self.control.Expand(wxid)

        return
Adds 'element' as a child of the element identified by 'pid'.
dataset/ETHPy150Open enthought/pyface/pyface/viewer/tree_viewer.py/TreeViewer._add_element