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 Aug 30, 2014 10:13 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: this is from my menu Help/About: no "Cloae" button.
PostPosted: Wed Feb 08, 2012 1:03 am 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
the following is apated from a popup/dialog without a close button. it is from a simple text editor that i thought would teach me something about creating "Close" buttons on short menu dialogs. i've done what you guys suggested above to no avail.


#include <gtk/gtk.h>

/* remove text window when button is pressed */
static gint
remove_text_window (GtkWidget *widget, GdkEventExpose *event, GtkWidget * text_window)
{
gtk_widget_destroy (text_window);
return FALSE;
}


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

GtkWidget *window;
GtkWidget *close;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *halign;
GtkWidget *valign;
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);



/* only string in Help/show ...*/
label = gtk_label_new ("Text Editor\nGtk / C\nVersion 4.5\n\nCopyRight\nAll Rights Reserved\n");
gtk_container_add (GTK_CONTAINER (window), label);

vbox = gtk_vbox_new(FALSE, 5);
valign = gtk_alignment_new(0, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(vbox), valign);
gtk_container_add(GTK_CONTAINER(window), vbox);

hbox = gtk_hbox_new(TRUE, 3);

close = gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(hbox), close);

halign = gtk_alignment_new(1, 0, 0, 0);
gtk_container_add(GTK_CONTAINER(halign), hbox);

gtk_box_pack_start(GTK_BOX(vbox), halign, FALSE, FALSE, 0);

gtk_signal_connect (GTK_OBJECT (close), "button_press_event",
(GtkSignalFunc) remove_text_window, window);

gtk_widget_show_all(window);

gtk_main();

return 0;
}

i figured i can cobble together a few function that takes "tht" and outputs "that" and around 133 other common abbreviations and add to this editor. vim or gvim is a bit complex for new users. at any rate, i figured i would *at least* be able to add a close button to my help dialogs. i ran into the same problems i had before and trying to fix them so far has has no success. if there are quick fixes for this problem, i would be much obliged for some help...!


Top
 Profile  
 
 Post subject: Re: this is from my menu Help/About: no "Cloae" button.
PostPosted: Wed Feb 08, 2012 7:23 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I updated your code a bit, since it was using some long-deprecated stuff (gtk_signal_connect() for example). I hope this code does what you want. If you need some more explanation, just ask.

Code:
#include <gtk/gtk.h>

/* remove text window when button is pressed */
static void
remove_text_window (GtkButton *widget,
                    GtkWidget *text_window)
{
  gtk_widget_destroy (text_window);
}


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

  GtkWidget *window;
  GtkWidget *close;
  GtkWidget *vbox;
  GtkWidget *bbox;
  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/show ...*/
  label = gtk_label_new ("Text Editor\n"
                         "Gtk / C\n"
                         "Version 4.5\n\n"
                         "CopyRight\n"
                         "All Rights Reserved\n");
  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);

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


Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: this is from my menu Help/About: no "Cloae" button.
PostPosted: Wed Feb 08, 2012 9:38 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
as often happens, about 20 minutes after i posted my try, i did get what your post gives. A blank window with a [Close] button in the lower right. but in my revision and is whast you posted, i see no Text and no Copyright strings. i am using gtk 2.24 [i think] on ubuntu 11.10.

maybe i am missing some library?

in my Help menu, i have three drop-down items that should be more or less stable: authors+everyone who helped me create VBC, instructions on using the program, and maybe a brief "About" dialog. in short, i'm looking for something the naive user can click on and read, with a Close button in the lower right.

what i finally came up with, and your code only gives me an empty dialog window with the Close button.

how-to fix?

gary


Top
 Profile  
 
 Post subject: Re: this is from my menu Help/About: no "Cloae" button.
PostPosted: Thu Feb 09, 2012 7:26 am 
Offline
Never Seen the Sunlight

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

I have tried out Tadej's example on my machine and it works OK (Debian using GTK+ 2.24). Ubuntu seams to be playing around a lot with themes, fonts etc. So first check that your font and theme settings are OK and that colours are set OK for example you do not have white text on a white background. Also when you run the example via a "xterm" console do you get any warnings posted.

Also note there is a widget just for doing an about dialog it is called GtkAboutDialog. You can use it to display in a standardised way a short description of your application and all the credits as wells as links for web sites and email. See http://developer.gnome.org/gtk/stable/GtkAboutDialog.html for more information on it.

_________________
E.


Top
 Profile  
 
 Post subject: Re: this is from my menu Help/About: no "Cloae" button.
PostPosted: Thu Feb 09, 2012 6:00 pm 
Offline
GTK+ Geek

Joined: Sun Dec 04, 2011 9:29 pm
Posts: 71
Location: Seattle, WA
Errol (and Tadej),

AAAARRRRGH! yes. i hadn't copy/pasted the
Code:
correctly and it never compiled.[1] *worse*, because i have 6 or 7 examples in my directory, i wasn't sure. [[yes, i used grep in my "checking", but missed it nevertheless. i'm sorry for this mess-up.]]

gary

(crawling back in my hole... .)

[1]:: i mean, it did compile, but i didn't see the error messages until a few minutes ago.


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

All times are UTC


Who is online

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