The code for a graphical user interface can very quickly get very messy. In very small applications, such as our old interface, it is sufficient to simply lump all the code together. But as the application gets more complex, better techniques of building the interface need to be used, in order to allow extendability and modularity. Large applications will make their own classes or data types that wrap GTK, and so for example when adding a new option to a preferences dialogue, an object is created of the type of preference that that preference is is created. That class will then handle how that preference is created, it will handle connecting its signals to the correct callback, and also how that preference is stored.
In our case, we don't need such a complex system, but we will use some routines
to make extending the interface easier. Subjects are created by the
addSubject
method. This method takes a class to be created, an optional
change method, and an optional configuration page associated with that class.
It creates the class and stores it in a dictionary, along with its change
function and configuration page. The configuration page is automatically added
to the interface, and the change method is called when the user selects that
function or deselects that function. A similar method is used to create
observers.
Using this method, new functions can be added into the interface with just one line of code. Configuration pages and change methods take more lines of code, but they are kept separate from the rest of the interface, they can even come from another module or file. This ensures ease of extendability.