':returns: a deep copy of the element and its children. Property values are shallow copies.
:rtype: :class:`UIElement`'

def clone(self, set_ui=None, set_context=None):

    o = self.__class__.__new__(self.__class__)
    o._prepare()
    (o.ui, o.typeid, o.context) = ((set_ui or self.ui), self.typeid, (set_context or self.context))
    o.events = self.events.copy()
    o.event_args = self.event_args.copy()
    o.properties = self.properties.copy()
    o.properties_dirty = self.properties_dirty.copy()
    o.children = []
    for c in self.children:
        o.append(c.clone(set_ui=set_ui, set_context=set_context))
    o.post_clone()
    return o
