#
2 The Kiwi FrameWork

This section introduces the Kiwi framework, and shows the use cases that each of the main classes were designed for. Throughout this guide, I'll be showing code examples that are included in the distribution (in the examples/ directory); just install Kiwi and you are ready to run them. To start off with, I'll show a very simple Kiwi application that saves information defined in a graphical form. This app is included in examples/framework/person/person.py. Note that this app uses the glade file Person.glade.

    #!/usr/bin/env python
    import gtk
    from kiwi.model import PickledModel
    from kiwi.ui.delegates import ProxyDelegate

    # define the class that holds our application data
    class Person(PickledModel):
        pass
    person = Person.unpickle()

    # create and run a proxy interface attached to person
    view = ProxyDelegate(person, gladefile="Person",
                         widgets=["address", 'name', 'phone'],
                         delete_handler=gtk.main_quit)
    view.focus_topmost()
    view.show_and_loop()

    # save changes done to the instance
    person.save()

This application (17 lines) renders an interface to edit personal data, transparently saving and loading it. A quick glance at the code:

1. We define Person, a class to hold our application information
2. `Person.unpickle()` loads (creating, if it didn't exist) a Person instance.
3. We create a `ProxyDelegate` instance, which loads an interface from a glade definition file and attaches it to the Person instance.
4. We run the application; changes in the interface reflect transparently on the person instance.
5. Upon exiting the mainloop, the window closes and we save the person. It is ready to be edited the next time we run the program.

This example is a summary of many Kiwi features; it exemplifies the Proxy class, which is one of the more featureful parts of the framework. This guide will take you gradually through the different classes in Kiwi, and the next section begins by describing the general Kiwi architecture.