GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Apr 19, 2014 7:19 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to re-paint GTK component??
PostPosted: Fri Dec 11, 2009 9:15 am 
Offline

Joined: Mon Nov 30, 2009 4:11 am
Posts: 3
I am using GTK with c++. It is a client-server socket communication. The server sends some messages (char* data) and client displays it in a GTK_ENTRY. I am using API gtk_entry_set_text (GTK_ENTRY (entry), bufer).
As soon as the client receives the message it directly invokes the method gtk_entry_set_text (GTK_ENTRY (entry), bufer) to display. But my problem is that the GtkWindow is not updated immediately. I need to move the cursor (any mouse event) any where in the GtkWindow then it gets updated and displays the message. Is there any re-paint kind of API which can immediately update the GtkWindow??

I also tried by using following thread_enter and thread_leave API. It aslo did not work.

gdk_threads_enter();
gtk_entry_set_text(GTK_ENTRY(entry),bufer);
gdk_flush();
gdk_threads_leave();


Can anybody tell me what should i do??

-Jagadish


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 9:29 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums.

gtk_entry_set_text() function will trigger proper repaints by itself. There must be some other code that is interfering with GTK+'s normal operation. And when it comes to threads, it's quite easy to shoot yourself in the foot.

You'll need to post some code to get more help and give a general design of your application (what is running in which thread, how threads communicate, ...).

Tadej


Top
 Profile  
 
 Post subject: Re
PostPosted: Fri Dec 11, 2009 1:41 pm 
Offline

Joined: Mon Nov 30, 2009 4:11 am
Posts: 3
Hi,
Thanx for your reply.

My code snipet is given below-

void GUIClass::updateMessage(const char * msg)
{
_updateMessageDisplay(entry, msg);
}

void GUIClass::_updateMessageDisplay(GtkWidget * widget, const char * messageToDisplay)
{
cout<<"\nTrying to update: "<<messageToDisplay<<endl;
gtk_widget_set_sensitive(widget, true);
gtk_entry_set_text(GTK_ENTRY(widget),messageToDisplay);
gtk_widget_set_sensitive(widget, false);
}

My client node class is running in a posix thread. Whenever the client node receives any message to display it immediately invokes the method as-

guiClassInst->updateMessage(message);

The trace "Trying to update" gets displayed along with the message at proper time whenever the node receives. But the GTK_ENTRY is updated only when i move the mouse. Same problem i am facing in following -

gtk_widget_show(widget);
gtk_label_set_text(gtklabel,"LABEL");

These also need mouse movement to be updated...


-Jagadish Buragohain


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 1:58 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

Did you initialize threading system of GTK+ correctly? Do you obtain and release global GDK lock when appropriate? I would advice you to use GTK+ from single thread and use g_idle_add() to queue any other GUI intervention.

I wrote a blog post some time ago about threading in GTK+ application, which you may find interesting: http://tadeboro.blogspot.com/2009/06/multi-threaded-gtk-applications.html.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 2:50 pm 
Offline

Joined: Mon Nov 30, 2009 4:11 am
Posts: 3
Hi,
I tried using-
if( ! g_thread_supported() )
g_thread_init( NULL );
gdk_threads_init();
gdk_threads_enter();

But I got : undefined reference to `g_thread_init'

I have included following headers-
#include <gtk/gtk.h>
#include <gtk/gtkwindow.h>
#include <glib.h>

in the compile time i used gthread-2.0 also

Do i need to include some other lib or header??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 11, 2009 3:03 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

To get thread system working properly, you only need to include gtk/gtk.h file. All other header files will be included for you. BTW, including gtk/gtkwindow.h is deprecated, since single includes should not be used.

When it comes to compiling and linking, just make sure gthread-2.0 is listed on pkg-config cmd line and you should be good.

What OS are you using and whet version of GTK+?

Tadej


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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