Re: Please, help me.



This list is for discussion of development *of* gtk+, not for discussion of development of applications using gtk+. Please use gtk- app-devel-list in the future.


On Jan 11, 2006, at 3:29 AM, Cool Guy wrote:

[code doing

   create file selection
   set up EmptyCallBack to be called after ok_button is clicked
   set up gtk_widget_destroy to be called when ok_button is clicked
   set up gtk_widget_destroy to be called when cancel_button is clicked
   if a handler is connected to ok_button
      print something
   immediately call ExtractFilePath
]

I don't know why "g_singal_handler_is_connected()" is performed before
"GTK_FILE_SELECTION(temp)->ok_button" is clicked.

What is the problems at g_signal_handler_is_connnected()?

Because the g_signal_connect_* set up functions to be called when something happens, rather than "right now". A signal connection essentially defers a function call until some later time. Notice that in your code the user doesn't actually click the button until long after this code has run, so it doesn't do anything useful.

Also, you are destroying the widget in a normal signal handler, which runs before the default action, and attempting to use the widget in an "after" signal handler, which runs after the default handler.

You're making it harder than it needs to be by trying to connect to the buttons directly. GtkFileSelection derives from GtkDialog, which provides a nice interface for running dialogs based on response codes, so that you don't have to do that sort of thing.


I want to run "ExtractFilePath()" when clicked ok_button.

Using code like this will make your life easier, but will not solve your issues with signal connections:

void
do_something ()
{
GtkWidget * file_selection = gtk_file_selection_new ("Choose a file");
   /*
* gtk_dialog_run() will interact with the user and return a response code * depending on what button the user clicked in the window. The only one * we're actually interested in is "ok", because for all other responses * we just dismiss. For "ok", we get and attempt to use the filename. * This is done in a loop so that if the filename was no good (for example,
    * the user chose an unreadable file) we can ask again.
    */
while (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (file_selection))) {
       gchar * filename;
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selection));
       if (do_something_with_filename (filename)) {
          /* filename was good, we can stop */
          break;
       }
   }
   /* finished */
   gtk_widget_destroy (file_selection);
}


Please read and understand the tutorial, http://www.gtk.org/ tutorial/ , which should help you get a better idea of how to use signals and callbacks.


--
muppet <scott at asofyet dot org>




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