Created
March 7, 2011 13:07
-
-
Save hansent/858477 to your computer and use it in GitHub Desktop.
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 characters
| 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