next up previous contents
Next: Using Adapters Up: A short tutorial for Previous: The main code   Contents

Multiple views, one model

This example shows the powerful of the Observer pattern.

Here both the glade-based and manually built versions are being run at the same time, with a single instance of class MyModel shared between those two versions. The execution of this example results in two windows being displayed; by clicking the button of one of them, the counter is incremented, and the labels in both of them are updated.

       
# This is file main_mixed.py
import gtk
from model import MyModel
from ctrl_no_glade import MyControllerNoGlade
from ctrl_glade import MyController
from view_no_glade import MyViewNoGlade
from view_glade import MyView

m = MyModel()
c1 = MyControllerNoGlade(m)
c2 = MyController(m)
v1 = MyViewNoGlade(c1)
v2 =  MyView(c2)
gtk.main()



Roberto Cavada 2008-08-26