Re: Textview



Thanks Robert.

In fact this was explained to me about a year ago, but clearly I didn't entirely grasp what they were saying.
I really appreciate your answer. Very helpful.

Thanks again,
Dave


From: Robert Pearce <rob bdt-home demon co uk>
To: gtk-list gnome org
Cc: David Buchan <pdbuchan yahoo com>
Sent: Saturday, May 26, 2012 3:23 AM
Subject: Re: Textview

Hi David,

On Fri, 25 May 2012 18:24:59 -0700 (PDT) you wrote:
> Hi guys,
>
> This might be a really dumb one...
>
It's certainly a very common "failure to grasp a basic concept" issue.


> --- code tidbits ---
>
> Loop:
>
>             memset (text, 0, 100);
>             sprintf (text, "some very interesting data", interesting_arguments);
>             textbuffer1 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data->textview1));
>             gtk_text_buffer_get_end_iter (textbuffer1, &end);
>             gtk_text_buffer_insert (textbuffer1, &end, text, -1);
>             gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (data->textview1), &end, 0.0, FALSE, 0, 0);
>
> End Loop
>
> --- end of code ---
>
> Any idea what I've done wrong?
>

You have not understood that EVERYTHING done by Gtk (and all such tool
kits) gets buffered for performance reasons. Your program is hogging
the CPU doing its work, part of which is to populate the text buffer,
and never letting Gtk have a chance to update the display. If you want
the display to respond, you MUST let the Gtk main loop get a slot. Try
re-writing your code into a form like:

    g_idle_add ( my_worker_callback, NULL );


Gboolean my_worker_callback(gpointer data)
{
    do_some_small_amount_of_stuff();
    sprintf (text, "some very interesting data", interesting_arguments);
    textbuffer1 = gtk_text_view_get_buffer (GTK_TEXT_VIEW(data->textview1));
    gtk_text_buffer_get_end_iter (textbuffer1, &end);
    gtk_text_buffer_insert (textbuffer1, &end, text, -1);
    gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (data->textview1),&end, 0.0, FALSE, 0, 0);
    return more_to_do_yet;
}

(You'll need to check the syntax details, I've only thrown together a
basic shape)

In other words, don't use a loop construct - instead register the
contents of the loop as an idle task and let the Gtk main loop be your
loop.


HTH,
Rob




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]