Source

gtkarchitect-main / gtkarchitect / gtkentities / __init__.py

Full commit

"""
Entity definitions for the GTK Entities
"""

import gtk

from ..model.definitions import EntityDefinition, entity_catalog
from ..view.gadget import Gadget, ContainerGadget, WidgetGadget
from ..view.placeholder import Placeholder


class ButtonGadget(WidgetGadget):

    def create_widget(self):
        return gtk.Button()


class WindowGadget(ContainerGadget):

    def create_ui(self):
        t = self.get_toplevel()
        self.widget = gtk.Frame()
        t.add(self.widget)


class FrameGadget(ContainerGadget):

    def create_ui(self):
        t = self.get_toplevel()
        self.widget = gtk.Frame('')
        t.add(self.widget)


class BoxGadget(ContainerGadget):
    """Abstract"""

    def set_defaults(self):
        for i in range(3):
            self.create_placeholder()

    def add_widget(self, widget, position):
        ContainerGadget.add_widget(self, widget, position)
        self.widget.reorder_child(widget, position)


class VBoxGadget(BoxGadget):

    def create_widget(self):
        return gtk.VBox()


class HBoxGadget(BoxGadget):

    def create_widget(self):
        return gtk.HBox()


class NotebookGadget(ContainerGadget):

    def set_defaults(self):
        self.create_placeholder()
        self.create_placeholder()
        self.create_placeholder()

    def create_widget(self):
        return gtk.Notebook()

    def add_widget(self, widget, position):
        ContainerGadget.add_widget(self, widget, position)
        self.widget.reorder_child(widget, position)


entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkButton', gadget_type=ButtonGadget)
)
entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkWindow', gadget_type=WindowGadget,
                                    is_toplevel=True)
)

entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkFrame', gadget_type=FrameGadget)
)

entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkVBox', gadget_type=VBoxGadget)
)

entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkHBox', gadget_type=HBoxGadget)
)

entity_catalog.register_entity_def(
    'GTK Widgets', EntityDefinition('GtkNotebook', gadget_type=NotebookGadget)
)



class ObjectTreeGadget(Gadget):

    def create_widget(self):
        from kiwi.ui.objectlist import ObjectList
        o = ObjectList()
        o.show_all()
        return o

entity_catalog.register_entity_def(
    'Kiwi Widgets', EntityDefinition('ObjectList',
    gadget_type=ObjectTreeGadget)
)