GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Nov 25, 2014 11:09 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Passing Structure Of Widgets Problem
PostPosted: Tue Jan 08, 2008 7:56 pm 
Offline
Familiar Face

Joined: Tue Jan 08, 2008 7:39 pm
Posts: 9
Hello,

I am having an issue with passing widgets to callback functions.

What I am trying to do is pass two widgets with one callback. One widget is a combo box and one is a status bar.

I prefer not to use global variables, so I figured my only way would be to create a structure and pass the structure.

I've tried this and it failed to work.

My structure look as such:

Code:
typedef struct status_and_widget {
   GtkWidget *widget;
   GtkWidget *status_bar;
} status_trans;


My declarations look like this in main:

Code:
GtkWidget *status_bar;
GtkWidget *combo_nearby_dev;

...

status_trans status_and_combo;
status_and_combo.widget = combo_nearby_dev;
status_and_combo.status_bar = status_bar;
g_signal_connect (G_OBJECT (button_nearby_dev), "clicked", G_CALLBACK (button_nearby_dev_callback), (gpointer)&status_and_combo);

...



And finally, my callback function:

Code:
static void button_nearby_dev_callback( GtkWidget *widget, gpointer data ) {
   status_trans *status_and_combo = (status_trans*)data;
   
   GList *list;
   bt_node *head;
   list = NULL;
   head = NULL;

   gtk_statusbar_push(GTK_STATUSBAR(status_and_combo->status_bar), 1, "Updating. Please Wait.");

    /* Fills Combo Box */
   bt_populate_list(&head);
   list = g_list_append (list, "John");

   /* Adds list to combo box */
   gtk_combo_set_popdown_strings(GTK_COMBO(status_and_combo->widget), list);    
   
   gtk_statusbar_pop(GTK_STATUSBAR(status_and_combo->status_bar), 1);
}


It does update the combo box, but does not do anything for the status_bar.

Also, the bt_populate_list() function searches for local bluetooth devices which takes some time. So I don't believe that I'm not seeing it due to it being too quick but I'm not positive.

Any help would be appreciated.

Thanks
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 9:24 pm 
Offline
Familiar Face

Joined: Tue Dec 11, 2007 11:03 pm
Posts: 11
Location: Burleson, TX
Right after your gtk_statusbar_push() you can run

gtk_main_iteration();

to iterate through the main loop one time and process the push message.

The event is not being fired until after your event ends (I think).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:08 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
as mentioned...

while (gtk_events_pending()) gtk_main_iteration();

will update the GUI with pending events before proceeding which would insure that the status bar message is shown before moving on.

Sometimes stepping through the code can help with this type of issue. Compile with the -g flag and then using gdb, you can simply do:

gdb myprogram

which will load your program into gdb. Then enter: "b button_nearby_dev_callback" to put a breakpoint in the callback and then type "r" to run the app. When you click the button, it will pause at the beginning of your callback function. Press "n" to step through each call. I'll bet that after the gtk_statusbar_push() call the GUI still won't reflect this change. Keep typing "n" to keep stepping to the next line of code.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 4:39 am 
Offline
Familiar Face

Joined: Tue Jan 08, 2008 7:39 pm
Posts: 9
Would I need to update after the pop as well? It works without it, but I was wondering why.

The only thing I could think of is that since it is going back to main it would update it.

Thanks for all of the help.

Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 3:17 pm 
Offline
Familiar Face

Joined: Tue Dec 11, 2007 11:03 pm
Posts: 11
Location: Burleson, TX
You shouldn't have to call it again after the pop; the bt_list process is blocking the events from being fired, therefore, you are getting a push() and pop() event after your callback completes. So after your event finishes the pop message is fired successfully.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group