GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Dec 19, 2014 7:15 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GTK Adjustment Question
PostPosted: Sat Apr 06, 2013 6:26 pm 
Offline

Joined: Wed Jan 16, 2013 11:50 pm
Posts: 4
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
Code:
// 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" );

   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);

   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);

   Red_Adj = gtk_adjustment_new (0.0, 0.0, 999.0, 1.0, 1.0, 1.0);
   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);

   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 );

   };


Top
 Profile  
 
 Post subject: Re: GTK Adjustment Question
PostPosted: Sun Apr 07, 2013 11:03 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
It sure doesn't help that you have Red_Adj declared as both a GtkAdjustment* global and a GtkObject* local in Color_Panel()

Also gtk_hscale is depreciated in 3.2 so you might want to move to gtk_scale with the orientation specified.


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

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


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