diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py index d5227037e..ff25e9d0f 100644 --- a/kivy/uix/widget.py +++ b/kivy/uix/widget.py @@ -59,6 +59,7 @@ widget moves, you can bind your own callback function like this:: __all__ = ('Widget', 'WidgetException') from kivy.event import EventDispatcher +from kivy.factory import Factory from kivy.properties import NumericProperty, StringProperty, \ AliasProperty, ReferenceListProperty, ObjectProperty, \ ListProperty @@ -73,6 +74,17 @@ class WidgetException(Exception): pass +class WidgetMetaclass(type): + '''Metaclass to auto register new widget into :class:`~kivy.factory.Factory` + + .. warning:: + This metaclass is used for Widget. Don't use it directly ! + ''' + def __init__(mcs, name, bases, attrs): + super(WidgetMetaclass, mcs).__init__(name, bases, attrs) + Factory.register(name, cls=mcs) + + class Widget(EventDispatcher): '''Widget class. See module documentation for more information. @@ -91,6 +103,8 @@ class Widget(EventDispatcher): ''' + __metaclass__ = WidgetMetaclass + def __init__(self, **kwargs): # Before doing anything, ensure the windows exist. EventLoop.ensure_window()