#!/usr/bin/env python

from gi.repository import Gtk, GLib

w = Gtk.Window()
w.connect('destroy', Gtk.main_quit)
tv = Gtk.TextView()
w.add(tv)
tb = tv.get_buffer()
tag = tb.create_tag('invisible')
tag.props.invisible = True
w.show_all()

BEFORE = "Not hidden before\n"
tb.insert(tb.get_start_iter(), BEFORE+"Not hidden after\n")
it = tb.get_start_iter()
it.forward_chars(len(BEFORE))

def f():
    tb.insert_with_tags(it, "123456789\n", tag)
    return True

GLib.idle_add(f)
Gtk.main()
