GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Sep 20, 2014 7:55 am

All times are UTC




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Four hscale widgets waiting for labels.
PostPosted: Fri Mar 02, 2012 6:31 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
I'm all done but adding in the "gender" code. [x] checkbox. so far I have four horizontal hscale bars and a means of printing the input via fprintf; but I have tried everything I can thing of to label the four bar and no-joy. I figured it would be a simple matter of doing something like this:

Code:
label = gtk_label_new("Pitch")
gtk_box_pack_start(.........)
gtk_widget_show(label);

For each label. It isn't that simple. nothing i've tried over more than three hours has worked. Any ideas? i'd like the strings to read 1.: "Pitch", 2) "Volume, 3) Speed WPM", and 4, "Delay"

I'll see if I can attach me src. Ii'd be very much obliged to learn what I've been doing Wrong!

tia, gary


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Fri Mar 02, 2012 8:08 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Hi Gary,

What you are doing sounds about right, you may just be doing it in the wrong order that may be all.

You may also want to consider using a GtkFrame. These are containers so you can add your GtkHScale to it, but it also can take a title which is what you want and can have a decorative frame around it which I would advise against using.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Fri Mar 02, 2012 8:36 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
when i try adding a frame, everything disappears. the frame evidently covers up my hscale widgets.

{i tried to enclose my src code, but dont see it .


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Fri Mar 02, 2012 9:14 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
postind src code directly
Code:
// {uncomments to get scrollbars} #define WWW

#include <stdio.h>
#include <gtk/gtk.h>

gint count = 0;
GtkWidget *hscale, *hscale7, *hscale11, *hscale13;

void
scale_set_default_values (GtkScale * scale)
{
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_CONTINUOUS);
  gtk_scale_set_digits (scale, 0);      // Zero digits after N.
  gtk_scale_set_value_pos (scale, GTK_POS_TOP);
  gtk_scale_set_draw_value (scale, TRUE);
  count++;
  //printf("count = (%d)\n", count);
}

void
cb_get_value (GtkAdjustment *adj)
{
  double value;
  /*
   * get the value for each hscale
   */
  value = gtk_adjustment_get_value(adj);
  fprintf(stdout,"hscale value: %g\n",value);
}

void
create_range_controls (void)
{
  GtkWidget *window;
  GtkWidget *box1, *box2, *box3;
  GtkWidget *button, *quitbox, *label;
  GtkWidget *scrollbar, *scrollbar7, *scrollbar11, *scrollbar13;
  GtkObject *adj1, *adj7, *adj11, *adj13;

  /*
     Standard window-creating stuff
   */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size (GTK_WINDOW (window), 350, 450);

  g_signal_connect (GTK_OBJECT (window), "destroy",
                    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "four horiz bars");

  box1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), box1);
  gtk_widget_show (box1);

  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

  /* adjustment widgets */

  adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj11 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj13 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

  box3 = gtk_vbox_new (FALSE, 10);
  gtk_box_pack_start (GTK_BOX (box2), box3, TRUE, TRUE, 0);
  gtk_widget_show (box3);

  /*
     Reuse the same adjustment BAR-1
   */

  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale));
  gtk_box_pack_start (GTK_BOX (box3), hscale, TRUE, TRUE, 0);

  g_signal_connect (GTK_OBJECT (adj1), "value_changed",
                    GTK_SIGNAL_FUNC (cb_get_value), NULL);

  gtk_widget_show (hscale);

  /**** BAR-2 ****/
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
  gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale7));
  gtk_box_pack_start (GTK_BOX (box3), hscale7, TRUE, TRUE, 0);
  gtk_widget_show (hscale7);

  /**** BAR-3 ****/
  hscale11 = gtk_hscale_new (GTK_ADJUSTMENT (adj11));
  gtk_widget_set_usize (GTK_WIDGET (hscale11), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale11));
  gtk_box_pack_start (GTK_BOX (box3), hscale11, TRUE, TRUE, 0);
  gtk_widget_show (hscale11);

  /**** BAR-4 ****/
  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13));
  gtk_widget_set_usize (GTK_WIDGET (hscale13), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_box_pack_start (GTK_BOX (box3), hscale13, TRUE, TRUE, 0);
  gtk_widget_show (hscale13);

#ifdef WWW
  /*
     Reuse the same adjustment again
   */
  scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj1));
  gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start (GTK_BOX (box3), scrollbar, TRUE, TRUE, 0);
  gtk_widget_show (scrollbar);

  scrollbar7 = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj7));
  gtk_range_set_update_policy (GTK_RANGE (scrollbar7), GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start (GTK_BOX (box3), scrollbar7, TRUE, TRUE, 0);
  gtk_widget_show (scrollbar7);

  scrollbar11 = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj11));
  gtk_range_set_update_policy (GTK_RANGE (scrollbar11),
                               GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start (GTK_BOX (box3), scrollbar11, TRUE, TRUE, 0);
  gtk_widget_show (scrollbar11);

  scrollbar13 = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj13));
  gtk_range_set_update_policy (GTK_RANGE (scrollbar13),
                               GTK_UPDATE_CONTINUOUS);
  gtk_box_pack_start (GTK_BOX (box3), scrollbar13, TRUE, TRUE, 0);
  gtk_widget_show (scrollbar13);

#endif

  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

  /****  END of horizontal bar stuff ****/

  quitbox = gtk_vbox_new (FALSE, 10);   // WAS "box2" reused
  gtk_container_set_border_width (GTK_CONTAINER (quitbox), 10);

        /**** "box1" below, so this button fits into the overall Window ****/
  gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, TRUE, 0);
  gtk_widget_show (quitbox);

  button = gtk_button_new_with_label ("Quit");
  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, TRUE, 0);
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_widget_grab_default (button);
  gtk_widget_show (button);

  gtk_widget_show (window);
}

int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  create_range_controls ();     // Handles windows and h-bars

  gtk_main ();
  return (0);
}


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sat Mar 03, 2012 12:57 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Ah found the newer thread. Where abouts did you have the labels included for things to go wrong? I thought you said they were the issue but can't find an example in your code?


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sun Mar 04, 2012 9:55 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Paul Childs wrote:
Ah found the newer thread. Where abouts did you have the labels included for things to go wrong? I thought you said they were the issue but can't find an example in your code?


i pulled the labels because they were screwy. i was trying toi label the first hscale widget "pitch"; the second as "Volume," the third as "SPeed (words/min)" and so on. somebody suggested i add a 'frame'; that was when things blew away. i've worked again today until i am blind with a headache.... it is time for a Scotch....naaa, bed....Enuf; this is bey ond me .

gary

ps, tx.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sun Mar 04, 2012 10:36 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Why not just:
Code:
  GtkWidget *table;
  AtkObject *atk_widget, *atk_label;
...
  adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj11 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj13 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

  table = gtk_table_new (4, 2, FALSE);
  gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
  gtk_widget_show (table);

  label=gtk_label_new(_("Pitch:")); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale));
  gtk_table_attach(GTK_TABLE(table), hscale, 1, 2, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale);
  atk_widget=gtk_widget_get_accessible(hscale);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  g_signal_connect (GTK_OBJECT (adj1), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), NULL);
  label=gtk_label_new(_("Volume:")); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
  gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale7));
  gtk_table_attach(GTK_TABLE(table), hscale7, 1, 2, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale7);
  atk_widget=gtk_widget_get_accessible(hscale7);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new(_("Speed WPM:")); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale11 = gtk_hscale_new (GTK_ADJUSTMENT (adj11));
  gtk_widget_set_usize (GTK_WIDGET (hscale11), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale11));
  gtk_table_attach(GTK_TABLE(table), hscale11, 1, 2, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale11);
  atk_widget=gtk_widget_get_accessible(hscale11);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new(_("Delay:")); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13));
  gtk_widget_set_usize (GTK_WIDGET (hscale13), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_table_attach(GTK_TABLE(table), hscale13, 13, 2, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale13);
  atk_widget=gtk_widget_get_accessible(hscale13);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
...


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sun Mar 04, 2012 10:38 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
sorry typo on the lst gtk_table attach. Should read hscale13, 1, 2,... rather than hscale 13, 13, 2, ...


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 05, 2012 2:03 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Paul Childs wrote:
sorry typo on the lst gtk_table attach. Should read hscale13, 1, 2,... rather than hscale 13, 13, 2, ...

Is this the area that I should/did change?
Code:
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_table_attach(GTK_TABLE(table), hscale13, 1, 2, 3, 4,
GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale13);

It will take awhile for me to glue this in place! but I will.

Thanks for your rehacking, paul. I haven't used tables that much. --time to learn... .
gary


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 05, 2012 5:32 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
i got the following code to compile and esec about 90 minutes ago... no labels?

what am i missing?
Code:
/* {uncomments to get scrollbars} #define WWW

compile::

gcc -Wall -Wextra -g xperiment.c -o xC `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
*/

#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget *hscale, *hscale7, *hscale11, *hscale13;

void
scale_set_default_values (GtkScale * scale)
{
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_CONTINUOUS);
  gtk_scale_set_digits (scale, 0);      // Zero digits after N.
  gtk_scale_set_value_pos (scale, GTK_POS_TOP);
  gtk_scale_set_draw_value (scale, TRUE);
}

void
cb_get_value (GtkAdjustment *adj)
{
  double value;
  /*
   * get the value for each hscale
   */
  value = gtk_adjustment_get_value(adj);
  fprintf(stdout,"hscale value: %g\n",value);
}

void
create_range_controls (void)
{
  GtkWidget *window;
  GtkWidget *box1, *box2, *box3;
  GtkWidget *button, *quitbox, *label;
  // {no longer needed }GtkWidget *scrollbar,*scrollbar7,*scrollbar11, *scrollbar13;

GtkWidget *table;
  AtkObject *atk_widget, *atk_label;

  GtkObject *adj1, *adj7, *adj11, *adj13;

  /*
     Standard window-creating stuff
   */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size (GTK_WINDOW (window), 350, 450);

  g_signal_connect (GTK_OBJECT (window), "destroy",
                    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "four horiz bars");

  box1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), box1);
  gtk_widget_show (box1);

  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

  /* adjustment widgets */

  adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj11 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj13 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

  table = gtk_table_new (4, 2, FALSE);
  gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
  gtk_widget_show (table);

  label=gtk_label_new("Pitch:"); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale));
  gtk_table_attach(GTK_TABLE(table), hscale, 1, 2, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale);
  atk_widget=gtk_widget_get_accessible(hscale);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  g_signal_connect (GTK_OBJECT (adj1), "value_changed", GTK_SIGNAL_FUNC
(cb_get_value), NULL);

  label=gtk_label_new("Volume:"); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
  gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale7));
  gtk_table_attach(GTK_TABLE(table), hscale7, 1, 2, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale7);
  atk_widget=gtk_widget_get_accessible(hscale7);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new("Speed WPM:"); /*delete the _() if you are not using gettext for translations*/

  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale11 = gtk_hscale_new (GTK_ADJUSTMENT (adj11));
  gtk_widget_set_usize (GTK_WIDGET (hscale11), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale11));
  gtk_table_attach(GTK_TABLE(table), hscale11, 1, 2, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale11);
  atk_widget=gtk_widget_get_accessible(hscale11);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new("Delay:"); /*delete the _() if you are not using gettext for translations*/
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13)); hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13));
  gtk_widget_set_usize (GTK_WIDGET (hscale13), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_table_attach(GTK_TABLE(table), hscale13, 1, 2, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale13);
  atk_widget=gtk_widget_get_accessible(hscale13);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
// end of p.c.'s atk table code ...
   
  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

  /****  END of horizontal bar stuff ****/

  quitbox = gtk_vbox_new (FALSE, 10);   // WAS "box2" reused
  gtk_container_set_border_width (GTK_CONTAINER (quitbox), 10);

        /**** "box1" below, so this button fits into the overall Window ****/
  gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, TRUE, 0);
  gtk_widget_show (quitbox);

  button = gtk_button_new_with_label ("Quit");
  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, TRUE, 0);
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_widget_grab_default (button);
  gtk_widget_show (button);

  gtk_widget_show (window);
}

int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  create_range_controls ();     // Handles windows and h-bars

  gtk_main ();
  return (0);
}

Same as before. Just the hscacle widgets, no strings.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 05, 2012 11:25 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Yes you got the relacement right.
Sorry my stupid fault it doesn't display right. Happens when one doesn't test before giving out advice. Forgot to include the gtk_widget_show(label); after each label. Tested it this time and it gives the labels. Let me know if you want a different look.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Tue Mar 06, 2012 7:17 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Paul Childs wrote:
Yes you got the relacement right.
Sorry my stupid fault it doesn't display right. Happens when one doesn't test before giving out advice. Forgot to include the gtk_widget_show(label); after each label. Tested it this time and it gives the labels. Let me know if you want a different look.

I largely took the day off yesterday, paul. Back at it today. I'll give it another try ...
Thanks much.
Gary


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Tue Mar 06, 2012 9:35 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Yes. thank you; it does with the the gtk_widget_show [!!]

Now I need to drop in the:

[] male [] female checkboxes`atop the hdcale stuff.

How can I gtkallign the strings to the left? paul? or anybody?

gary


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Tue Mar 06, 2012 10:38 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Replace each of the labels table_attach with the following code (as well as the GtkWidget *halign; declaration):
Code:
  halign = gtk_alignment_new(0, 0, 0, 1);
  gtk_container_add(GTK_CONTAINER(halign), label);
  gtk_widget_show (halign);
  gtk_table_attach(GTK_TABLE(table), halign, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 2, 2);


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Tue Mar 06, 2012 11:08 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
i'm trying to add male/femalr radio buttons here; this wsas gleaned from a lykert scale of five radio buttons initionally. then there is th w trouble at line 106. how do i fix this??
Code:
/*compile::
gcc -Wall -Wextra -g xperiment.c -o xC `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
*/

#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget *hscale, *hscale7, *hscale11, *hscale13;

void
scale_set_default_values (GtkScale * scale)
{
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_CONTINUOUS);
  gtk_scale_set_digits (scale, 0);      // Zero digits after N.
  gtk_scale_set_value_pos (scale, GTK_POS_TOP);
  gtk_scale_set_draw_value (scale, TRUE);
}

void
cb_get_value (GtkAdjustment *adj)
{
  double value;
  /*
   * get the value for each hscale
   */
  value = gtk_adjustment_get_value(adj);
  fprintf(stdout,"hscale value: %g\n",value);
}

void
create_range_controls (void)
{
  GtkWidget *window;
  GtkWidget *box1, *box2, *box3;
  GtkWidget *button, *quitbox, *label;
  GtkWidget *hbox, *radio1, *radio2;
  GtkWidget *table;
  AtkObject *atk_widget, *atk_label;
  GtkObject *adj1, *adj7, *adj11, *adj13;
  /*
     Standard window-creating stuff
   */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size (GTK_WINDOW (window), 350, 450);

  g_signal_connect (GTK_OBJECT (window), "destroy",
                    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "four horiz bars");

  box1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), box1);
  gtk_widget_show (box1);

  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

gtk_container_border_width (GTK_CONTAINER (window), 15);

  /****   – Create the hbox    ****/

  hbox = gtk_hbox_new (FALSE, 0);

     /**** Create the first radio button with a label ****/
  radio1 = gtk_radio_button_new_with_label (NULL,"Male");

  /*
     – Create the rest of the radio buttons with labels –
   */
  radio2 = gtk_radio_button_new_with_label (gtk_radio_button_group
                                            (GTK_RADIO_BUTTON (radio1)),
                                            "Female");
  /*
     Pack the two radio buttons into the hbox.
   */
  gtk_box_pack_start (GTK_BOX (hbox), radio1, TRUE, TRUE, 2);
  gtk_box_pack_start (GTK_BOX (hbox), radio2, TRUE, TRUE, 2);

   // lykert scalr   1 to 5 ...

  /*gtk_box_pack_start (GTK_BOX (hbox), radio5, TRUE, TRUE, 2); */

  /*
     Add the hbox to the window.
   */
  //---gtk_container_add (GTK_CONTAINER (window), hbox);  //FOO

  /*
     Add a border to the window to give the button a little room.
   */
  gtk_container_border_width (GTK_CONTAINER (window), 15); //MARGINS SOLVE ...

  /*
     Display the widgets.
   */
  gtk_widget_show (radio1);
  gtk_widget_show (radio2);
  gtk_widget_show (hbox);
  gtk_widget_show (window);

  /* adjustment widgets */

#ifdef XXXX
  adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj11 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj13 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

  box3 = gtk_vbox_new (FALSE, 10);
  gtk_box_pack_start (GTK_BOX (box2), box3, TRUE, TRUE, 0);
  gtk_widget_show (box3);
  /*
     Reuse the same adjustment BAR-1
   */
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale));
  gtk_box_pack_start (GTK_BOX (box3), hscale, TRUE, TRUE, 0);

  g_signal_connect (GTK_OBJECT (adj1), "value_changed",
                    GTK_SIGNAL_FUNC (cb_get_value), NULL);

  gtk_widget_show (hscale);

  /**** BAR-2 ****/
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
  gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale7));
  gtk_box_pack_start (GTK_BOX (box3), hscale7, TRUE, TRUE, 0);
  gtk_widget_show (hscale7);

  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13));
  gtk_widget_set_usize (GTK_WIDGET (hscale13), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_box_pack_start (GTK_BOX (box3), hscale13, TRUE, TRUE, 0);
  gtk_widget_show (hscale13);

#endif // XXX

// insert table stuff [[ paul Childs ]]

  adj1 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj7 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj11 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  adj13 = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

  table = gtk_table_new (4, 2, FALSE);
  gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
  gtk_widget_show (table);

  label=gtk_label_new("Pitch:"); /*delete the _() if you are not using gettext for translations*/
  gtk_widget_show(label);

  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj1));
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale));
  gtk_table_attach(GTK_TABLE(table), hscale, 1, 2, 0, 1, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale);
  atk_widget=gtk_widget_get_accessible(hscale);

  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  // {SSSS} g_signal_connect (GTK_OBJECT (adj1), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), NULL);
  label=gtk_label_new("Volume:"); /*delete the _() if you are not using gettext for translations*/
  gtk_widget_show(label);

  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj7));
  gtk_widget_set_usize (GTK_WIDGET (hscale7), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale7));
  gtk_table_attach(GTK_TABLE(table), hscale7, 1, 2, 1, 2, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale7);
  atk_widget=gtk_widget_get_accessible(hscale7);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new("Speed WPM:"); /*delete the _() if you are not using gettext for translations*/
  gtk_widget_show(label);

  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale11 = gtk_hscale_new (GTK_ADJUSTMENT (adj11));
  gtk_widget_set_usize (GTK_WIDGET (hscale11), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale11));
  gtk_table_attach(GTK_TABLE(table), hscale11, 1, 2, 2, 3, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale11);
  atk_widget=gtk_widget_get_accessible(hscale11);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  label=gtk_label_new("Delay:"); /*delete the _() if you are not using gettext for translations*/

  gtk_widget_show(label);

  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj13));
  gtk_widget_set_usize (GTK_WIDGET (hscale13), 200, -1);
  scale_set_default_values (GTK_SCALE (hscale13));
  gtk_table_attach(GTK_TABLE(table), hscale13, 1, 2, 3, 4, GTK_FILL|GTK_SHRINK|GTK_EXPAND, GTK_FILL|GTK_SHRINK|GTK_EXPAND, 2, 2);
  gtk_widget_show (hscale13);
  atk_widget=gtk_widget_get_accessible(hscale13);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
// end of p.c.'s atk table code ...

  box2 = gtk_hbox_new (FALSE, 10);
  gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
  gtk_widget_show (box2);

  /****  END of horizontal bar stuff ****/

  quitbox = gtk_vbox_new (FALSE, 10);   // WAS "box2" reused
  gtk_container_set_border_width (GTK_CONTAINER (quitbox), 10);

        /**** "box1" below, so this button fits into the overall Window ****/
  gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, TRUE, 0);
  gtk_widget_show (quitbox);

  button = gtk_button_new_with_label ("Quit");
  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                             GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, TRUE, 0);
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_widget_grab_default (button);
  gtk_widget_show (button);

  gtk_widget_show (window);
}

int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  create_range_controls ();     // Handles windows and h-bars

  gtk_main ();
  return (0);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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