Re: show/hide widgets
- From: Christopher Leopold <leopold in tum de>
- To: Olexiy Avramchenko <olexiy ctech cn ua>
- Cc: gtk-list gnome org
- Subject: Re: show/hide widgets
- Date: Thu, 14 Oct 2004 10:41:42 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I use the GTK runtime 2.4.9
The codesample is a bit complicated, 'cause it's part of a much bigger
program.
I tried to reduce it down to the interesting parts of the code ...
First comes the beginning point. It's cycle-method is called from
somewhere else once each turn. Beneath comes the intersting part of the
code. There, the label and the slider are created.
******************
GtkWidget* additionalBox;
int Initialize () {
~ // load the init and cycle functions from the subGUI modules with
~ // dlopen
~ // ...
~ // initialize the additional box (so everybody can draw there from
~ // now on)
~ g_type_init();
~ additionalBox = gtk_vbox_new(TRUE, 0);
~ // call the initialize functions of all subGUI modules
~ // ...
~ pictureOrGraph[i] = initializeFunctions[i](checkboxLabel[i]);
~ // initzialze things for the gui thread
~ pthread_t guiThreadID;
~ int* arg;
~ pthread_mutex_init(&drawing, NULL);
~ pthread_create(&guiThreadID, NULL, initGUI, arg);
~ pthread_detach(guiThreadID);
~ return MRC_SUCCESS;
}
int Cycle () {
~ pthread_mutex_lock(&drawing);
~ cycleFunctions[i](picturePixmap, toBeDrawn[i], color, -1);
~ pthread_mutex_unlock(&drawing);
~ return MRC_SUCCESS;
}
/*
~ * The GUI thread
~ */
void* initGUI(void* arg) {
~ int i;
~ GtkWidget* window;
~ GtkWidget* table;
~ //GtkWidget* additionalBox; defined global
~ gtk_init(NULL, NULL);
~ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
~ // click on the X in the upper right corner kills the window
~ // ...
~ // create table with 2x3 fields, not the same size
~ table = gtk_table_new(2, 3, FALSE);
~ gtk_container_add(GTK_CONTAINER(window), table);
~ // add the additional box on top and with the full width
~ gtk_widget_show(additionalBox);
~ gtk_table_attach_defaults(GTK_TABLE(table), additionalBox, 0,2,0,1);
~ gtk_widget_show(table);
~ gtk_widget_show(window);
~ while(showWindow) {
~ pthread_mutex_lock(&drawing);
~ if(showWindow) {
~ gtk_main_iteration_do(FALSE);
~ }
~ pthread_mutex_unlock(&drawing);
~ usleep(10000);
~ }
~ return 0;
}//initGUI
GtkWidget* getAdditionalBox() {
~ return additionalBox;
}
******************
// boxe for the slider and its label
GtkWidget* box;
// adjustment of the slider
GtkObject* timeAdjustment;
int GUI_Initialize(char* label) {
~ // ...
~ // set label and slider
~ box = gtk_hbox_new(FALSE, 0);
~ GtkWidget* sliderLabel = gtk_label_new("Time Slider");
~ gtk_widget_show(sliderLabel);
~ gtk_box_pack_start(GTK_BOX(box), sliderLabel, FALSE, TRUE, 2);
~ timeAdjustment = gtk_adjustment_new(0.0, 0.0, hdf5LogfileSize,
~ (hdf5LogfileSize / 1000.0), (hdf5LogfileSize / 150.0), 0.0);
~ g_signal_connect(G_OBJECT(timeAdjustment), "value_changed",
~ G_CALLBACK(setCycleCount), NULL);
~ GtkWidget* timeSlider =
~ gtk_hscale_new(GTK_ADJUSTMENT(timeAdjustment));
~ gtk_scale_set_draw_value(GTK_SCALE(timeSlider), FALSE);
~ gtk_range_set_update_policy(GTK_RANGE(timeSlider),
~ GTK_UPDATE_DISCONTINUOUS);
~ gtk_widget_show(timeSlider);
~ gtk_box_pack_start(GTK_BOX(box), timeSlider, TRUE, TRUE, 2);
~ //*** I don't want to show the box here ***//
~ gtk_widget_show(box);
~ gtk_box_pack_start(GTK_BOX(getAdditionalBox()), box, TRUE, TRUE, 0);
~ return GUI_PICTURE_WINDOW;
}
void GUI_Cycle(GdkPixmap* pixmap, int toBeDrawn, ....) {
~ if (timeSliderValue + 1 == ++GTK_ADJUSTMENT(timeAdjustment)->value) {
~ gtk_adjustment_value_changed(GTK_ADJUSTMENT(timeAdjustment));
~ }
~ printf("cycleTime %i\n", cycleCount);
~ if (toBeDrawn) {
~ // draw the slider and label
~ if (!boxDrawn) {
~ //*** I want to show the box here ***//
~ //gtk_widget_show_now(box);
~ boxDrawn = 1;
~ }
~ }
~ else {
~ // hide the slider and label
~ if (boxDrawn) {
~ //*** I want to hide the box here ***//
~ //gtk_widget_hide(box);
~ boxDrawn = 0;
~ }
~ }
}
void setCycleCount(GtkAdjustment* adj) {
~ // ...
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBbjvFzt/GDRHk1XARAoMCAJ9DqfQziYr/tH6M8tH3hfmnntd7dQCgnpXC
zI7YZih6Bb+w8iWt2z8jJlw=
=I1oc
-----END PGP SIGNATURE-----
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]