def new_layer(spj, element):
    layer = Layer(**element.attrib)

    # TODO: test type and _then_ assign the data    
    for eLine in element.findall('Line'):        
        layer.lines.append(new_line(spj, eLine))        

    # TODO:
    ### group properties
    ###group_markers = element.findall('GroupMarkers')
    
    
    for eAxis in element.findall('Axis'):
        key = eAxis.attrib.pop('key', 'x')
        a = Axis(**eAxis.attrib)
        if key == 'x':
            layer.xaxis = a
        elif key == 'y':
            layer.yaxis = a

    eLegend = element.find('Legend')
    if eLegend is not None:
        layer.legend = new_legend(spj, eLegend)
    
    return layer
def new_layer(spj, element):
        
    # create new layer
    layer = Layer(**element.attrib)

#     # group properties
#     group_properties = {}
#     eGroups = element.find('Groups')
#     if eGroups is not None:
#         # We iterate over all group properties and look for elements
#         # with tags that match the group property's classname, e.g.
#         # <GroupLineMarker>...</GroupLineMarker> for the Property
#         # Layer.marker.
#         keys = ['group_linestyle', 'group_linewidth', 'group_linecolor', 'group_linemarker']
#         for key in keys:
#             classname = layer.get_value(key).__class__.__name__
#             groupclass = layer.get_value(key).__class__
#             eGroup = eGroups.find(classname)
#             if eGroup is not None:
#                 eGroup.attrib['type'] = int(eGroup.attrib['type'])
#                 group_properties[key] = groupclass(**eGroup.attrib)
#                 print "CYCLE LIST", group_properties[key].cycle_list

#     layer.set(**group_properties)

    # TODO: test type and _then_ assign the data    
    for eLine in element.findall('Line'):        
        layer.lines.append(new_line(spj, eLine))        
    
    # axes
    for eAxis in element.findall('Axis'):
        key = eAxis.attrib.pop('key', 'x')
        a = Axis(**eAxis.attrib)
        if key == 'x':
            layer.xaxis = a
        elif key == 'y':
            layer.yaxis = a

    # legend
    eLegend = element.find('Legend')
    if eLegend is not None:
        layer.legend = new_legend(spj, eLegend)
    
    return layer