Ian Ward <ian <at> excess.org> writes: > > > > Also, is there a simple way to have attributes "inherit" from their parents or > > vice versa? i.e. in the above example, instead of making the row standout is > > there a way to make the entire row bold without remapping every attribute? > > Not at the moment, but if you can think of what a good API would look > like I'd be interested. Problems include supporting mono/16/88/256 > colour modes equally well, and the fact that some combinations don't > work very well on some terminals.
I've noticed that there's no way to remap attributes except explicitly in a dictionary. Arbitrary remapping with any mapping type would be possible with a couple tweaks to AttrMap and CompositeCanvas.fill_attr_apply, but this has a few problems: AttrMap.get_(attr|focus)_map has no obvious way to return a clone (since the mapping type may not be a plain dict), and CompositeCanvas.fill_attr_apply has no obvious way to compose attribute mappings because the mapping type might not have an update method. Also, subclassing dict or writing a mapping type from scratch could get ugly for the user. Allowing a function to map attributes might be simpler. CompositeCanvas.fill_attr_apply could accept a callable which takes the attribute and returns the new one. For backwards compatibility, this could be mapping.__getitem__ when the mapping is a dict. cview[4] could be a list of these functions, and fill_attr_apply could just append the mapping function. Alternatively, cview[4] could be a single callable and adding another mapping would just be cview[4] = lambda attr: mapping(cview[4](attr)). AttrMap would have to start accepting functions or another class would be needed. As far as I can tell the only other thing that would need to change is how the attribute mapping is handled in the content methods of the Canvas classes, unless I'm missing something. It's not a complete solution, but I think being able to remap attributes programmatically is a step in the right direction. Does this sound like a good/interesting idea to you? I'd be happy to send a patch if it's anywhere near as simple as it looks. Thanks -- Jacob _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
