from gi.repository import Gtk, GObject

class MyButton(Gtk.Button):
    __gtype_name__ = 'MyButton'

    def __init__(self):
        Gtk.Button.__init__(self)

GObject.type_register(MyButton)

builder = Gtk.Builder()
builder.add_from_string('''
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="MyButton" id="btn1" />
</interface>
''')
btn1 = builder.get_object('btn1')
print 'got button from builder:', btn1
assert btn1.__gtype_name__ == 'MyButton'
assert btn1.__grefcount__ == 1
