Internals

This page contains the Support Package documentation.

The metaclasses Module

class gtkmvc.support.metaclasses.PropertyMeta(name, bases, _dict)

Bases: type

This is a meta-class that provides auto-property support. The idea is to allow programmers to define some properties which will be automatically connected to auto-generated code which handles access to those properties. How can you use this meta-class? First, ‘__metaclass__ = PropertyMeta’ must be class member of the class you want to make the automatic properties handling. Second, ‘__properties__’ must be a map containing the properties names as keys, values will be initial values for properties. That’s all: after the instantiation, your class will contain all properties you named inside ‘__properties__’. Each of them will be also associated to a couple of automatically-generated functions which get and set the property value inside a generated member variable. About names: suppose the property is called ‘x’. The generated variable (which keeps the real value of the property x) is called _prop_x. The getter is called get_prop_x(self), and the setter is called ‘set_prop_x(self, value)’.

Customization: The base implementation of getter is to return the value stored in the variable associated to the property. The setter simply sets its value. Programmers can override basic behaviour for getters or setters simply by defining their getters and setters (see at the names convention above). The customized function can lie everywhere in the user classes hierarchy. Every overridden function will not be generated by the metaclass.

To supply your own methods is good for few methods, but can result in a very unconfortable way for many methods. In this case you can extend the meta-class, and override methods get_[gs]etter_source with your implementation (this can be probably made better). An example is provided in meta-class PropertyMetaVerbose below.

class constructor

check_value_change(old, new)
Checks whether the value of the property changed in type or if the instance has been changed to a different instance. If true, a call to model._reset_property_notification should be called in order to re-register the new property instance or type
create_value(prop_name, val, model=None)
This is used to create a value to be assigned to a property. Depending on the type of the value, different values are created and returned. For example, for a list, a ListWrapper is created to wrap it, and returned for the assignment. model is different from None when the value is changed (a model exists). Otherwise, during property creation model is None
get_getter(prop_name, user_getter=None, getter_takes_name=False)

Returns a function wich is a getter for a property. prop_name is the name off the property.

user_getter is an optional function doing the work. If specified, that function will be called instead of getting the attribute whose name is in ‘prop_name’.

If user_getter is specified with a False value for getter_takes_name (default), than the method is used to get the value of the property. If True is specified for getter_takes_name, then the user_getter is called by passing the property name (i.e. it is considered a general method which receive the property name whose value has to be returned.)

get_setter(prop_name, user_setter=None, setter_takes_name=False, user_getter=None, getter_takes_name=False)
Similar to get_getter, but for setting property values. If user_getter is specified, that it may be used to get the old value of the property before setting it (this is the case in some derived classes’ implementation). if getter_takes_name is True and user_getter is not None, than the property name is passed to the given getter to retrieve the property value.
has_prop_attribute(prop_name)
This methods returns True if there exists a class attribute for the given property. The attribute is searched locally only
class gtkmvc.support.metaclasses.ObservablePropertyMeta(name, bases, dict)

Bases: gtkmvc.support.metaclasses.PropertyMeta

Classes instantiated by this meta-class must provide a method named notify_property_change(self, prop_name, old, new)

get_getter(prop_name, user_getter=None, getter_takes_name=False)
This implementation returns the PROP_NAME value if there exists such property. Otherwise there must exist a logical getter (user_getter) which the value is taken from. If no getter is found, None is returned (i.e. the property cannot be created)
get_setter(prop_name, user_setter=None, setter_takes_name=False, user_getter=None, getter_takes_name=False)
The setter follows the rules of the getter. First search for property variable, then logical custom setter. If no setter is found, None is returned (i.e. the property is read-only.)
class gtkmvc.support.metaclasses.ObservablePropertyMetaMT(name, bases, dict)

Bases: gtkmvc.support.metaclasses.ObservablePropertyMeta

This class provides multithreading support for accesing properties, through a locking mechanism. It is assumed a lock is owned by the class that uses it. A Lock object called _prop_lock is assumed to be a member of the using class. see for example class ModelMT

get_setter(prop_name, user_setter=None, setter_takes_name=False, user_getter=None, getter_takes_name=False)
The setter follows the rules of the getter. First search for property variable, then logical custom getter/seter pair methods
class gtkmvc.support.metaclasses.ObservablePropertyGObjectMeta(name, bases, dict)
Bases: gtkmvc.support.metaclasses.ObservablePropertyMeta, gobject.GObjectMeta
class gtkmvc.support.metaclasses.ObservablePropertyGObjectMetaMT(name, bases, dict)
Bases: gtkmvc.support.metaclasses.ObservablePropertyMetaMT, gobject.GObjectMeta

The decorators Module

gtkmvc.support.decorators.good_classmethod_decorator(decorator)
This decorator makes class method decorators behave well wrt to decorated class method names, doc, etc.
gtkmvc.support.decorators.good_decorator(decorator)
This decorator makes decorators behave well wrt to decorated functions names, doc, etc.
gtkmvc.support.decorators.good_decorator_accepting_args(decorator)

This decorator makes decorators behave well wrt to decorated functions names, doc, etc.

Differently from good_decorator, this accepts decorators possibly receiving arguments and keyword arguments.

This decorato can be used indifferently with class methods and functions.

Table Of Contents

Previous topic

Little Helpers

This Page