[Glade-users] Output text to TextView widget. How?



On Sat, 2003-06-21 at 10:42, Ahmad Al-rasheedan wrote:
I started using Glade 2 days ago and have zillions of questions.
Can you please help in the following code? I basically need to
display "Hi there" in the TextView widget upon pressing of a button.

---

on_button5_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
 gchar output[50]= "Hi there";
 GtkWidget *target = NULL;
 
 target = lookup_widget(GTK_WIDGET(button), "textview1");

/ * 

Don't know what to put here to have "Hi there" display in the
TextView widget
This is all in the API documentation on gtk.org or using the DevHelp
program with gtk+ books installed.  Basicly whenever you see View in the
name of a widget then it uses a model/view architecture.  Views are used
to display data in models so any editing of the data needs to be done on
the model.  In this case the model is a GtkTextBuffer.  Use the method
GtkTextBuffer buf = gtk_text_view_get_buffer(text_view);

You can then use any of the gtk_text_buffer_insert methods to insert
text.  gtk_text_buffer_insert_at_cursor is probably the easiest to use. 
I think the tutorial on gtk.org goes deeper into using iterators.

Also when using libglade I think it is best to get refrences to all the
widgets you are going to use and put them in a struct at the beginning
of your program.  This increases loading time (not by much) but in most
cases will decrease memory usage since you don't have to have a large
XML document loaded at all times and will decrease the time it takes to
access a widget since you will not need to search the widget tree every
time you need to get a refrence to the widget (i.e. all lookup_widget's
are done on startup).

*/
 }

Hope this helps.

--
J5





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