# Path: tilenol/event.py
# class Event(object):
# 
#     def __init__(self, name=None):
#         self.name = name
#         self._listeners = []
#         self._worker = None
# 
#     def listen(self, fun):
#         self._listeners.append(fun)
# 
#     def unlisten(self, fun):
#         self._listeners.remove(fun)
# 
#     def emit(self):
#         log.debug("Emitting event %r", self.name)
#         if self._worker is None and self._listeners:
#             self._worker = gethub().do_spawn(self._do_work)
# 
#     def _do_work(self):
#         try:
#             log.debug("Processing event %r", self.name)
#             for l in self._listeners:
#                 l()
#         finally:
#             self._worker = None


from collections import OrderedDict
from zorro.di import di, has_dependencies, dependency
from tilenol.event import Event


class LayoutMeta(type):

    @classmethod
    def __prepare__(cls, name, bases):
        return OrderedDict()

    def __init__(cls, name, bases, dic):
        cls.fields = list(dic.keys())


@has_dependencies
class Layout(metaclass=LayoutMeta):

    def __init__(self):
        self.visible = False
        self.relayout = Event('layout.relayout')
        self.relayout.listen(self.check_relayout)

    def check_relayout(self):
        if self.visible:
            self.layout()
            self.group.check_focus()

    @classmethod
    def get_defined_classes(cls, base):
        res = OrderedDict()
        for k in cls.fields:
            v = getattr(cls, k)

# Path: tilenol/event.py
# class Event(object):
# 
#     def __init__(self, name=None):
#         self.name = name
#         self._listeners = []
#         self._worker = None
# 
#     def listen(self, fun):
#         self._listeners.append(fun)
# 
#     def unlisten(self, fun):
#         self._listeners.remove(fun)
# 
#     def emit(self):
#         log.debug("Emitting event %r", self.name)
#         if self._worker is None and self._listeners:
#             self._worker = gethub().do_spawn(self._do_work)
# 
#     def _do_work(self):
#         try:
#             log.debug("Processing event %r", self.name)
#             for l in self._listeners:
#                 l()
#         finally:
#             self._worker = None


# Path: tilenol/layout/base.py
from collections import OrderedDict
from zorro.di import di, has_dependencies, dependency
from tilenol.event import Event



class LayoutMeta(type):

    @classmethod
    def __prepare__(cls, name, bases):
        return OrderedDict()

    def __init__(cls, name, bases, dic):
        cls.fields = list(dic.keys())


@has_dependencies
class Layout(metaclass=LayoutMeta):

    def __init__(self):
        self.visible = False
        self.relayout = Event('layout.relayout')
        self.relayout.listen(self.check_relayout)

    def check_relayout(self):
        if self.visible:
            self.layout()
            self.group.check_focus()

    @classmethod
    def get_defined_classes(cls, base):
        res = OrderedDict()
        for k in cls.fields:
            v = getattr(cls, k)

            if isinstance(v, type) and issubclass(v, base):