title: Overriding virtual methods in PyGObject
body: <p>I'm trying to implement the <a href="http://developer.gnome.org/gtk3/3.2/GtkWidget.html#geometry-management" rel="noreferrer">Heigh-for-width Geometry Management</a> in GTK with Python for my custom Widget. My widget is a subclass from <code>Gtk.DrawingArea</code> and draws some parts of an Image.</p>
  
  <p>As I understood the GTK Docs (link above) I have to implement the following 4 methods:</p>
  
  <ul>
  <li>GtkWidgetClass.get_preferred_width()</li>
  <li>GtkWidgetClass.get_preferred_height()</li>
  <li>GtkWidgetClass.get_preferred_height_for_width()</li>
  <li>GtkWidgetClass.get_preferred_width_for_height()</li>
  </ul>
  
  <p>Now wondering where to implement this in Python.</p>
  
  <p>I tried this:</p>
  
  <pre><code>from gi.repository import Gtk
  class Patch(Gtk.DrawingArea):
    def __init__(self, model, image, position):
      super(Patch,self).__init__()
      #…
  
    def get_preferred_width(self, *args, **kargs):
      print("test")
  
    def get_preferred_height(self, *args, **kargs):
      print("test")
  
    def get_preferred_width_for_height(self, *args, **kargs):
      print("test")
  
    def get_preferred_height_for_width(self, *args, **kargs):
      print("test")
  </code></pre>
  
  <p>But the methods don't get called. In C you define the functions and set it to the widget like this:</p>
  
  <pre><code>static void
  my_widget_get_preferred_height (GtkWidget *widget, gint *minimal_height,
                                  gint *natural_height)
  {
    /* ... */
  }
    /* ... */
  
  static void
  my_widget_class_init (MyWidgetClass *class)
  {
    /* ... */
    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
    widget_class-&gt;get_preferred_height = my_widget_get_preferred_height;
    /* ... */
  }
  </code></pre>
  
  <p>How is this done in Python?</p>