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 12:17 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How do get all the bottons on the last line/row?
PostPosted: Mon Feb 20, 2012 12:39 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
you know, somethimes it's a LOT easier just coding yourself rather than looking for example to snarf up. after two or three hours of googling around, i wrote up something i thought might work. it did. the only thing now it to get the buttons on the same level.

also, i think i'm doing something wrong or clumsy here and would be much obliged for help in any de-clumsying or whatever.

thanks much,

gary
Code:
/*
* Compile:

gcc -Wall -Wextra -g twoLeft.c -o tLeft `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

*/

#include <gtk/gtk.h>

#define ABOUT \
"\n\n     This program assists those with a speech impairment to speak\n\
     \n\n\n\
     Principal Author: Gary Kline\n\n\n\
     Copyright (C), 2011, 2012."

static void
remove_text_window (GtkButton *widget, GtkWidget *text_window)
{
  (void) widget;  // get rid of gcc complaint.
  gtk_widget_destroy (text_window);
}


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

  GtkWidget *window;
  GtkWidget *close;
  GtkWidget *vbox;
  GtkWidget *bbox, *hbox, *halign, *credits, *license;
  GtkWidget *label;

  gtk_init (&argc, &argv);

  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, 200);
  gtk_window_set_title (GTK_WINDOW (window), "GtkAlignment");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);

  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /****    Only string in Help/About ...  ****/

  label = gtk_label_new (ABOUT);

  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

  bbox = gtk_hbutton_box_new ();
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
  gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);

  hbox = gtk_hbox_new (TRUE, 3);
  credits = gtk_button_new_with_label ("Credits");
  gtk_widget_set_size_request (credits, 70, 30);
  gtk_container_add (GTK_CONTAINER (hbox), credits);
  license = gtk_button_new_with_label ("License");
  gtk_container_add (GTK_CONTAINER (hbox), license);
  halign = gtk_alignment_new (0, 0, 0, 1);
  gtk_container_add (GTK_CONTAINER (halign), hbox);
  gtk_box_pack_start (GTK_BOX (vbox), halign, FALSE, FALSE, 0);

  close = gtk_button_new_with_label ("Close");
  gtk_container_add (GTK_CONTAINER (bbox), close);
  g_signal_connect (close, "clicked", G_CALLBACK (remove_text_window), window);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}




Top
 Profile  
 
 Post subject: Re: How do get all the bottons on the last line/row?
PostPosted: Mon Feb 20, 2012 7:25 pm 
Offline
Never Seen the Sunlight

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

There are two ways of doing the help dialog that you want, the hard way and the easy way. First I shall show you the hard way which is a correction of your code.

What you did originally was to place the buttons two on one line and the last button on another. Here I have used a GtkVBox to contain the GtkLabel and a GtkHBox which is set to be expanded. To the GtkHBox is added two GtkHButtonBox again both set expanded and with one set to have the buttons to the start and the other to have the buttons set to the end. To these I then added the buttons. I also tried to simplify the code.

Code:
/*
* Compile:

gcc -Wall -Wextra -g twoLeft.c -o tLeft `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

*/

#include <gtk/gtk.h>

#define ABOUT \
"\n\n     This program assists those with a speech impairment to speak\n\
     \n\n\n\
     Principal Author: Gary Kline\n\n\n\
     Copyright (C), 2011, 2012."

static void
remove_text_window (GtkButton *widget, GtkWidget *text_window)
{
  (void) widget;  // get rid of gcc complaint.
  gtk_widget_destroy (text_window);
}


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

  GtkWidget *window;
  GtkWidget *close;
  GtkWidget *vbox;
  GtkWidget *hbbox;
  GtkWidget *b1box, *b2box, *credits, *license;
  GtkWidget *label;

  gtk_init (&argc, &argv);

  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, 200);
  gtk_window_set_title (GTK_WINDOW (window), "GtkAlignment");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /****    Only string in Help/About ...  ****/

  label = gtk_label_new (ABOUT);
  gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

  hbbox = gtk_hbox_new(TRUE, 2);
  b1box = gtk_hbutton_box_new ();
  b2box = gtk_hbutton_box_new ();

  gtk_box_pack_start (GTK_BOX (vbox), hbbox, TRUE, TRUE, 0);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (b1box), GTK_BUTTONBOX_START);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (b2box), GTK_BUTTONBOX_END);
  gtk_box_pack_start (GTK_BOX (hbbox), b1box, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbbox), b2box, TRUE, TRUE, 0);

  credits = gtk_button_new_with_label ("Credits");
  license = gtk_button_new_with_label ("License");
  close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);

  gtk_box_pack_start (GTK_BOX(b1box), credits, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX(b1box), license, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX(b2box), close, FALSE, FALSE, 0);

  g_signal_connect (close, "clicked", G_CALLBACK (remove_text_window), window);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}


and the easy way. This is a complete example and all that you need to show an about dialog that is standardised across most GTK applications is one function call to set all the properties.

The API you need is for the GtkAboutDialog http://developer.gnome.org/gtk/stable/GtkAboutDialog.html and the function I used is gtk_show_about_dialog() see http://developer.gnome.org/gtk/stable/GtkAboutDialog.html#gtk-show-about-dialog

Code:
/*
* Compile:

gcc -Wall -Wextra -g twoLeft.c -o tLeft `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

*/

#include <gtk/gtk.h>

const gchar *authors[] = {
  "Gary Kline",
  NULL
};

void
cb_on_about(GtkWidget *object, gpointer data)
{
  gtk_show_about_dialog(GTK_WINDOW(data),
    "program-name", "VBC",
    "version", "0.0",
    "copyright", "Copyright (c) 2011, 2012",
    "comments", "This program assists those with a speech impairment to speak",
    "authors", authors,
    "license", "Some license",
    NULL);
}

int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *about_button, *quit_button;
  GtkWidget *hbox;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  hbox = gtk_hbox_new(FALSE, 2);
  about_button = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
  quit_button = gtk_button_new_from_stock(GTK_STOCK_QUIT);

  gtk_container_add(GTK_CONTAINER(window), hbox);
  gtk_box_pack_start(GTK_BOX(hbox), about_button, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), quit_button, FALSE, FALSE, 0);

  g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  g_signal_connect (about_button, "clicked", G_CALLBACK(cb_on_about), window);
  g_signal_connect (quit_button, "clicked", G_CALLBACK(gtk_main_quit), NULL);

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: How do get all the bottons on the last line/row?
PostPosted: Tue Feb 21, 2012 7:46 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Aaargh. i started writing a reply and took a break. when i got back to my reply, it vanished...

nutshell, you're help has been great and in the morning [localtime], i'll study further. lots of tweaks to do....


Top
 Profile  
 
 Post subject: Re: How do get all the bottons on the last line/row?
PostPosted: Wed Feb 22, 2012 12:06 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
hi errol,

i've been experimention with your code--mainly tryihng to figure out how gtk_show_about_dialog() works. for example, why the fuction creates two buttons on the lower left and why nothing i do creates`another button. [note that i don't want a third button on the left... just that my code doesn't do it!]

there's no sense in wasting the bandwidth is re-posting your coded, but here is what i added minus the title_button stuff below.


void
cb_on_about(GtkWidget *object, gpointer data)
{
gtk_show_about_dialog(GTK_WINDOW(data),
"program-name", "VBC",
"version", "0.0",
"copyright", "Copyright (c) 2011, 2012",
"comments", "This program assists those with a speech impairment to speak",
"authors", authors,
"license", "Some license",
"title", "This is a title",
NULL);
}

to create a title_buuton i have tried various 'GTK_STOCK_XYZ';it obviously does create XYZ, but only in the startup window. where am i messing up?

gary


Top
 Profile  
 
 Post subject: Re: How do get all the bottons on the last line/row?
PostPosted: Wed Feb 22, 2012 7:23 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
gtk_show_about_dialog() is a convenience function for creating a GtkAboutDialog setting any properties on it and showing it. It also keeps track of the GtkAboutDialog so that only one is shown at a time. The properties can be listed in the function call and as many as is needed. So you added the property "title", this then sets the title of the window. Not all properties will have a button. They are only created if they are needed, so the properties that do have a button are "artists", "authors", "documenters", "license", "translator-credits"??. Note that you can also add email links, website (property "website") and a logo (property "logo").

So it can be very useful as you do not need to put in all the hard work into creating an about dialog window, it will be standardised across GTK applications and it will handle all the handling of signals internally for things like the links to emails and websites, button clicks etc.

On the down side it is not very flexible as you can not add your own buttons or do other things within the GtkAboutDialog. If you need that then this is not really what you want, the about dialog should be kept short and to the point. It is really a short description of the application, credits and the license for it. If you need things like "help" that should be another window, where more details can be given.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How do get all the bottons on the last line/row?
PostPosted: Wed Feb 22, 2012 8:05 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
i tried twso or three of the properties listed and none worked. i was going to try the website and give a link to somwhere on my domain site that will offer more features, help--if necessary, and possibly the latest tarball. i didn't go through with the attempt; now i'll see.

tthanks for clearing this up.

gary

PS: i have already gave the callback a first-run test in vbc.c. Looks promising.


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

All times are UTC


Who is online

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