Re: Gtk Refresh Problem



Bharat Bhushan wrote:
> 
> Hey Diego,
>          Thanks for the suggestion. it worked to some extent. Now I dont
> get any error or warning but my GUI freezes now. I display a message box
> in my program and I have put the code for GUI is in a separate thread.
> I do something like this in the thread function:
ARGH! That's obvious! You have to GDK_THREADS_ENTER()/LEAVE() multiple
times!
I hope leaving and reentering around gtk_dialog_run() is enough. But IMO
you're taking the wrong approach to event-driven programming: you're
trying to write a sequential program...

> gdk_threads_enter();
This one is too early! Move it down after var decl.
> GtkWidget *dialog;
> gint result = 0;
> 
> dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
> GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "No new hard drive was found.
> Please check cable connections and jumper setting on the hard drive. Check
> out Hardware Guide for details.\n");
> 
>   gtk_dialog_add_buttons(GTK_DIALOG(dialog), "View Hardware Guide",
> GTK_RESPONSE_HGUIDE, NULL);
>   gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_OK,
> GTK_RESPONSE_ACCEPT,
> NULL);
> 
>   /*-- Display the widgets --*/
>   gtk_widget_show_all(dialog);
gdk_threads_leave();
>   result = gtk_dialog_run (GTK_DIALOG (dialog));
gdk_threads_enter();
>   switch (result)
>     {
>       case GTK_RESPONSE_ACCEPT:
>          printf("OK BUTTON PRESSED\n");
>          gtk_widget_destroy(dialog);
>          break;
>       case GTK_RESPONSE_HGUIDE:
>          printf("HGUIDE BUTTON PRESSED\n");
>          gtk_widget_destroy(dialog);
>          break;
>       default:
>          printf("WINDOW WAS KILLED\n");
>          gtk_widget_destroy(dialog);
>          break;
>     }
>   gdk_threads_leave();
> 
> And I never see the result of clicking any button. The program seems to
> freeze after showing the message box.
> Can you suggest anything?
It could be better to have a callback for every button in the dialog,
then just display it. The following switch() is unnecessary, since the
proper "case" is handled by the callback. You could even write a single
callback function, connecting it with different data. It's better if you
read some source code from a not-so-trivial program.

BYtE,
 Diego.



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