Re: problem: text view appends



Deependra Shekhawat wrote:

Hello friends,
I am trying to append text in a text view, don't know
how to do this (tried alot of things).


here is code snippet:

gint call_me(gpointer user_data)
{
      int bytes=0,temp;
//checks to see whether called for first time or not
      static int flag=1;
      GtkWidget *textview1;
      FILE *fp;
      gchar *buffer=NULL;
 GtkTextBuffer *buffer2=gtk_text_buffer_new(NULL);

      textview1=(GtkWidget *)user_data;
      fp=fopen("/var/log/messages","r");
      while(1)
      {
              temp=getline(&buffer,&bytes,fp);
              if(temp<=0)
                      break;                  
      }
      if(flag)
      {
                      gtk_text_buffer_set_text(buffer2,buffer,-1);
                      flag=0;
      }
      else
      {
//TODO: something that makes the previous text as it
is     // and the new text to appear below it. (don't
know 
// what to write).
      }

gtk_text_view_set_buffer(GTK_TEXT_VIEW(textview1),buffer2);
      fclose(fp);
      return 1;
}

and here is the timeout function call:

gint
i=g_timeout_add(1000,call_me,(gpointer)textview1);

what should i write in the commented area (else part)
so that the text previously displayed by the view
doesn't get's cleared up and the new text (line in
this case) gets appear below it.

 

It's not there that you must do something. It's before.

Don't use gtk_text_buffer_set_text(). That will overwrite everything in
the text view with it's argument.

Use gtk_text_buffer_insert(). Get and end iter with
gtk_text_buffer_get_end_iter().

You should really look at the documentation for GtkTextView and its
associated classes.


-- 
Newman's Discovery:
        Your best dreams may not come true; fortunately, neither will
        your worst dreams.

Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb




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