next up previous
Next: The controller Up: The implementation glade-based Previous: The model

The glade-based view

glade-2 while editing the example is depicted in figure 1. The names for the main window, the label and the button are significant, and signal clicked of the button has been associated with a function called on_button_clicked.

Figure 1: glade-2 in action (click to enlarge)
\includegraphics[width=8cm]{glade-low.eps}

The result is saved in pygtkmvc-example.glade.

The view is represented by class MyView, that derives from class View provided by gtkmvc. The class View can be thought as a container that holds a set of widgets, and may associate each widget with a string name. When a glade file is used to build the view, each widget will be associated automatically inside the view with the corresponding name occurring in the glade file.

Moreover, each View instance is connected to a corresponding Controller, and when built from a glade file, methods inside the Controller will be scanned to try to connect automatically all signals declared in the glade file.

from gtkmvc.model import Model

  
# This is file model.py
from gtkmvc.view import View

class MyView (View):

def __init__(self, ctrl):
View.__init__(self, ctrl, 'pygtkmvc-example.glade')
return

pass # end of class

Class MyView calls simply View's class constructor from within its constructor, by passing the Controller instance which it belongs to, and the glade file name. All the hard work is carried out by class View.


next up previous
Next: The controller Up: The implementation glade-based Previous: The model
Roberto Cavada 2004-06-11