Skip to content

Instantly share code, notes, and snippets.

@xlarsx
Created March 9, 2011 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlarsx/862985 to your computer and use it in GitHub Desktop.
Save xlarsx/862985 to your computer and use it in GitHub Desktop.
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