In our previous example, our model was defined as an instance of a simple Python class. If we use the complete framework, by having our model classes inherit from FrameWork.Model, we also get reverse notifications from Model to Proxy: when the model is altered, the change propagates to the proxy interface attached to it.
To demonstrate, we can extend the example above to add a "reset" button
to trigger a change of the model; we will subclass GladeProxy (which is
also a Delegate, as stated before, and thus supports the special handler
syntax on_*()
) to define a handler for clicking on the reset
button (examples/NewsForm/newsform2.py):
If we look at the handler for reset, on_reset__clicked()
, we
can see it alters the model directly. These changes reflect
automatically in the interface by means of an update mechanism present
in FrameWork.Model. This holds true no matter what function
triggers the change in the model: it is not limited to callbacks defined
in Proxy itself; any handler that alters the model will trigger the
model's update mechanism.
In summary: if you need to alter your model independently of the interface, have your model inherit from FrameWork.Model and enjoy automatic UI updating.
In all the examples we have shown up to now, you may notice that the proxy manipulates the model's instance variables directly. There are times where this is not desirable, and the next section explains how to customize the proxy and model's behavior.