GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 24, 2014 3:23 am

All times are UTC




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Wed Mar 07, 2012 5:14 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Here's how you would set up the radio buttons. Add more and rearrange them as you need
Code:
GSList *group=NULL;
...
  gtk_box_pack_start(GTK_BOX (box1), hbox, TRUE, TRUE, 2);
  radio1 = gtk_radio_button_new_with_label (group,"Male");
  group=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio1));
  gtk_widget_show(radio1);
  radio2 = gtk_radio_button_new_with_label (group, "Female");
  group=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio2));
  gtk_widget_show(radio2);
  gtk_box_pack_start(GTK_BOX (hbox), radio1, TRUE, TRUE, 2);
  gtk_box_pack_start(GTK_BOX (hbox), radio2, TRUE, TRUE, 2);


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sat Mar 17, 2012 6:37 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
no-joy, even tho i spent an entire afternoon -> evening to get your code to work. my domain went down for over a delay due to my upstream service provider, thus the delay in responding. any other ideas?


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

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Here's a more thorough example of the radio buttons included within your code along with a few tweaks. By the way, how come you have create_range_controls rather than putting it in main? It's only called once and doesn't really make the code any neater having it out of main.

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

#include <gtk/gtk.h>

void scale_set_default_values (GtkScale *scale)
{
  gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_CONTINUOUS);
  gtk_scale_set_digits (scale, 0);
  gtk_scale_set_value_pos (scale, GTK_POS_TOP);
  gtk_scale_set_draw_value (scale, TRUE);
}

void cb_get_value (GtkAdjustment *adj, gpointer data)
{
  gdouble value;
  gchar *str;

  str=g_strdup(gtk_label_get_label(GTK_LABEL(data)));
  value = gtk_adjustment_get_value(adj);
  g_print("%s %f\n",str,value);
  g_free(str);
}

void create_range_controls (void)
{
  AtkObject *atk_widget, *atk_label;
  GSList *group1=NULL, *group2=NULL;
  GtkObject *adj;
  GtkWidget *vbox, *hbox, *table;
  GtkWidget *hscale, *hscale7, *hscale11, *hscale13;
  GtkWidget *button, *label;
  GtkWidget *radio1, *radio2, *radio3, *radio4, *radio5;
  GtkWidget *window;

  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);
  gtk_window_set_title (GTK_WINDOW (window), "four horiz bars");
  gtk_container_border_width (GTK_CONTAINER (window), 15);
  g_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), NULL);

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

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

  label=gtk_label_new("Pitch:");
  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);
  adj = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
  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 (adj), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), (gpointer) label);

  label=gtk_label_new("Volume:");
  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);
  adj = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  hscale7 = gtk_hscale_new (GTK_ADJUSTMENT (adj));
  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);
  g_signal_connect (GTK_OBJECT (adj), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), (gpointer) label);

  label=gtk_label_new("Speed WPM:");
  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);
  adj = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  hscale11 = gtk_hscale_new (GTK_ADJUSTMENT (adj));
  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);
  g_signal_connect (GTK_OBJECT (adj), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), (gpointer) label);

  label=gtk_label_new("Delay:");
  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);
  adj = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
  hscale13 = gtk_hscale_new (GTK_ADJUSTMENT (adj));
  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);
  g_signal_connect (GTK_OBJECT (adj), "value_changed", GTK_SIGNAL_FUNC (cb_get_value), (gpointer) label);

  label=gtk_label_new("My Gender is:");
  gtk_box_pack_start(GTK_BOX (vbox), label, TRUE, TRUE, 2);
  gtk_widget_show(label);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  hbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start(GTK_BOX (vbox), hbox, TRUE, TRUE, 2);
  gtk_widget_show (hbox);

  radio1 = gtk_radio_button_new_with_label (group1,"Male");
  group1=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio1));
  gtk_box_pack_start(GTK_BOX (hbox), radio1, TRUE, TRUE, 2);
  gtk_widget_show(radio1);
  atk_widget=gtk_widget_get_accessible(radio1);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  radio2 = gtk_radio_button_new_with_label (group1, "Female");
  group1=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio2));
  gtk_box_pack_start(GTK_BOX (hbox), radio2, TRUE, TRUE, 2);
  gtk_widget_show(radio2);
  atk_widget=gtk_widget_get_accessible(radio2);
  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("This Likert scale is useful to me:");
  gtk_box_pack_start(GTK_BOX (vbox), label, TRUE, TRUE, 2);
  gtk_widget_show(label);
  atk_label=gtk_widget_get_accessible(GTK_WIDGET(label));
  hbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start(GTK_BOX (vbox), hbox, TRUE, TRUE, 2);
  gtk_widget_show (hbox);

  radio1 = gtk_radio_button_new_with_label (group2,"Strongly Agree");
  group2=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio1));
  gtk_box_pack_start(GTK_BOX (hbox), radio1, TRUE, TRUE, 2);
  gtk_widget_show(radio1);
  atk_widget=gtk_widget_get_accessible(radio1);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  radio2 = gtk_radio_button_new_with_label (group2, "Agree");
  group2=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio2));
  gtk_box_pack_start(GTK_BOX (hbox), radio2, TRUE, TRUE, 2);
  gtk_widget_show(radio2);
  atk_widget=gtk_widget_get_accessible(radio2);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  radio3 = gtk_radio_button_new_with_label (group2,"Neutral");
  group2=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio3));
  gtk_box_pack_start(GTK_BOX (hbox), radio3, TRUE, TRUE, 2);
  gtk_widget_show(radio3);
  atk_widget=gtk_widget_get_accessible(radio3);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  radio4 = gtk_radio_button_new_with_label (group2, "Disagree");
  group2=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio4));
  gtk_box_pack_start(GTK_BOX (hbox), radio4, TRUE, TRUE, 2);
  gtk_widget_show(radio4);
  atk_widget=gtk_widget_get_accessible(radio4);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
  radio5 = gtk_radio_button_new_with_label (group2,"Strongly Disagree");
  group2=gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio5));
  gtk_box_pack_start(GTK_BOX (hbox), radio5, TRUE, TRUE, 2);
  gtk_widget_show(radio5);
  atk_widget=gtk_widget_get_accessible(radio5);
  atk_object_add_relationship(atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
  atk_object_add_relationship(atk_widget, ATK_RELATION_LABELLED_BY, atk_label);

  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 (vbox), button, TRUE, TRUE, 2);
  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 ();
  gtk_main ();
  return (0);
}


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sun Mar 18, 2012 4:50 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
i;ll test this as soon as i can ws/ my shoulde ralmost falling off, :(

i put the call by itself because i t will be turned into an "Options"dropdown from the menu bar.

if you can atp-get gespeaker, THAT is what i am using to emulate. i want my hscale bars to look almost exactly as he has it. i emailed in weeks ago, but havn't heard how get gets the deafult valut to render as he has.

at any rate, tx.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Sun Mar 18, 2012 5:14 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
hey paul,
that lykert scale that i use from male/female WAS very useful: Strongly agree. ...ah, life; what would we do without it :)

gary'


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

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Ah well in that case you can find the code on http://code.google.com/p/gespeak/. It's written in pygtk though, so more of the guts are hidden.
As espeak is fairly multilingual, I'd suggest learning how to use gettext in your code so as to provide translations for all the strings. It will most likely mean also having to learn how to use the autotools in writing makefiles and configure files, but at some stage every software developer has to do that (even if its only an activity done in ones spare time like me). Finding a good tutorial is tricky as the one on the GNOME site is pretty out of date. Though I've thought of putting one together, It'd likely be full of my own misunderstandings and be more confusing then helpful. Then again maybe it'd inspire someone more knowledgable to do a good job of it. Come to think of it why isn't there any ATK stuff in the GTK tutorials? Nevermind that's enough of my ranting for now.
Sorry with the lykert scale. I am used to them being >=5 buttons so you can get rid of that bit. Never thought of it in terms of possibly being a male/female selector. The radio_buttons can also be done as radio_menu_buttons if you want to remove them from you main app area.
Looks like the GUI side of things is simple enough that it shouldn't be too much more work.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 19, 2012 5:26 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
my small program relies on the already-exististing speech program, espeak. gespeaker does the same thing. /usr/bin/espeak has a rather convoluted means of selected language and type of speaker. For example, -v en/en-us+m5 gives you the united state accent of the 5rh type of male speaker. similarly, -v wn/en-us+f3 yields the third flavor of female speaker. there are scores of countiries , if not hundreds. and i'm pretty sure that espeeak is still under devel. so i'm sticking with it.

what i am trying to figure out is HOW you set the hscale bars to some default value.
say that you watch the pitch of the voice to read 17--that is 17/100ths which is a pretty low male voice and comes close to what i growl out:-) i have looked high/low for some means of setting the hscale bar to a default of 17.

likewise, the volume in espeak is 200; the default is 100. i would like to set the default to 100 to mimick gespeaker. so far i have had no luch. do you have any idea how to do this is gtk?

{FWIW, I have found the python equiv for the C language in a lot of cases. ...but haven't found anything in whast i can grok from gespeaker or otherwise google up to set a default horizontal scale value......}

anyway, appreciate your help ....

gary


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 19, 2012 6:45 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
YES::I found it!![bar-over] :)

the call is gtk_range_set_value() and given GTK_RANGE(hscale) value, say value == 17,
the scale draws a line from 0-16 or 17 :)

EEE-ha! || yee-ha. i ==found == it. i have been hunting for at least 5 days.

Here, e.g.::


gtk_widget_set_usize (GTK_WIDGET (hscale), 200, -1);
scale_set_default_values (GTK_SCALE (hscale));
gtk_range_set_value(GTK_RANGE(hscale), 17); // line-64.


now:: the rest is just plain C hackking.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 19, 2012 9:21 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
actually you have already been setting it all along. Just to zero each time. The initial value is the first value of gtk_adjustment_new.


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Mon Mar 19, 2012 10:37 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Paul Childs wrote:
actually you have already been setting it all along. Just to zero each time. The initial value is the first value of gtk_adjustment_new.



hmm. well, here is what i've got in mind:: folr a separate Options window to appear with, possibly, a few lines of explaination at the top.
[[ i would be much obliged if you could explain how to get such--say, from one to three paragraphs of Intro:]] **

Before you use this Voice By Computer program, here is how you select your own
voice:

or whatever. This code will probable be in a header. Used only onnce. at the end of the page one line, invinting the user to click on the 'Help' drop-downs where i explain this 'universal access' stuff.

...i think i wrote on this forum that this program for the speech-impaired or people who have no larngyx or deaf/dumb--Whatever--is probably not going to be used primarily by us nerds. i intend it for anybody in any culture who has difficulty with verbal communication.

** be great if i could just use fprintf(stdout, .....)


Top
 Profile  
 
 Post subject: Re: Four hscale widgets waiting for labels.
PostPosted: Tue Mar 20, 2012 4:17 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
A lot of minor instructional help can be provided with tool tips but if you want to do a proper job of it, your best bet is to use gnome-doc-utils and include a help menu. Again this will require learning about autotools. Also you'll need to know a bit of xml too, but no biggie there. http://developer.gnome.org/gnome-doc-ma ... ng.html.en gives instruction on how to make use of gnome-doc-utils but assumes you already have a autotools based setup. Here's an example of what it looks like for me (buttons aren't working for putting in code, hope I get the macros right):

Firstly organise your project into folders to help structure and declutter your projects:
/src for putting your xperiment.c file into
/doc Set up a xperiment-help.omf.in according to instructions in the website above. Also a C folder including the Docbook help file: xperiment-help.xml
/po for translations. This requires quite a bit to set up. If you don't want it yet, comment out the po/makefile.in in the AC_CONFIG_FILES macro (configure.ac) and the po folder in the SUBDIRS macro (makefile.am), but its better getting this sorted out earlier before the software gets too complicated.
/confsupp this fills with temporary files when you run configure though you'll probably want to copy in config.guess, config.rpath and maybe config.sub from somewhere else so configure has something to go on. You'll also need gnome-doc-utils.make
/pixmap include an icon for your program: icon_name.png in the following

configure.ac
Code:
AC_PREREQ([2.65])
AC_INIT([packagename],[version#],[your@e.mail],[tarname],[url])
AC_CONFIG_SRCDIR([src/main.h])
AC_CONFIG_AUX_DIR([confsupp])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_GNU_GETTEXT([external])
GNOME_DOC_INIT
AC_PROG_CC([gcc cc])
AC_CONFIG_HEADERS([config.h])
PKG_CHECK_MODULES([XPRT], [gtk+-2.0 >= 2.14 espeak])
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile po/Makefile.in])
AC_OUTPUT()


makefile.am
Code:
SUBDIRS= doc po src
Applicationsdir=$(datadir)/applications
Applications_DATA=xperiment.desktop
pixmapdir=$(datadir)/pixmaps
pixmap_DATA=pixmaps/icon_name.png
EXTRA_DIST=confsupp/gnome-doc-utils.make \
   ABOUT-NLS confsupp/config.rpath m4/ChangeLog \
   AUTHORS ChangeLog COPYING COPYING-DOCS INSTALL NEWS README TODO \
   $(pixmap_DATA) $(Applications_DATA) \
   configure.ac
DISTCHECK_CONFIGURE_FLAGS= --disable-scrollkeeper
ACLOCAL_AMFLAGS = -I m4


src/makefile.am
Code:
AM_CFLAGS=$(XPRT_CFLAGS)
AM_CPPFLAGS= -DLOCALEDIR=\"$(localedir)\" -DPACKAGE=\"$(PACKAGE)\"
bin_PROGRAMS=packagename
packagename_SOURCES=xperiment.c
packagename_LDADD=$(XPRT_LIBS)


doc/makefile.am
Code:
include $(top_srcdir)/confsupp/gnome-doc-utils.make
dist-hook: doc-dist-hook
DOC_MODULE=xperiment-help
DOC_ENTITIES=
DOC_INCLUDES=
DOC_FIGURES=
DOC_LINGUAS=


To access the help file from your program include the following (also have included an about menu):
Code:
GtkWidget *statusbar; /*it helps to have set up a statusbar as a global to send information to*/

void help(GtkWidget *widget, gpointer data)
{
   gchar *uri, *str;
   GError *Err=NULL;

   if (data) uri=g_strdup_printf("ghelp:xperiment-help?%s", (gchar *) data);
   else uri=g_strdup("ghelp:xperiment-help");
   gtk_show_uri(NULL, uri, gtk_get_current_event_time(), &Err);
   g_free(uri);
   if (Err)
   {
      str=g_strdup(_("Could not load help files."));
      gtk_statusbar_push(GTK_STATUSBAR(statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), str), str);
      g_free(str);
      g_error_free(Err);
   }
}

void about(GtkWidget *widget, gpointer data)
{
   GtkWidget *helpwin;

   helpwin=gtk_about_dialog_new();
   g_signal_connect_swapped(G_OBJECT(helpwin), "destroy", G_CALLBACK(gtk_widget_destroy), G_OBJECT(helpwin));
   gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(helpwin), "version#");
   gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(helpwin), "(c) Kline, 2012");
   gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(helpwin), _("xperiment is my experiment in providing an espeak frontend alternative to gespeaker."));
   gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(helpwin), _("translator-credits"));
   gtk_widget_show(helpwin);
   g_signal_connect_swapped(G_OBJECT(helpwin), "response", G_CALLBACK(gtk_widget_destroy), G_OBJECT(helpwin));
}

int main( int argc, char *argv[])
{
   GtkAccelGroup *accel_group=NULL;
   GtkWidget *mnb, *mnu, *mni, *vbox, *window;

   bindtextdomain(PACKAGE, LOCALEDIR); /*these three lines if you set up gettext for translations*/
   bind_textdomain_codeset(PACKAGE, "UTF-8");
   textdomain(PACKAGE);
   gtk_init(&argc, &argv);
   window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), _("Speech Synthesizer"));
   g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
   vbox=gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(window), vbox);
   gtk_widget_show(vbox);
   mnb=gtk_menu_bar_new();
   gtk_box_pack_start(GTK_BOX(vbox), mnb, FALSE, FALSE, 2);
   gtk_widget_show(mnb);
/*add other menus here*/
   mnu=gtk_menu_new();
   mni=gtk_menu_item_new_with_label(_("Instructions"));
   gtk_widget_add_accelerator(mni, "activate", accel_group, GDK_F1, 0, GTK_ACCEL_VISIBLE);
   g_signal_connect(G_OBJECT(mni), "activate", G_CALLBACK(help), NULL);
   gtk_menu_shell_append(GTK_MENU_SHELL(mnu), mni);
   gtk_widget_show(mni);
   mni=gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL);
   g_signal_connect(G_OBJECT(mni), "activate", G_CALLBACK(about), NULL);
   gtk_menu_shell_append(GTK_MENU_SHELL(mnu), mni);
   gtk_widget_show(mni);
   mni=gtk_menu_item_new_with_mnemonic(_("_Help"));
   gtk_widget_show(mni);
   gtk_menu_item_set_submenu(GTK_MENU_ITEM(mni), mnu);
   gtk_menu_shell_append(GTK_MENU_SHELL(mnb), mni);
   gtk_menu_item_right_justify(GTK_MENU_ITEM(mni));
/*pack in the rest of your GUI into the vbox here*/
   statusbar=gtk_statusbar_new();
   gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 2);
   gtk_widget_show(statusbar);
   gtk_widget_show(window);
   gtk_main();
   return 0;
}


You then compile your code with
autoreconf -vif
./configure
make
sudo make install
(or otherwise instead of sudo depending on your OS)

As you can see it's quite complicated, though most of what is above is the autotools on which gnome-doc-utils is just a small bit of work to add in.
As your software depends on espeak you will likely need to know how to use the autotools so that it ensures that espeak is available one way or another (I have it in the PKG_CONFIG macros which are for static linking of code -- not likely what you are doing -- haven't figured out how to ensure things are fine for runtime dependencies). It does become easier once setup; just a bit of a learning curve to get through.


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

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
thanks for your code. i wince at the thought of having to learn the auto-tools stuff, but maybe it's timr. (i've got to rethink my project if it means building in more than i had originally intended. but then, late last year, i knew this would not be a brief project!)

only the initial setup would be based on gespeaker. i have found at least two examples in various categories. basically, i want the user to choose his own voice and be able to test it once or twice. after that, i will re-use most of the same code from the Options menu to let users tune their computer voices.

meanwhile, lots to consider... .

if you want to see some old screen shots:http://www.thought/vbc/


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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