Created
March 4, 2011 20:01
Revisions
-
xlarsx created this gist
Mar 4, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ class Canvas(object): def __init__(self, lock): self.lock = lock def __enter__(self): ContenedorCanvas.estableceObjeto(self) return self def __exit__(self, type, value, tb): ContenedorCanvas.terminaUsarObjeto(self) def obtenTexto(self): return self.lock class Scatter(object): def __init__(self, num): self.canvas = Canvas("Canvas: " + str(num)) class ContenedorCanvas(object): pilaObjetos = [] @staticmethod def estableceObjeto(objeto): if objeto not in ContenedorCanvas.pilaObjetos: ContenedorCanvas.pilaObjetos.append(objeto) @staticmethod def terminaUsarObjeto(objeto): if objeto in ContenedorCanvas.pilaObjetos: ContenedorCanvas.pilaObjetos.remove(objeto) @staticmethod def obtenUltimoElemento(): return ContenedorCanvas.pilaObjetos[-1] if len(ContenedorCanvas.pilaObjetos) > 0 else None class Rectangle(object): def __init__(self): ultimoElemento = ContenedorCanvas.obtenUltimoElemento() if ultimoElemento is not None: print "Dibujando rectangulo en %s" % ultimoElemento.obtenTexto() node = Scatter(1) node2 = Scatter(2) with node.canvas: Rectangle() # Solicitud de dibujar rectangulo en Canvas 1 with node2.canvas: Rectangle() # Solicitud de dibujar rectangulo en Canvas 2