Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

kcrisman's second approach, basically fixing the zorder after the fact, makes the most sense to me. Simply add as you like and then set the zorders from the order in the G list before printing. (I don't think G does any reshuffling, although I could be wrong about that.)

Whatever you do, don't do this.

# monkey madness
def zadd_wrap(f):
    def zadd(*args):
        zorders = list(g.options().get('zorder') for g in args[0])
        max_zorder = max(zorders) if zorders else 0
        for i, p in enumerate(args[1],1):
            p.set_zorder(max_zorder+i)
        return f(*args)
    return zadd

# it's asking -- no, begging! -- for all kinds of disaster, and for zero benefit
Graphics.__add__ = zadd_wrap(Graphics.__add__)

# seriously, I mean it
G = Graphics()
G += plot(sin) + circle((3,2),2)+ arrow((5,6),(3,2)) 
G += point((3,4))
print list(g.options()['zorder'] for g in G)

# You are likely to be eaten by a grue.