# The Controller

class `gtkmvc.controller.``Controller`(model, view, spurious=False, auto_adapt=False)

  Bases: `gtkmvc.observer.Observer`

  Two positional and two optional keyword arguments.

  model will have the new instance registered as an observer. It is made available as an attribute.

  view may contain signal connections loaded from XML. The handler methods have to exist in this class.

  spurious denotes whether notifications in this class will be called if a property of model is set to the same value it already has.

  auto_adapt denotes whether to call `adapt()` with no arguments as part of the view registration process.

  View registration consists of connecting signal handlers, `register_view()` and `register_adapters()`, and is scheduled with the GTK main loop. It happens as soon as possible but after the constructor returns. When it starts view is available as an attribute.

  `_find_widget_match`(prop_name)

    Used to search `self.view` when `adapt()` is not given a widget name.

    prop_name is the name of a property in the model.

    Returns a string with the best match. Raises `TooManyCandidatesError` or `ValueError` when nothing is found.

    Subclasses can customise this. No super call necessary. The default implementation converts prop_name to lower case and allows prefixes like `entry_`.

  `adapt`(*args)

    There are four ways to call this:

    `adapt`()

      Take properties from the model for which `adapt` has not yet been called, match them to the view by name, and create adapters fitting for the respective widget type.

      That information comes from `gtkmvc.adapters.default`. See `_find_widget_match()` for name patterns.

      Changed in version 1.99.1: Allow incomplete auto-adaption, meaning properties for which no widget is found.

    `adapt`(ad)

      Keep track of manually created adapters for future `adapt()` calls.

      ad is an adapter instance already connected to a widget.

    `adapt`(prop_name)

      Like `adapt()` for a single property.

      prop_name is a string.

    `adapt`(prop_name, wid_name)

      Like `adapt(prop_name)` but without widget name matching.

      wid_name has to exist in the view.

  `register_adapters`()

    This does nothing. Subclasses can override it to create adapters. No super call necessary.

  `register_view`(view)

    This does nothing. Subclasses can override it to connect signals manually or modify widgets loaded from XML, like adding columns to a TreeView. No super call necessary.

    view is a shortcut for `self.view`.