Re: Re[6]: GtkDialog Usage
- From: Harring Figueiredo <harringf yahoo com>
- To: jan jakon <janjakon mail ru>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Re[6]: GtkDialog Usage
- Date: Sat, 25 Dec 2004 19:41:02 -0800 (PST)
Jan:
A couple of comments:
1) you should use g_signal_connect instead of gtk_signal_connect.
2) you should use G_CALLBACK instead of GTK_SIGNAL_CONNECT
The glib is now handling all the signal stuff.
No to the problem:
On the function:
void ShowDialog(GtkWidget *widget, gpointer data)
Remove this line:
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(response_handler), dialog);
You are connecting the signal and you go to the .._run() loop and click the
close button, the gtk_main_loop is one deeper (I think) and never comes back.
Try it out and let me know.
Regards,
Harring.
--- jan jakon <janjakon mail ru> wrote:
Thanks for you help.
Simple code which demonstrate my problem.
$cat main.cpp
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <cstdlib>
#include <cstring>
GtkWidget *dialog;
gint OnDelete(GtkWidget *widget, GdkEvent *event, gpointer data);
gint OnDestroy(GtkWidget *widget, GdkEvent *event, gpointer data);
void ShowDialog(GtkWidget *widget, gpointer data);
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *topLevelWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(topLevelWindow), "delete_event",
GTK_SIGNAL_FUNC(OnDelete), NULL);
gtk_signal_connect(GTK_OBJECT(topLevelWindow), "destroy",
GTK_SIGNAL_FUNC(OnDestroy), NULL);
gtk_container_set_border_width(GTK_CONTAINER(topLevelWindow), 20);
GtkWidget *DialogButton=gtk_button_new_with_label("Dailog");
gtk_signal_connect(GTK_OBJECT(DialogButton), "clicked",
GTK_SIGNAL_FUNC(ShowDialog), &dialog);
gtk_container_add(GTK_CONTAINER(topLevelWindow), DialogButton);
gtk_widget_show(DialogButton);
gtk_widget_show(topLevelWindow);
gtk_main();
g_print("Done!\n");
return EXIT_SUCCESS;
}
gint OnDelete(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return FALSE;
}
void close_dialog(void)
{
if(dialog){
g_print("Destroy dialog\n");
gtk_widget_destroy(dialog);
dialog=NULL;
}
}
gint OnDestroy(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_print("Shutting down\n");
close_dialog();
gtk_main_quit();
return 0;
}
void response_handler(GtkDialog *dialog, gint res_id, GtkWidget *widget)
{
close_dialog();
}
void ShowDialog(GtkWidget *widget, gpointer data)
{
dialog=gtk_dialog_new();
gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE,
GTK_RESPONSE_CLOSE);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(response_handler), dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
}
for any case my Makefile
$cat Makefile
CXX=g++
LDLIBS=`pkg-config --libs gtk+-2.0` `pkg-config --libs gconf-2.0`
CXXFLAGS=-Wall -g -O0 `pkg-config --cflags gtk+-2.0` `pkg-config --cflags
gconf-2.0`
.cpp.o:
$(CXX) $(CXXFLAGS) -c -o$@ $<
gtk-example: main.o
$(CXX) $(LDLIBS) $^ -o $@
clean:
rm -f -r *~ *.o gtk-example
-----Original Message-----
From: Harring Figueiredo <harringf yahoo com>
To: jan jakon <janjakon mail ru>
Date: Sat, 25 Dec 2004 14:08:15 -0800 (PST)
Subject: Re: Re[4]: GtkDialog Usage
Jan:
We are probably missing something silly. If the code license does not
restrict you from sharing, please send me a copy so that I can run and
track it
down. Alternatively, you can send a small sample that replicates the
problem.
Regards,
Harring.
--- jan jakon <janjakon mail ru> wrote:
It is very bad, but already have this code in "quit" handler.
I have close dialog function with such code:
printf("close dialog\n");
fflush(stdout);
if(window){
gtk_widget_destroy(window);
window = NULL;
}
I have response dialog function with suce code:
switch(res_id){
case GTK_RESPONSE_HELP:
//some code
default:
printf("close from response_handler\n");
close_dialog_function();
}
I have main_quit function with such code:
printf("main window close\n");
//some code
close_dialog_function();
//some code
gtk_main_quit();
I get such output:
close from response_handler
close dialog
close from response_handler
close dialog
close from response_handler
close dialog
main end is execute
close dialog
And application hang up.
-----Original Message-----
From: Harring Figueiredo <harringf yahoo com>
To: jan jakon <janjakon mail ru>
Date: Sat, 25 Dec 2004 10:07:51 -0800 (PST)
Subject: Re: Re[2]: GtkDialog Usage
Jan:
In that case, you still have to destroy the dialog when the main
"window"
is
being destroyed.
callback_to_quit_app(){
if(dialog)
gtk_widget_destroy(dialog)
destroy other widget like the dialog you mentioned.
gtk_main_quit()
}
This should do it.
Reg,
Harring
--- jan jakon <janjakon mail ru> wrote:
The main idea: didn't create dialog each time, because it required
too
much
time,
create it once.
But in any way it didn't help.
I try this code:
#if 0
if(dialog){
gint res=gtk_dialog_run(dialog);
return res;
}
#endif
dialog = gtk_dialog_new();
//fill dialog with widgest
gint res=gtk_dialog_run(dilog);
gtk_widget_destroy(GTK_WINDOW(dialog));
dialog=NULL;
return res;
But it DIDN'T solve the problem.
-----Original Message-----
From: Harring Figueiredo <harringf yahoo com>
To: jan jakon <janjakon mail ru>
Date: Sat, 25 Dec 2004 07:34:30 -0800 (PST)
Subject: Re: GtkDialog Usage
--- jan jakon <janjakon mail ru> wrote:
Hello.
I have problem with GtkDialog.
In my application there is main window, on main window there is
button
wich
activate
the follow code:
if(dialog){
gint res=gtk_dialog_run(GTK_DIALOG(window));
return res;
}
dialog = gtk_dialog_new();
//fill dialog with widgest
gint res=gtk_dialog_run(GTK_DIALOG(window));
return res;
If I didn't click on button which show dialog all right.
But if I click, then after close main window program still alive,
and only Ctrl+C help to close it.
You are not destroying the dialog.
try gtk_widget_destroy(dialog);
once you are done with it.
Harring
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
___________________________________________________________
Mail.ru ÎÁÐÏÍÉÎÁÅÔ ÞÔÏ Õ ÏÔÐÒÁ×ÉÔÅÌÑ ÜÔÏÇÏ ÐÉÓØÍÁ ÓËÏÒÏ ÄÅÎØ
ÒÏÖÄÅÎÉÑ:)
___________________________________________________________
ðÕÔÅÛÅÓÔ×ÉÅ - ÂÅÚÕÐÒÅÞÎÙÊ ÐÏÄÁÒÏË ËÏ äÎÀ òÏÖÄÅÎÉÑ!
ôÅÐÅÒØ ÅÇÏ ÍÏÖÎÏ ÐÏÄÁÒÉÔØ ËÒÁÓÉ×Ï.
http://r.mail.ru/cln2625/www.Puteshestvie.ru
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
___________________________________________________________
Mail.ru ÎÁÐÏÍÉÎÁÅÔ ÞÔÏ Õ ÏÔÐÒÁ×ÉÔÅÌÑ ÜÔÏÇÏ ÐÉÓØÍÁ ÓËÏÒÏ ÄÅÎØ ÒÏÖÄÅÎÉÑ:)
___________________________________________________________
ðÕÔÅÛÅÓÔ×ÉÅ - ÂÅÚÕÐÒÅÞÎÙÊ ÐÏÄÁÒÏË ËÏ äÎÀ òÏÖÄÅÎÉÑ!
ôÅÐÅÒØ ÅÇÏ ÍÏÖÎÏ ÐÏÄÁÒÉÔØ ËÒÁÓÉ×Ï.
http://r.mail.ru/cln2625/www.Puteshestvie.ru
=====
==================================================================
Plese, don't send me any attachment in Micro$oft (.DOC, .PPT) format.
Read http://www.fsf.org/philosophy/no-word-attachments.html
Preferable attachments: .PDF, .HTML, .TXT
Please, consider adding this text to Your email signature.
Harring Figueiredo
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
___________________________________________________________
Mail.ru ÎÁÐÏÍÉÎÁÅÔ ÞÔÏ Õ ÏÔÐÒÁ×ÉÔÅÌÑ ÜÔÏÇÏ ÐÉÓØÍÁ ÓËÏÒÏ ÄÅÎØ ÒÏÖÄÅÎÉÑ:)
___________________________________________________________
ðÕÔÅÛÅÓÔ×ÉÅ - ÂÅÚÕÐÒÅÞÎÙÊ ÐÏÄÁÒÏË ËÏ äÎÀ òÏÖÄÅÎÉÑ!
ôÅÐÅÒØ ÅÇÏ ÍÏÖÎÏ ÐÏÄÁÒÉÔØ ËÒÁÓÉ×Ï.
http://r.mail.ru/cln2625/www.Puteshestvie.ru
__________________________________
Do you Yahoo!?
All your favorites on one personal page ? Try My Yahoo!
http://my.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]