Created
March 9, 2011 20:51
-
-
Save xlarsx/862985 to your computer and use it in GitHub Desktop.
Ejemplo de gestión de eventos con decoradores en Python
This file contains 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 characters
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