Model Classes
There are several possible ways to derive your model. All look the same
to a Controller.
-
class gtkmvc.model.Model
Bases: gtkmvc.observer.Observer
-
__observables__
Class attribute. A list or tuple of name strings. The metaclass
ObservablePropertyMeta
uses it to create properties.
Value properties have to exist as an attribute with an
initial value, which may be None.
Logical properties require a getter and may have a setter method in
the class.
-
get_properties()
All observable properties accessible from this instance.
Return type: | frozenset of strings |
-
classmethod getter(*f, **k)
Decorate a method as a logical property getter. Comes in two flavours:
-
getter()
- Uses the name of the method as the property name.
The method must not require arguments.
-
getter(one, two, ...)
- Takes a variable number of strings as the property
name(s). The name of the method does not matter.
The method must take a property name as its sole argument.
-
has_property(name)
- Returns true if given property name refers an observable
property inside self or inside derived classes.
-
notify_method_after_change(prop_name, instance, meth_name, res, args, kwargs)
Send a notification to all registered observers.
args the arguments we just passed to meth_name.
res the return value of the method call.
-
notify_method_before_change(prop_name, instance, meth_name, args, kwargs)
Send a notification to all registered observers.
instance the object stored in the property.
meth_name name of the method we are about to call on instance.
-
notify_property_value_change(prop_name, old, new)
Send a notification to all registered observers.
old the value before the change occured.
-
notify_signal_emit(prop_name, arg)
Emit a signal to all registered observers.
prop_name the property storing the Signal
instance.
arg one arbitrary argument passed to observing methods.
-
register_observer(observer)
- Register given observer among those observers which are
interested in observing the model.
-
classmethod setter(*f, **k)
Decorate a method as a logical property setter. The counterpart to
getter(). Also comes in two flavours:
-
setter()
- Uses the name of the method as the property name.
The method must take one argument, the new value.
-
getter(one, two, ...)
- Takes a variable number of strings as the property
name(s). The name of the method does not matter.
The method must take two arguments, the property name and new value.
-
unregister_observer(observer)
- Unregister the given observer that is no longer interested
in observing the model.
Persistence
Threading
-
class gtkmvc.model_mt.ModelMT
- A base class for models whose observable properties can be
changed by threads different than gtk main thread. Notification is
performed by exploiting the gtk idle loop only if needed,
otherwise the standard notification system (direct method call) is
used. In this model, the observer is expected to run in the gtk
main loop thread.
-
class gtkmvc.model_mt.TextBufferModelMT(table=None)
- Use this class as base class for your model derived by
gtk.TextBuffer
-
class gtkmvc.model_mt.ListStoreModelMT(column_type, *args)
- Use this class as base class for your model derived by
gtk.ListStore
-
class gtkmvc.model_mt.TreeStoreModelMT(column_type, *args)
- Use this class as base class for your model derived by
gtk.TreeStore