def dump_ui(uri, oc, outfile=None, extend=None, rdn=None, contains=None): subschemasubentry_dn, schema = ldap.schema.urlfetch(uri) schema_reverse = ldap.schema.SubSchema(schema.ldap_entry()) oco = schema.get_obj(ldap.schema.ObjectClass, oc) if oco is None: log.error("unknown objectclass '%s' - please use the --list option to see what's there" % oc) exit(1) # Complete attributes in case of inheritance if oco.kind == 0: r = resolve_inherited_attrs(schema, oco.sup[0]) oco.must = list(set(list(oco.must) + r['must'])) oco.may = list(set(list(oco.may) + r['must'])) # Tabstop and connection collectors ts = [] cs = [] # Build resulting XML dump e = ElementMaker() n = 0 attrs = [] for mua in oco.must: attr = resolve_attribute(schema, mua) syntax = attr['syntax'] if skip(syntax): continue if not 'widget' in TYPE_MAP[syntax]: continue widget = TYPE_MAP[syntax]['widget'] attrs.append( e.item( e.widget( e.property(e.string(mua), name="text"), CLASS("QLabel"), name="%sLabel*" % mua), row=str(n), column="0")) attrs.append(e.item(e.widget(CLASS(widget), name="%sEdit*" % mua), row=str(n), column="1")) ts.append(e.tabstop(mua)) cs.append(e.connection( e.sender("%sEdit" % mua), e.signal("textChanged(QString)"), e.receiver(oc), e.slot("property_%s()" % mua))) n += 1 for mua in oco.may: if mua in oco.must: continue attr = resolve_attribute(schema, mua) syntax = attr['syntax'] if skip(syntax): continue if not 'widget' in TYPE_MAP[syntax]: continue widget = TYPE_MAP[syntax]['widget'] attrs.append( e.item( e.widget( e.property(e.string(mua), name="text"), CLASS("QLabel"), name="%sLabel" % mua), row=str(n), column="0")) attrs.append(e.item(e.widget(CLASS(widget), name="%sEdit" % mua), row=str(n), column="1")) ts.append(e.tabstop(mua)) cs.append(e.connection( e.sender("%sEdit" % mua), e.signal("textChanged(QString)"), e.receiver(oc), e.slot("property_%s()" % mua))) n += 1 res = '<?xml version="1.0" encoding="UTF-8"?>\n' data = e.ui( e("class", oc), e.widget( e.property(e.rect(e.x("0"), e.y("0"), e.width("400"), e.height("300")), name="geometry"), e.property(e.string(oc), name="windowTitle"), e.layout( e.item( e.layout(CLASS("QFormLayout"), *attrs, name="formLayout"), row="0", column="0"), CLASS("QGridLayout"), name="gridLayout"), CLASS("QWidget"), name=oc), e.tabstops(*ts), e.connections(*cs), version="4.0") res += etree.tostring(data, pretty_print=True) return res