Subject: GTK2.TextView and tags - assistance requested
From: Chris Angelico <rosuav@gmail.com>
Date: Sun, 18 Sep 2011 AD 09:32:30 -0400

I'm trying to write a program that will display lines of text in
various colors, governed at run-time, and am currently attempting to
do this using a GTK2.TextView and the insert_with_tags() method.
Pike's giving me an assertion failure that suggests that I need to
link the tag object to something, but I'm not understanding what. Any
assistance or advice gratefully received!

My code:

GTK2.TextBuffer buf;

int main()
{
    GTK2.setup_gtk();
    buf=GTK2.TextBuffer();
    object mainwindow=GTK2.Window(GTK2.WindowToplevel);
    mainwindow->set_title("Testing")->set_default_size(800,600)->signal_connect("destroy",window_destroy);
    mainwindow->signal_connect("delete_event",window_destroy);
    mainwindow->add(
        GTK2.TextView(buf)->set_editable(0)->set_cursor_visible(0)
    )->show_all();
    buf->insert_with_tags(buf->get_end_iter(),"asdf\n",-1,({GTK2.TextTag((["left-margin":200]))}));
    buf->insert_with_tags(buf->get_end_iter(),"qwer\n",-1,({GTK2.TextTag((["background":"blue"]))}));
    return -1;
}
int window_destroy(object self)
{
        exit(0);
}

The output:

(pike.exe:9660): Gtk-CRITICAL **: gtk_text_buffer_apply_tag: assertion
`tag->table == buffer->tag_table' failed

(pike.exe:9660): Gtk-CRITICAL **: gtk_text_buffer_apply_tag: assertion
`tag->table == buffer->tag_table' failed

The text is added, but with default attributes. (As a side point, I
have no idea what the correct format for the background attribute is.)

Thanks in advance!

Chris Angelico

Return to results