Source

gtkarchitect-main / gtkarchitect / model / definitions.py


"""
Defines how widgets are displayed in gazpacho
"""

from lxml.etree import Element

from collections import defaultdict

from .entity import get_entity_type


class EntityDefinition(object):

    is_toplevel = False

    def __init__(self, entity_name, gadget_type=None, editor_type=None,
                 is_toplevel=False):
        self.new_item_counter = 1
        self.entity_name = entity_name
        self.gadget_type = gadget_type
        self.editor_type = editor_type
        self.is_toplevel = is_toplevel

    def create_entity(self):
        return Element('object', **{'class':self.entity_name})


class EntityCatalog(object):

    def __init__(self):
        self.entity_defs = defaultdict(list)
        self.entity_map = {}

    def register_entity_def(self, category, definition):
        self.entity_defs[category].append(definition)
        self.entity_map[definition.entity_name] = definition

    def get_entity_def(self, name):
        print 'ged', name, self.entity_map.get(name)
        return self.entity_map.get(name)

entity_catalog = EntityCatalog()


def get_entity_def(entity):
    return entity_catalog.get_entity_def(get_entity_type(entity))