Why doesn't my label show up in the window
When I click the button the subwindow shows up but the label is missing in action. I thought that this line --> while (g_main_context_iteration(NULL, FALSE)); would make both the subwindow and the label show up without having to re-visit gtk_main(), but obviously that's not the case. Unsurprisingly the window doesn't show up at all without that line but what happened to the label? -- MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER! #include #include void subroutine(GtkWidget *button, gpointer data); int main( int argc, char *argv[]) { GtkWidget *window, *button; gtk_init(&argc, &argv); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); button=gtk_button_new_from_stock(GTK_STOCK_OK); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(subroutine), NULL); gtk_container_add(GTK_CONTAINER(window),button); gtk_widget_show_all(window); gtk_main(); return 0; } void subroutine(GtkWidget *button, gpointer data) { GtkWidget *subwindow, *label; subwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(subwindow), 400, 50); label=gtk_label_new("Label"); gtk_container_add(GTK_CONTAINER(subwindow),label); gtk_widget_show_all(subwindow); while (g_main_context_iteration(NULL, FALSE)); sleep(5); gtk_widget_destroy(subwindow); return; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Why doesn't my label show up in the window
You call sleep() in mainloop causes it block, you can use g_timeout_*() functions to create event in mainloop in timely manner. Below I modify your code to implement g_timeout_*() functions. Note, you must care with subwindow creation, user may still create the subwindow (by clicking the OK button) although the subwindow is still displayed. gboolean destroy_subwindow(GtkWidget *subwindow) { gtk_widget_destroy(subwindow); return FALSE; } void subroutine(GtkWidget *button, gpointer data) { GtkWidget *subwindow, *label; subwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(subwindow), 400, 50); label=gtk_label_new("Label"); gtk_container_add(GTK_CONTAINER(subwindow),label); gtk_widget_show_all(subwindow); g_timeout_add (5000, (GSourceFunc) destroy_subwindow, subwindow); /* while (g_main_context_iteration(NULL, FALSE)); */ /* sleep(5); */ /* gtk_widget_destroy(subwindow); */ return; } Regards On Sat, Aug 25, 2012 at 3:41 PM, Frank Cox wrote: > When I click the button the subwindow shows up but the label is missing in > action. > > I thought that this line --> while (g_main_context_iteration(NULL, FALSE)); > > would make both the subwindow and the label show up without having to re-visit > gtk_main(), but obviously that's not the case. Unsurprisingly the window > doesn't show up at all without that line but what happened to the label? > > -- > MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com > www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER! > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Why doesn't my label show up in the window
On Sat, 25 Aug 2012 16:49:14 +0800 Ardhan Madras wrote: > You call sleep() in mainloop causes it block, you can use > g_timeout_*() functions to create event in mainloop in timely manner. > Below I modify your code to implement g_timeout_*() functions. So the sleep() causes the g_main_context_iteration function to stop before it completes its operation? The example I posted isn't actually what I'm doing, but it is (was?) the simplest way to demonstrate it. The real objective is to bring up a subwindow with status reports in the form of a label that updates at intervals as a function runs without returning to gtk_main() until completion. So I create the subwindow, create a label and add it to the subwindow, do task x, update the label, do task y, destroy the subwindow and return to gtk_main(). What I have discovered is that the subwindow appears as expected prior to starting task x, but the label is missing (the subwindow is blank) until it updates at the start of task y. 1. Create subwindow, create label "Talking to John", gtk_show_all (subwindow). subwindow shows up with no text. 2. Talk to John. 3. Update label "Now talking to Mary". Text shows up in the subwindow as expected, "Now talking to Mary" 4. Talk to Mary. 5. Destroy subwindow. I never get told that we're talking John, even though John does get talked to. http://developer.gnome.org/gtk-faq/stable/x601.html That webpage appears to say that nothing gtk-related will normally be executed until the program gets back to gtk_main(), and I can get around this by putting a "while (g_main_context_iteration (NULL, FALSE));" into my code at the point that I want to run the pending gtk-related stuff (like updating my label). But it doesn't work so my understanding of what's going on here is either incomplete or wrong. I guess my question comes down to how can I process everything from within a function that would normally get processed by returning to gtk_main(), without having to actually return to gtk_main()? "Go and update everything, then come right back here and continue this job". -- MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Why doesn't my label show up in the window
On Sat, 25 Aug 2012 11:35:27 -0600 Frank Cox wrote: The more I look at this the less I understand it. > What I have discovered is that the subwindow appears as expected prior to > starting task x, but the label is missing (the subwindow is blank) until it > updates at the start of task y. Playing around with this a bit more just now, I have discovered that the behaviour of my demonstration program that I posted last night is inconsistent. I'm pretty sure that it didn't show the label at all last night when I wrote it, but today when I ran it again I get the label in the window the first time I click the OK button but when I click it again (after the subwindow goes away) all I get it a blank subwindow that's missing the label. So what changes between the first click and the second click that causes the label to work and then not work? And now that I've spent two minutes writing this email, I went back and ran the program again and now I'm back to the original behaviour: No label on the first click or the second or subsequent click. I just noticed that the OK button in the main window also disappears when I click on it, and it doesn't re-appear until the sleep() times out, as well. Reading about "while (g_main_context_iteration (NULL, FALSE));" seems to indicate that it does in fact do exactly what I thought it did, and what I want it to do. You stated "You call sleep() in mainloop causes it block,". Could you go into more detail about this, since I think that's where my understanding of this is going off the track. Is it blocked prior to completing the "while (g_main_context_iteration (NULL, FALSE));"? If so, why? If the "while (g_main_context_iteration (NULL, FALSE));" did in fact complete before the sleep () command, then why is the label not being consistently drawn? And for that matter, why is the window itself showing up? Adding another "while (g_main_context_iteration (NULL, FALSE));" immediately after "gtk_container_add(GTK_CONTAINER(subwindow),label);" didn't make any difference in the behaviour; the label still didn't show up as it should. If "while (g_main_context_iteration (NULL, FALSE));" does what I think it does, then this should work. Since it doesn't, it's obvious that it doesn't actually do what I think it does. And since it does occasionally work on the first click, but not always and less than half of the time, why? What changes between runs? The only thing that I can think of is some kind of a timing issue, but why would that matter in a (supposedly) self-contained program that's not looking for external input other than a click? -- MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
button background color in gtk3
Friends, I am putting gtkbuttons inside a grid with modify_bg. I am getting an odd case that when the window is focused, all buttons are showing white, not what suggested by modify_bg. The same structure was working fine in gtk2 (while I was using table instead of grid). I am posting the complete minimal code(60 line only) for your reference. I have seen that the gtk_widget_modify_bg is deprecated in gtk 3 so I tried the suggested method with gtk_widget_override_background_color but there it seems that declaration of GdkColor colorRed2 = {0x, 65535, 29555, 24158} has changed to something like GdkRGBA. I tried to change to GdkRGBA colorRed = {1,0,0,1}; yeilding error: ‘const struct GdkRGBA *’ but argument is of type ‘GdkRGBA’ Please Help. here is the complete code: #include int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *grid; GtkWidget *menubar; GtkWidget *filemenu; GtkWidget *quit; GtkAccelGroup *accel_group = NULL; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Try Grid"); gtk_container_set_border_width(GTK_CONTAINER(window), 05); grid = gtk_grid_new(); gtk_container_add(GTK_CONTAINER(window), grid); gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE); menubar = gtk_menu_bar_new(); filemenu = gtk_menu_new(); accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File"); quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit); gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file); g_signal_connect(G_OBJECT(quit), "activate", G_CALLBACK(gtk_main_quit), NULL); gtk_grid_attach(GTK_GRID(grid), menubar, 0, 0, 2, 1); /* Color Scheme */ GdkColor colorRed2 = {0x, 65535, 29555, 24158}; GdkColor colorBlue = {0x, 3598, 57054, 61937}; GdkColor colorWht = {0x, 65535, 65535, 65535}; GtkWidget *Abutton = gtk_button_new_with_label("A"); gtk_grid_attach(GTK_GRID(grid), Abutton, 0, 1, 1, 1); gtk_widget_modify_bg(Abutton, GTK_STATE_NORMAL, &colorBlue); gtk_widget_modify_bg(Abutton, GTK_STATE_PRELIGHT, &colorWht); /* Create second button */ GtkWidget *Bbutton = gtk_button_new_with_label("B"); gtk_grid_attach(GTK_GRID(grid), Bbutton, 10, 1, 1, 1); gtk_widget_modify_bg(Bbutton, GTK_STATE_NORMAL, &colorRed2); gtk_widget_modify_bg(Bbutton, GTK_STATE_PRELIGHT, &colorWht); gtk_widget_show_all(window); gtk_main(); return 0; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Why doesn't my label show up in the window
On Sat, 25 Aug 2012 16:18:20 -0600 Frank Cox wrote: I have modified my little test program so it will provide a visual cue for each pending event. I have attached the modification. I get three pending events every time I press the OK button. The subwindow always appears. The label sometimes appears on the first button press, but never on any subsequent button press. But in all cases, there are three pending events, never more and never less, regardless of whether the label appears or not. What is going on here? I have also been experimenting with a progress bar and have a similar situation. It only updates the bar length to 100% after the entire job is over, interim updates never show up and the bar stays at zero, but interestingly enough text superimposed on the bar with gtk_progress_bar_set_text() shows up as it should be. So I get the text updated but not the bar length. Which bothers me because, again, I would think I should get either both the bar length and the text updated, or neither. I have read up on the use of timeouts as suggested by Ardhan Madras and while it appears to be an approach that could be made to work in my situation, I don't see why it should be necessary to work off of a timer when I'm just counting records. -- MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER! #include #include void subroutine(GtkWidget *button, gpointer data); int main( int argc, char *argv[]) { GtkWidget *window, *button; gtk_init(&argc, &argv); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); button=gtk_button_new_from_stock(GTK_STOCK_OK); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(subroutine), NULL); gtk_container_add(GTK_CONTAINER(window),button); gtk_widget_show_all(window); gtk_main(); return 0; } void subroutine(GtkWidget *button, gpointer data) { GtkWidget *subwindow, *label; subwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(subwindow), 400, 50); label=gtk_label_new("Label"); gtk_container_add(GTK_CONTAINER(subwindow),label); gtk_widget_show_all(subwindow); //while (g_main_context_iteration(NULL, FALSE)); while (gtk_events_pending ()) { g_print("Yahoo!"); gtk_main_iteration (); } sleep(5); gtk_widget_destroy(subwindow); return; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list