1. Ronny Pfannschmidt
  2. gtkarchitect-main

Source

gtkarchitect-main / gtkarchitect / view / gadget.py


import gtk, gobject

from kiwi.utils import gsignal

from base import Slave

from ..controller.command import EntityPropertyChangeCommand
from .placeholder import Placeholder

class GadgetHolder(gtk.EventBox):

    def __init__(self):
        gtk.EventBox.__init__(self)


class Gadget(Slave):

    gsignal('placeholder-clicked', gobject.TYPE_PYOBJECT)

    def __init__(self, entity):
        self.entity = entity
        self.placeholders = []
        Slave.__init__(self)

    def create_toplevel_widget(self):
        return GadgetHolder()

    def create_ui(self):
        pass

    def fill_empty(self):
        pass

    def register_placeholder(self, placeholder):
        placeholder.connect('clicked', self._on_placeholder_clicked)
        self.placeholders.append(placeholder)

    def set_prop(self, property, value):
        c = EntityPropertyChangeCommand(None)
        c.do(self.entity, property, value)
        return c

    def _on_placeholder_clicked(self, placeholder):
        print 'ph clicked'
        self.emit('placeholder-clicked', placeholder)

    def add_gadget(self, gadget):
        p = self.placeholders.pop(0)
        self.widget.remove(p)
        p.unparent()
        print gadget.get_toplevel()
        self.widget.add(gadget.get_toplevel())
        self.widget.show_all()


class ContainerGadget(Gadget):

    def fill_empty(self):
        print 'fill empty'
        p = Placeholder()
        self.register_placeholder(p)
        self.widget.add(p)
        p.show()


if __name__ == '__main__':
    from lxml.etree import Element, tostring
    e = Element('a')

    g = Gadget(e)
    g.set_prop('foo', 'blah')
    c = g.set_prop('foo', 'blar')
    print tostring(e)
    c.undo()
    print tostring(e)