from gi.repository import Gtk


def _destroy_cb(widget, data=None):
    Gtk.main_quit()

window = Gtk.Window()
window.connect("destroy", _destroy_cb)

view = Gtk.TextView()

buffer = view.get_buffer()
buffer.set_text('Hello World Hello GNOME!')
i = buffer.get_iter_at_offset(0)

(start, end) = i.forward_search('World', 0, 0)
print '# "world"'
print '  Start:', start.get_offset()
print '  End:', end.get_offset()

(start, end) = i.forward_search(
    'world',
    Gtk.TextSearchFlags.CASE_INSENSITIVE,
    None)

print '# "world" icase'
print '  Start:', start.get_offset()
print '  End:', end.get_offset()

window.add(view)

window.show_all()
Gtk.main()
