Source

gtkarchitect-main / gtkarchitect / model / project.py

Full commit

from lxml.etree import Element

from .entity import add_entity_child

import gobject

from kiwi.utils import gsignal


class Project(gobject.GObject):

    gsignal('entity-added', gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)

    def __init__(self, tree=None):
        gobject.GObject.__init__(self)
        if tree is None:
            tree = Element('interface')
        self.tree = tree

    def add_entity(self, entity, parent=None):
        if parent is None:
            parent_entity = self.tree
            no_child = True
        else:
            parent_entity = parent
            no_child = False
        add_entity_child(parent_entity, entity, no_child=no_child)
        self.emit('entity-added', entity, parent)

    def create_entity(self, definition, parent=None):
        entity = definition.create_entity()
        self.add_entity(entity, parent)