Writing to a buffer

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing to a buffer

Christos Jonathan Hayward
I presently have a buffer that I create:

    pmsg_buffer = GTK_WIDGET(gtk_text_buffer_new(NULL));
    pmsg_text_view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(
      pmsg_buffer));
    gtk_widget_show(pmsg_text_view);
    gtk_widget_show(pmsg_buffer);

and then update from a function by inserting text at the end:

    GtkTextIter *iterator;
    g_print("New_pmsg 1\n");
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), "\n",
      strlen("\n"));
    g_print("New_pmsg 2\n");
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), message,
      strlen(message));
    g_print("New_pmsg 3\n");
    gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(pmsg_buffer), iterator);
    g_print("New_pmsg 4\n");
    g_print("New_pmsg 5\n");
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pmsg_text_view), iterator,
      0.0f, 1, 0.0f, 1.0f);
    g_print("New_pmsg 6\n");

When I run it, the function behaves as expected the first time (the text is displayed).

On subsequent runs, it doesn't appear to display any of the new text. There are error messages:

New_pmsg 1

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'

(gtk_tms:12510): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `GdkWindow'

(gtk_tms:12510): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
New_pmsg 2

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'

(gtk_tms:12510): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `GdkWindow'

(gtk_tms:12510): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
New_pmsg 3

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'
New_pmsg 4
New_pmsg 5
New_pmsg 6

Is it interpreting the output of gtk_text_buffer_new() as a GdkWindow? I don't have any other code that refers to pmsg_buffer. What should I do next?
--
++ Jonathan Hayward, [hidden email]
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!
_______________________________________________
gtk-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Writing to a buffer

Christos Jonathan Hayward
It's now manifesting a different problem. I can write at the end of a text_buffer inside a text_view, but not tell it to scroll down. The last two calls are meant to scroll all the way down:

void new_pmsg(char* message)
    {
    GtkTextIter iterator;
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), "\n",
      strlen("\n"));
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), message,
      strlen(message));
    gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(pmsg_buffer), &iterator);
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pmsg_text_view), &iterator,
      0.0f, 1, 0.0f, 1.0f);
    }

Any obvious mistakes in this?

On 8/4/05, Jonathan Hayward <[hidden email]> wrote:
I presently have a buffer that I create:

    pmsg_buffer = GTK_WIDGET(gtk_text_buffer_new(NULL));
    pmsg_text_view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(
      pmsg_buffer));
    gtk_widget_show(pmsg_text_view);
    gtk_widget_show(pmsg_buffer);

and then update from a function by inserting text at the end:

    GtkTextIter *iterator;
    g_print("New_pmsg 1\n");
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), "\n",
      strlen("\n"));
    g_print("New_pmsg 2\n");
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), message,
      strlen(message));
    g_print("New_pmsg 3\n");
    gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(pmsg_buffer), iterator);
    g_print("New_pmsg 4\n");
    g_print("New_pmsg 5\n");
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pmsg_text_view), iterator,
      0.0f, 1, 0.0f, 1.0f);
    g_print("New_pmsg 6\n");

When I run it, the function behaves as expected the first time (the text is displayed).

On subsequent runs, it doesn't appear to display any of the new text. There are error messages:

New_pmsg 1

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'

(gtk_tms:12510): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `GdkWindow'

(gtk_tms:12510): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
New_pmsg 2

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'

(gtk_tms:12510): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `GdkWindow'

(gtk_tms:12510): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
New_pmsg 3

(gtk_tms:12510): GLib-GObject-WARNING **: invalid uninstantiatable type `GdkWindow' in cast to `GdkWindow'
New_pmsg 4
New_pmsg 5
New_pmsg 6

Is it interpreting the output of gtk_text_buffer_new() as a GdkWindow? I don't have any other code that refers to pmsg_buffer. What should I do next?
--
++ Jonathan Hayward, [hidden email]
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at <a href="http://JonathansCorner.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://JonathansCorner.com

** If you'd like a Google Mail (<a href="http://gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> gmail.com) account, please tell me!



--
++ Jonathan Hayward, [hidden email]
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail ( gmail.com) account, please tell me!
_______________________________________________
gtk-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Writing to a buffer

Tim-Philipp Müller
On Friday 05 August 2005 16:05, Jonathan Hayward wrote:

> It's now manifesting a different problem. I can write at the end of a
> text_buffer inside a text_view, but not tell it to scroll down. The last
> two calls are meant to scroll all the way down:
>  ...
> gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(pmsg_buffer), &iterator);
> gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pmsg_text_view), &iterator,
> 0.0f, 1, 0.0f, 1.0f);
>
> Any obvious mistakes in this?

You probably need to use _scroll_to_mark(), see question 4.3:

http://developer.gnome.org/doc/API/2.0/gtk/gtk-question-index.html

Cheers
 -Tim
_______________________________________________
gtk-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Writing to a buffer

Christos Jonathan Hayward

> Any obvious mistakes in this?

You probably need to use _scroll_to_mark(), see question 4.3:

http://developer.gnome.org/doc/API/2.0/gtk/gtk-question-index.html

Thanks for the pointer; it isn't working yet. The text displays, but it doesn't scroll down. The code that's doing the inserts is:

    GtkTextMark *mark;
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), "\n",
      strlen("\n"));
    gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(pmsg_buffer), message,
      strlen(message));
    mark = gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(pmsg_buffer));
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(pmsg_text_view), mark, 0.0, 1,
      0.0f, 1.0f);

I've fiddled around with the gtk_text_view_scroll_to_mark() parameters, and it doesn't scroll down.

Should I be trying to scroll its scrolled window instead? The initializer code is:

    scrolled_window = gtk_scrolled_window_new(NULL, NULL);
    scrolled_window_vertical_adjustment =
      gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window));
    gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 0);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
      GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
    gtk_box_pack_start(GTK_BOX(vbox1), scrolled_window, FALSE,
      FALSE, 0);
    gtk_widget_show(scrolled_window);
    pmsg_buffer = gtk_text_buffer_new(NULL);
    pmsg_text_view =
      gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(pmsg_buffer));
    gtk_widget_show(GTK_WIDGET(pmsg_text_view));
    gtk_widget_show(scrolled_window);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
      GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
      scrolled_window), pmsg_text_view);


--
++ Jonathan Hayward, [hidden email]
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!
_______________________________________________
gtk-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-list