GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Gtk+ text

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 21, 2007 10:31 am    Post subject: Gtk+ text Reply with quote

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 372
Location: State College, Pennsylvania

PostPosted: Wed Mar 21, 2007 1:05 pm    Post subject: Reply with quote

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.
Back to top
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 21, 2007 1:24 pm    Post subject: using g_print Reply with quote

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
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 372
Location: State College, Pennsylvania

PostPosted: Wed Mar 21, 2007 1:33 pm    Post subject: Reply with quote

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.
Back to top
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 21, 2007 2:19 pm    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 372
Location: State College, Pennsylvania

PostPosted: Wed Mar 21, 2007 2:31 pm    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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.
Back to top
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 21, 2007 2:53 pm    Post subject: thank you Reply with quote

thanks Andrew, that was helpful.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 372
Location: State College, Pennsylvania

PostPosted: Wed Mar 21, 2007 2:59 pm    Post subject: Reply with quote

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.
Back to top
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 28, 2007 4:09 pm    Post subject: new line insertion Reply with quote

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
Back to top
bluezapper
Familiar Face


Joined: 14 Mar 2007
Posts: 9

PostPosted: Wed Mar 28, 2007 6:54 pm    Post subject: Reply with quote

I solved the problem.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP