GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Nov 24, 2014 1:54 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Gtk+ text
PostPosted: Wed Mar 21, 2007 10:31 am 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
Hi,

I am new to Gtk + programming. I created a text window with some buttons. When I click on the button I call a function which generates an output. I want to display this output in my textwindow but my program always displays on the command line(terminal) of my Linux window. How can I divert my output to text window. Any hints would be great.

thanks,

bluezapper.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 1:05 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
If you are using something like g_print, g_message, etc, then it will always be sent to the terminal. What are you using to output messages? If you want to display a message in a dialog, you will want to use the GtkMessageDialog widget.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: using g_print
PostPosted: Wed Mar 21, 2007 1:24 pm 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
Hi Andrew,

thanks for the reply. I am using g_print to output messages. I want to direct these messages to my Text window. It is a not a dialog window.

any hints would be great

thanks

bluezapper


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 1:33 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
I'm sorry I can't give you an answer immediately, but I don't quite understand what you are saying. Are you saying that you have a GtkLabel widget in your main window that you want to display messages in? If that is the case, you should just use gtk_label_set_text(). I will be able to help you if you let me know what widget you want to display the messages in.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:19 pm 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
Hi Andrew,

Apologies for not elaborating completely.

I am creating a text window in the following way and I want to display the output of my function in this text window

Code:
GtkWidget *textwindow;
   
   GtkWidget *heading;
   
   GtkWidget *textinput;
   
   textwindow=gtk_vbox_new(FALSE,0);
   
   heading=gtk_label_new("Output");
   
   gtk_box_pack_start(GTK_BOX(textwindow),heading,FALSE,FALSE,0);
   
   gtk_widget_show(heading);
   
   textinput=gtk_text_new(NULL, NULL);   
      gtk_box_pack_start(GTK_BOX(textwindow),textinput,FALSE,FALSE,0);
   
   gtk_widget_show(textinput);


I hope this helps,

regards,

bluezapper


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:31 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Ok, there's a few things that I would like to point out. First, the GtkText widget is depreciated and should _never_ be used in a new program. Instead, use the GtkTextView widget.

With that said, the following code created a GtkTextView widget and appends text to it. It is added to a GtkScrolledWindow widget so that it will not resize when text goes beyond the bounds of the text view. (Also, I did not text this code, so you might have to fix a syntax error or two):

Code:
GtkWidget *textview, *swin;
GtkTextBuffer *buffer;
GtkTextIter iter;

/* Create a GtkScrolledWindow and only show scrollbars if necessary. */
swin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

/* Create a new text view widget. */
textview = gtk_text_view_new ();

/* Retrieve the buffer that was created for the text view. */
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));

/* Retrieve the last position in the buffer. */
gtk_text_buffer_get_end_iter (buffer, &iter);

/* Append the text to the end of the text buffer. */
gtk_text_buffer_insert (buffer, &iter, "Message", -1);

/* Add the text view as the scrolled window's child. */
gtk_container_add (GTK_CONTAINER (swin), textview);


You should send the text view widget to any function that needs to output data. Then, you can retrieve the buffer and follow the procedure above to insert text at the end. You can use the \n character to insert a new line.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: thank you
PostPosted: Wed Mar 21, 2007 2:53 pm 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
thanks Andrew, that was helpful.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:59 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Two other things that I just thought of. You should look into making the GtkTextView text non-editable if you are just outputting messages. Also, GtkTextView is fine, but most people use GtkTreeView for message output. You might want to check out that widget.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: new line insertion
PostPosted: Wed Mar 28, 2007 4:09 pm 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
Hi,

I am using an older version of GTK+ as my compiler does not recognize

"gtk_text_view_new ();"

also how do I insert a new line between text inserted in my textwindow. Following does not work for me:

Following command is inserted in a for loop

gtk_text_insert (GTK_TEXT (textinput), NULL, NULL,
NULL,("%s \n",baddr), -1);

The whole text comes in the same line.

any hints would be great

thanks

bluezapper


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 6:54 pm 
Offline
Familiar Face

Joined: Wed Mar 14, 2007 9:02 am
Posts: 9
I solved the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group