Navigation

Kiwi is a library designed to make developing graphical applications as
easy as possible. It offers both a framework and a set of enhanced widgets,
and is based on Python and GTK+. Kiwi borrows concepts from MVC, Java Swing
and Microsoft MFC, but implements a set of unique classes that take
advantage of the flexibility and simplicity of Python to make real-world
application creation much easier.

The accessor module offers two important front-end functions:
kgetattr and ksetattr. These functions allow retrieving attribute values
from objects much in the same way as getattr/setattr allow, but with two
important differences:

They follow a dot hierarchy to retrieve or modify any value
reachable from the object.

They cache the method used to access a certain attribute and reuse
it the next time the value is retrieved.

Enables the use of the kgetattr cache when using Python
versions that do not support weakrefs (1.5.x and earlier). Be
warned, using the cache in these versions causes leaked
references to accessor methods and models!

Obtains from model a callable through which attr_name can be
retrieved. This callable is an accessor named get_foo, where
foo is the value of attr_name, or getattr(model, foo) if the
accessor does not exist. If the callable exists, it is returned;
if getattr() is to be used a tuple in the format (model,
attr_name) is returned.

Obtains from model a callable through which attr_name can be
set. This callable is an accessor named set_foo, where
foo is the value of attr_name, or setattr(model, foo, value) if the
accessor does not exist. If the callable exists, it is returned;
if setattr() is to be used a tuple in the format (model,
attr_name) is returned.

Returns the value associated with the attribute in model
named by attr_name. If default is provided and model does not
have an attribute called attr_name, the default value is
returned. If flat=1 is specified, no dot path parsing will
be done.

You can customize the checks by subclassing your type from CustomType,
there are two builtin types: number which is a float/int combined check
and a percent which verifis that the value is a percentage

It may seems like a bit of work, but this is everything that’s needed
for kiwi to figure out how to load resources when installed and when
running in an uninstalled mode, eg directly from the source tree.
To locate a pixmap called kiwi.png the following is enough:

This module defines a couple of extensions to the logging module included
in the python standard distribution.

It creates an additional logging handler that print log records on the
standard output. This handler is only showing records which has a level
set to logging.WARNING or higher by default.
The messages printed by this handler can be modified by using the environment
variable called KIWI_LOG.

The syntax for the string which KIWI_LOG points to is the following:

domain ':' level [, domain ':', level]

domain can contain wildcards such as * and ?
level is an integer 1-5 which defines the minimal level:

B{5}: DEBUG

B{4}: INFO

B{3}: WARNING

B{2}: ERROR

B{1}: CRITICAL

Examples:

KIWI_LOG="stoq*:5"

will print all the messages in a domain starting with stoq with DEBUG or higher:

KIWI_LOG="kiwi*:4,stoq.*:5"

will print all the messages with INFO or higher in all domains starting with kiwi,
and all the messages in the stoq.* domains which are DEBUG or higher

The Model is a mixin to be used by domain classes when attached to
Proxies. It also provides autonotification of changes to the
attached proxies. Note that if using setters, a specific call to
notify_proxies() may be necessary; see the doc for __setattr__.

PickledModel is a model that is able to save itself into a pickle
using save(). This has all the limitations of a pickle: its
instance variables must be picklable, or pickle.dump() will raise
exceptions. You can prefix variables with an underscore to make them
non-persistent (and you can restore them accordingly by overriding
__setstate__, but don’t forget to call PickledModel.__setstate__)

Saves the instance to a pickle filename. If no filename argument is
provided, will try to use the internal _filename attribute that is
set using set_filename()
:param filename: optional filename to pass in

Loads an instance from a pickle file; if it fails for some reason,
create a new instance.

filename: the file from which the pickle should be loaded.
If file is not provided, the name of the class suffixed by
”.pickle” is used (i.e. “FooClass.pickle” for the
class FooClass).

If the pickle file is damaged, it will be saved with the extension
”.err”; if a file with that name also exists, it will use ”.err.1”
and so on. This is to avoid the damaged file being clobbered by an
instance calling save() unsuspectingly.

I am an object which will call a classmethod called
__class_init__ when I am created.
Subclasses of me will also have __class_init__ called.

Note that __class_init__ is called when the class is created,
eg when the file is imported at the first time.
It’s called after the class is created, but before it is put
in the namespace of the module where it is defined.

This module adds infrastructure for managing tasklets. In this
context, a X{tasklet} is defined as a routine that explicitly gives
back control to the main program a certain points in the code, while
waiting for certain events. Other terms that may be used to describe
tasklets include I{coroutines}, or I{cooperative threads}.

The main advantages of tasklets are:

Eliminates the danger of unexpected race conditions or deadlocks
that happen with preemptive (regular) threads;

Reduces the number of callbacks in your code, that sometimes are
so many that you end up with I{spaghetti code}.

The fundamental block used to create tasklets is Python’s generators.
Generators are objects that are defined as functions, and when called
produce iterators that return values defined by the body of the
function, specifically C{yield} statements.

The neat thing about generators are not the iterators themselves but
the fact that a function’s state is completely frozen and restored
between one call to the iterator’s C{next()} and the following
one. This allows the function to return control to a program’s main
loop while waiting for an event, such as IO on a socket, thus allowing
other code to run in the mean time. When the specified event occurs,
the function regains control and continues executing as if nothing had
happened.

At the outset, a tasklet is simply a python U{generator
function<http://www.python.org/peps/pep-0255.html>}, i.e. a function
or method containing one or more C{yield} statements. Tasklets add a
couple more requirements to regular generator functions:

Inside tasklet functions, C{yield} statements are used to suspend
execution of the tasklet while waiting for certain events. Valid
C{yield} values are:

A single Message object, with a correctly set I{dest}
parameter. With this form, a message is sent to the indicated
tasklet. When C{yield} returns, no event is generated, so the
tasklet should B{not} call get_event.

When a wait condition receives the event it is waiting for, it
should call the method
L{wait_condition_fired<Tasklet.wait_condition_fired>} of the
tasklet with the wait condition as argument. The method
returns True or False; if it returns True, it means the
WaitCondition object must “rearm” itself (continue to monitor
events), otherwise it should disarm.

Parameters:

tasklet – the tasklet instance the wait condition is
to be associated with.