Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2006, 10:21 AM
random guy random guy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 3 random guy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old July 5th, 2006, 10:39 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,538 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1050
We'll need to see some code.

I can't quite follow what you're saying. your code should explain.

Reply With Quote
  #3  
Old July 6th, 2006, 07:37 AM
random guy random guy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 3 random guy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}

Reply With Quote
  #4  
Old July 6th, 2006, 02:39 PM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,538 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1050
Can you please point out the lines of code you're having trouble with and why you think that is?

Reply With Quote
  #5  
Old July 7th, 2006, 08:47 AM
random guy random guy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 3 random guy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old July 7th, 2006, 09:38 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,538 LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)LinuxPenguin User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 30 m 28 sec
Reputation Power: 1050
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Gtk closeing windows

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap