Part of vmc.contrib.gtkmvc.support.metaclass_base View In Hierarchy
Known subclasses: vmc.contrib.gtkmvc.support.metaclasses.ObservablePropertyMeta
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 overrided 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.Method | __init__ | class constructor |
Method | __msg__ | if level is less or equal to VERBOSE_LEVEL, ths message will |
Method | __create_prop_accessors__ | Private method that creates getter and setter, and the |
Method | check_value_change | Checks whether the value of the property changed in type |
Method | create_value | This is used to create a value to be assigned to a |
Method | get_getter_source | This must be overrided if you need a different implementation. |
Method | get_setter_source | This must be overrided if you need a different implementation. |