Click to See Complete Forum and Search --> : dynamic GTK+ programming
tecknophreak
03-05-2003, 06:04 PM
howdy,
i'm trying to find some ways to do some dynamic programming in GTK+. I can change the data in text fields without a problem.
the problem i'm coming across is trying to "redraw" a vbox or hbox. say i have a window with two buttons in a vbox. when i click on the top one, the vbox will then have 3 buttons in it. would i have to use the canvas or can i do it somehow, all tricky-like?
tecknophreak
03-05-2003, 06:31 PM
by using
gtk_container_remove(GtkContainer *, GtkWidget *)
to remove the widgets in the box, then putting new info in.
megadave
03-05-2003, 11:45 PM
I'm a little lost on what u mean by dynamic programming. I assume u mean the screen updating when u make a change?
Apparently according to what I read, widgets are intelligent, ie the KNOW when to update themselves on teh screen.
Oh and don't forget about gtk_widget_show();
If u launch into a bunch of processing after a button press and u're app is not mutli-threaded,
the line while(g_main_iteration(FALSE));
is your friend. Just pop it in u're loop, and
it'll run any events that are qued up to be redrawn by Gtk+/Gnome.
That way u avoid the "screen freeze" while
your off calculating pi to 5^10000 digits.
Dave
[EDIT]
I think I just figured out what u meant.
U packed another button into a vbox, and it didn't show?
Oh, and if my suggestions didn't help, post
the code :)
tecknophreak
03-06-2003, 09:24 AM
looks like you got what i was saying. the topic should actually programming dynamic windows in GTK+.
Anyway, here's what i did:
Setup:
button1 = gtk_button_new_with_label("button1");
button2 = gtk_button_new_with_label("button2");
g_signal_connect(G_OBJECT(button1), "clicked",
G_CALLBACK(redraw), (gpointer)"button1");
gtk_box_pack_start(GTK_BOX(dynamicHBox), button1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(dynamicHBox), button2, TRUE, TRUE, 0);
And the Change:
static void redraw(GtkWidget *widget, gpointer data) {
gtk_container_remove((GtkContainer *)dynamicHBox, button2);
button2 = gtk_button_new_with_label("button3");
gtk_box_pack_start(GTK_BOX(dynamicHBox), button2, TRUE, TRUE, 0);
gtk_widget_show_all(window);
}
of course there's more to it, it'd just take up too much room. thanks for the reply, it might come in handy later!