GTK Question



Gentle People:

The function Color_Panel is called from a higher level GTK application.
The following Slider Bar Example works properly on the screen!
But how do I get the value of the adjustment out to drive the application?
I have spent several hours searching the internet for examples.
From the internet examples it seems that the approach below is correct?
But I do not seem to be able to extract the value of the double Red.
Several attempts are shown at the bottom!

Error Messages:
"Assertion Failed"
"Segmentation Fault"

Thanks For The Help.
Thomas Dineen

// Declared as global outside of Main.c

// GtkObject *Red_Adj;
GtkAdjustment *Red_Adj;

int Color_Panel ( )
   { /* Start Color_Panel */
   GtkWidget *vbox_top_main;
   GtkWidget *hbox_top0;
   GtkWidget *hbox_top1;
   GtkWidget *hbox_top2;

   GtkObject *Red_Adj;
   GtkWidget *hscale;

   GtkWidget *Button_Sel;

   GdkColor color;
   double Red;
   double Green;
   double Blue;

   printf ( "Running Color_Panel\n" );

/******************************************************************************/
/* */
/* Set Up The Top Level Window */
/* */
/******************************************************************************/

   CP_Window = gtk_window_new( GTK_WINDOW_TOPLEVEL );

   gtk_window_set_position( GTK_WINDOW(CP_Window), GTK_WIN_POS_MOUSE );

   gtk_window_set_default_size( GTK_WINDOW(CP_Window), 400, 585 );
   /* Width:Height*/

   gtk_window_set_title( GTK_WINDOW(CP_Window),
      "Adjust The Sliders To Select A Color" );

   vbox_top_main = gtk_vbox_new (FALSE, 0);
gtk_widget_set_size_request ( vbox_top_main, 400, 555 ); /* Width : Height */
   gtk_container_set_border_width (GTK_CONTAINER (vbox_top_main), 1 );
   gtk_container_add (GTK_CONTAINER (CP_Window), vbox_top_main);

/******************************************************************************/
/* */
/* Set Up The Horozontal Boxes */
/* */
/******************************************************************************/

   hbox_top0 = gtk_hbox_new (FALSE, 0);
   gtk_widget_set_size_request (hbox_top0, 35, 35 ); /* Width : Height */
   gtk_container_set_border_width (GTK_CONTAINER (hbox_top0), 1 );
   gtk_container_add (GTK_CONTAINER (vbox_top_main), hbox_top0);

   hbox_top1 = gtk_hbox_new (FALSE, 0);
   gtk_widget_set_size_request (hbox_top1, 35, 35 ); /* Width : Height */
   gtk_container_set_border_width (GTK_CONTAINER (hbox_top1), 1 );
   gtk_container_add (GTK_CONTAINER (vbox_top_main), hbox_top1);

   hbox_top2 = gtk_hbox_new (FALSE, 0);
   gtk_widget_set_size_request (hbox_top2, 35, 35 ); /* Width : Height */
   gtk_container_set_border_width (GTK_CONTAINER (hbox_top2), 1 );
   gtk_container_add (GTK_CONTAINER (vbox_top_main), hbox_top2);

/******************************************************************************/
/* */
/* Set Up The Red Scale: */
/* */
/******************************************************************************/

/* value, lower, upper, step_increment, page_increment, page_size */ /* Note that the page_size value only makes a difference for */ /* scrollbar widgets, and the highest value you'll get is actually */ /* (upper - page_size). */

   Red_Adj = gtk_adjustment_new (0.0, 0.0, 999.0, 1.0, 1.0, 1.0);
// g_signal_connect (Red_Adj, "value_changed",
//                    G_CALLBACK (Func_Red_Scale_Change), NULL);

   hscale = gtk_hscale_new (GTK_ADJUSTMENT (Red_Adj));
   gtk_widget_set_size_request (GTK_WIDGET (hscale), 200, -1);

   gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
   gtk_scale_set_digits (hscale, 1);
   gtk_scale_set_value_pos (hscale, GTK_POS_TOP);
   gtk_scale_set_draw_value (hscale, TRUE);

   gtk_box_pack_start (GTK_BOX (hbox_top0), hscale, TRUE, TRUE, 0);
   gtk_widget_show (hscale);

/******************************************************************************/
/* */
/* Create And Process Button Exit */
/* */
/******************************************************************************/

   Button_Sel = gtk_button_new_with_label ("Select Color And Exit");
gtk_widget_set_size_request(GTK_WIDGET(Button_Sel),25,25); /* Width:Height*/
   g_signal_connect (Button_Sel, "clicked",
                      G_CALLBACK (Button_Sel_Color_Func), NULL);
   gtk_box_pack_start (GTK_BOX(hbox_top2), Button_Sel, TRUE, TRUE, 0);

   gtk_widget_show (hbox_top0);
   gtk_widget_show (hbox_top1);
   gtk_widget_show (hbox_top2);
   gtk_widget_show (vbox_top_main);
   gtk_widget_show_all( CP_Window );

   printf ( "Finished Color_Panel\n" );

   } /* End Color_Panel */

void Func_Red_Scale_Change ( )
   {
// if ( Print_Head->Print_Headers_Event == TRUE )
      g_print ( "Menu: Func_Red_Scale_Change\n" );
   };

Button_Sel_Color_Func( )
   {
   gdouble Red;

// if ( Print_Head->Print_Headers_Event == TRUE )
      g_print ( "Menu: Func_Red_Scale_Change\n" );

// None Of These Worked!
// Red = gtk_adjustment_get_value ( GTK_ADJUSTMENT (Red_Adj) );
// Red = gtk_adjustment_get_value ( Red_Adj );
// Red = GTK_ADJUSTMENT((Red_Adj)->value);

// if ( Print_Head->Print_Headers_Event == TRUE )
      g_print ( "Red = %f\n", Red );

   };



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