def _make_panel4Struct(model=None, typ=None, name_leaf=None, **kargs): assert typ is not None or model is not None if not typ: typ = model.__class__ name = name_leaf if not name: try: name = typ.name except AttributeError: name = None if not isinstance(name, str): name = None title = name or typ.__name__ panel = Panel() panel.header["title"] = title panel4Struct(panel=panel, model=model, typ=typ, **kargs) panel.generated = True return panel
def panel4Struct( panel, model, typ, name_leaf="", fullname="", # model's pfx/name in view readonly=False, is_root=True, make_panel=make_panel4Struct, fields2ignore=None, extract_one_fld_panel=False, translator=None, attr_order=None, **kargs_ignore ): pfx = fullname and fullname + "." or "" mtyp = typ attr_order = attr_order or list(mtyp._order_Statics(items=False)) for name in attr_order: if fields2ignore and name in fields2ignore: continue typ = mtyp.StaticType[name] try: typ = typ.StaticType_alt fullname = pfx + typ.name except AttributeError: fullname = pfx + name if getattr(typ, "meta", None): continue if getattr(typ, "UI_hide", None): continue my_readonly = readonly optional = getattr(typ, "optional", None) if optional: opt_name = optional.name on = get_attrib(model, opt_name, None) # True - on by default item_name = not on and HIDE_OPTIONAL_OFF and name or "" # item's name at least opt_fullname = pfx + opt_name panel_opt = Panel("[_ %(opt_fullname)s] %(item_name)s" % locals(), {opt_fullname: dict(label="", width=30)}) panel += panel_opt my_readonly = my_readonly or not on if not on and HIDE_OPTIONAL_OFF: # without this, optional is visible but readonly continue m = None if getattr(typ, "non_atomary", None): m = getattr(model, name, None) p = _panel4any( model=m, typ=typ, fullname=fullname, readonly=my_readonly, name_leaf=name, make_panel=make_panel, fields2ignore=fields2ignore, translator=translator, ) if translator: if isinstance(p, tuple): d = p[1] d = d[d.keys()[0]] l = d.get("label") if l: d["label"] = translator(l) elif isinstance(p, Panel): p.header["title"] = translator(p.header["title"]) if not optional: panel += p else: if typ.non_atomary: panel_opt *= p else: # plain atomary txt, field_map = p panel_opt.field_map.update(field_map) panel_opt.parse(txt, start_new_row=False)