 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 5th, 2006, 10:21 AM
|
|
Registered User
|
|
Join Date: Jul 2006
Posts: 3
Time spent in forums: 33 m 7 sec
Reputation Power: 0
|
|
|
Gtk closeing windows
hey i am new to gtk programming, i am working on some simple practice code, so far i have a window with a table that has a label and then 2 buttons. one button quits the app completely. the other button makes an about like window that has a label and a close button. the close button is linked to delete_event but return false doesnt close that window, cant do gtk_main_quit because that will close the whole app not just the about window. i also tried another one earlier which i think was gtk_destroy(window) or something of the sort but in the delete_event function window would be undefined so that didnt work.
anyone can help me?
should i post what i have so far?
|

July 5th, 2006, 10:39 AM
|
 |
fork while true;
|
|
Join Date: May 2005
Location: England, UK
|
|
|
We'll need to see some code.
I can't quite follow what you're saying. your code should explain.
|

July 6th, 2006, 07:37 AM
|
|
Registered User
|
|
Join Date: Jul 2006
Posts: 3
Time spent in forums: 33 m 7 sec
Reputation Power: 0
|
|
|
thanks
#include <gtk/gtk.h>
static gboolean delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
/*HERE I NEED SOMETHING TO CLOSE THE ABOUT WINDOW WHEN THE BUTTON IS PUSHED, I CANT USE GTK_DESTROY(WINDOW) BECAUSE WINDOW IS NOT DEFINED IN THIS FUNCTION*/
return FALSE;
}
static void destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
static gboolean about( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *label;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "About");
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
frame = gtk_frame_new ("About");
label = gtk_label_new ("This is a label without autowrap text");
button = gtk_button_new_with_label ("close");
/* THIS IS THE BUTTON THAT WHEN PRESSED I WANT IT TO CLOSE THIS "ABOUT" WINDOW WITHOUT CLOSING THE ENTIRE PROGRAM, THIS BUTTON ACTIVATES delete_event BUT THAT DOESNT CLOSE THE ABOUT WINDOW */
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (delete_event), NULL);
table = gtk_table_new (2, 3, TRUE);
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 3, 0, 1);
gtk_container_add (GTK_CONTAINER (window), table);
gtk_widget_show (label);
gtk_widget_show (frame);
gtk_widget_show (button);
gtk_widget_show (table);
gtk_widget_show (window);
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *label;
gtk_init (&argc, &argv);
frame = gtk_frame_new ("DATA");
label = gtk_label_new ("This is a label without autowrap text");
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Application Name");
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
table = gtk_table_new (2, 2, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
button = gtk_button_new_with_label ("About");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (about), (gpointer) "About");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 2, 0, 1);
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Quit");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (destroy), NULL);
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
gtk_widget_show (button);
gtk_widget_show (label);
gtk_widget_show (frame);
gtk_widget_show (table);
gtk_widget_show (window);
gtk_main ();
return 0;
}
|

July 6th, 2006, 02:39 PM
|
 |
fork while true;
|
|
Join Date: May 2005
Location: England, UK
|
|
|
Can you please point out the lines of code you're having trouble with and why you think that is?
|

July 7th, 2006, 08:47 AM
|
|
Registered User
|
|
Join Date: Jul 2006
Posts: 3
Time spent in forums: 33 m 7 sec
Reputation Power: 0
|
|
|
(line numbers have changed a bit because of the new commenting)
i need line 11 to close the window made by the about function (line 21) without closeing the entire application (dont want to use gtk_main_quit)
maybe on line 34 something needs to be changed in the signal for the button that when pressed will call the delete_event function (line 4)
i also did a bit of commenting there too to explain the problem.
thanks for the help.
|

July 7th, 2006, 09:38 AM
|
 |
fork while true;
|
|
Join Date: May 2005
Location: England, UK
|
|
|
Right, I see what you're on with.
The only way out of this one that I can see is a global variable, which I use for all my windows anyway.
So declare window globally at the top of the file.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|