Skip to content

Instantly share code, notes, and snippets.

@hansent
Created March 7, 2011 13:07
Show Gist options
  • Select an option

  • Save hansent/858477 to your computer and use it in GitHub Desktop.

Select an option

Save hansent/858477 to your computer and use it in GitHub Desktop.
class KivyFactoryMetaClass(type):
def __new__(cls, name, bases, attrs):
#replacement for original __init__ function
original_init = attrs.get('__init__', bases[0].__init__)
def alternate_init(self,*args,**kwargs):
original_init(self,*args,**kwargs)
if name == self.__class__.__name__: #dont call base setup again
self.setup(**kwargs)
attrs['__init__'] = alternate_init
return super(KivyFactoryMetaClass, cls).__new__(cls, name, bases, attrs)
def __init__(self, name, bases, attrs):
super(KivyFactoryMetaClass, self).__init__(name, bases, attrs)
Factory.register(name, self)
print "Registered %s in Widget Factory" % name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment