Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ejemplo de gestión de eventos con decoradores en Python
class MiBoton(object):
def __init__(self):
self.delegadoClic = None
self.on_clic = self.obtenDecorador()
def obtenDecorador(self):
def decorador(f):
self.delegadoClic = f
def funcionInterna(*arg1, **arg2):
f(*arg1, **arg2)
return funcionInterna
return decorador
def clic(self):
if self.delegadoClic is not None:
self.delegadoClic() #Enviar eventos complementarios a funcion
miBoton = MiBoton()
@miBoton.on_clic
def miEventoAEjecutar():
print "Se dio clic sobre miBoton!!!"
#Evento generado por usuario en el Boton
miBoton.clic()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment