Threads on gtk



Hi all

I'm testing an gtk application. It is run from another application non gtk. I want to that gtk application be a thread of the non gtk application. I tried with conventional c pthread but gtk show me several warnings like this:

GLib-WARNING **: g_main_iterate(): main loop already active in another thread

I have several doubts about gtk main loop functionality.

1) If I call my gtk application x times as a thread, shouldn't it be opened x times like threads?
2) How can I run my gtk application  as  a thread of my non gtk application?
3) Any help? any idea?

Note: my gtk application is a function of my non gtk application. It's initilized without any arguments

I call my gtk application in this way:

pthread_create(&thread_init, NULL, Init_Gtk, (void *) data);

and my gtk apllication is here:

//-----------------------------------------------------------------------------
// Init_Gtk
//-----------------------------------------------------------------------------
void *Init_Gtk(void * data)
{
   GtkWidget *window;

   char * ch_text = (char*) data;
gtk_init (NULL, NULL);

       window = Create_Ch_Label (ch_text);

       gtk_timeout_add (3000,(GtkFunction) Destroy_Ch_Label, window);


   gtk_main();
}

//------------------------------------------------------------------------------
// Create_Ch_Label : //------------------------------------------------------------------------------
GtkWidget *Create_Ch_Label( char * label_text)
{
   GtkWidget *window;
   GtkWidget *label;

   gtk_rc_parse("style");

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

   label = gtk_label_new (label_text);

   gtk_widget_set_name(label, "mylabel");

   gtk_widget_show(label);

   gtk_container_add (GTK_CONTAINER (window), label);

   gtk_widget_set_usize( window, 200, 20);
   gtk_widget_set_uposition ( window, 550, 61);

   gtk_widget_show (label);
   gtk_widget_show_all (window);
return (window);
}
//-----------------------------------------------------------------------------
// Destroy_Ch_Label
//-----------------------------------------------------------------------------
gint Destroy_Ch_Label (GtkWidget *window)
{
   gtk_widget_destroy (window);
   gtk_main_quit();

return FALSE;
}


Thanks a lot and regards

Ariel Fritz








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