next up previous
Next: Conclusions Up: A short tutorial for Previous: The main code

More convoluted main code

Finally, 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.mainloop()



Roberto Cavada 2004-06-11