Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.ada

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-22-2011, 01:21 AM
ldries46
Guest
 
Posts: n/a
Default Closing a program with GTK

I have a program in which I want to stop the program to quit while first
conducting a special task. The program is linked with the "-mwindows" to get
rid of the DOS-window.
I am running on a Windows 7 system
I am using the following routines in the .callback package
-----------------------
-- On_Quit1_Activate --
-----------------------

procedure On_Quit1_Activate
(Object : access Gtk_Image_Menu_Item_Record'Class)
is
pragma Unreferenced (Object);
begin
Destroy(Transc_AdaWindow);
end On_Quit1_Activate;

where Transc_AdaWindow is the top level window and
-----------------------
-- On_Window_Destroy --
-----------------------

procedure On_Window_Destroy
(Object : access Gtk_Widget_Record'Class)
is
pragma Unreferenced (Object);
begin
Close_Ini;
end On_Window_Destroy;

where Close_Ini is the action that must be executed
Close_Ini is part of a package with no reference to GTK routines.

In both the cases That I use the On Quit facility or the windows abort
button I get the following message:
Program received signal SIGSEGV, Segmentation fault.
0x0003fd43 in ?? ()

When debugging in GPS I found that the message is generated in the
gtk_object package in the Destroy routine at the moment that you enter the
Internal routine with the Step button

What do I do wrong, this construction worked in another program whitout
the -mswindows switch, but I need this switch to get a full stop op the
program with the Quit menuitem or the abort button

L. Dries




Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 09-22-2011, 07:20 AM
Dmitry A. Kazakov
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

On Thu, 22 Sep 2011 03:21:00 +0200, ldries46 wrote:

See:

http://rosettacode.org/wiki/Simple_w...pplication#Ada

for proper handling of application exiting. In particular,
Gtk.Main.Main_Quit must be called from Destroy handler. Delete event
handler must return False.

> When debugging in GPS I found that the message is generated in the
> gtk_object package in the Destroy routine at the moment that you enter the
> Internal routine with the Step button


You cannot debug Gtk applications in the debugger. Use tracing and error
Glib logging.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Reply With Quote
  #3 (permalink)  
Old 09-22-2011, 10:24 AM
ldries46
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

I just have corrected the problem for the quit menu button, and that
worked. Thanks for that. But the problem with the Close button on top of the
window stays

The code of the procedures is now
procedure On_Quit1_Activate
(Object : access Gtk_Image_Menu_Item_Record'Class)
is
pragma Unreferenced (Object);
begin
On_Window_Destroy(Transc_AdaWindow);
end On_Quit1_Activate;
and
procedure On_Window_Destroy
(Object : access Gtk_Widget_Record'Class)
is
pragma Unreferenced (Object);
begin
Close_Ini;
Gtk.Main.Main_Quit;
end On_Window_Destroy;

In the package where I am initiating the handlers I have the following
lines

package Destroy_Callback is new Gtk.Handlers.Callback (Gtk_Widget_Record);
--------------------------------------------------------------------------------
-- Creation Destroy action
--------------------------------------------------------------------------------
Destroy_Callback.Connect( Transc_Ada, "destroy",
Destroy_Callback.To_Marshaller (On_Window_Destroy'Access), False);

I expected the close button to got to the On_Window_Destroy routine but
instead it goes to the gtk.object.Destroy routine

I can see in the GPS debugger the exact position where it goes wrong by
placing a breakpoint in that Destroy routine.


"Dmitry A. Kazakov" schreef in bericht
news:ec116uy7j718$.1urzzp7i6tpth$.dlg@40tude.net.. .

On Thu, 22 Sep 2011 03:21:00 +0200, ldries46 wrote:

See:

http://rosettacode.org/wiki/Simple_w...pplication#Ada

for proper handling of application exiting. In particular,
Gtk.Main.Main_Quit must be called from Destroy handler. Delete event
handler must return False.

> When debugging in GPS I found that the message is generated in the
> gtk_object package in the Destroy routine at the moment that you enter the
> Internal routine with the Step button


You cannot debug Gtk applications in the debugger. Use tracing and error
Glib logging.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Reply With Quote
  #4 (permalink)  
Old 09-22-2011, 12:07 PM
Dmitry A. Kazakov
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

On Thu, 22 Sep 2011 12:24:03 +0200, ldries46 wrote:

> I just have corrected the problem for the quit menu button, and that
> worked. Thanks for that. But the problem with the Close button on top of the
> window stays
>
> The code of the procedures is now
> procedure On_Quit1_Activate
> (Object : access Gtk_Image_Menu_Item_Record'Class)
> is
> pragma Unreferenced (Object);
> begin
> On_Window_Destroy(Transc_AdaWindow);


If you want to destroy a window, you have to call its Destroy. Calling a
handler is pointless.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Reply With Quote
  #5 (permalink)  
Old 09-22-2011, 12:36 PM
ldries46
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

It maybe pointless but the destroy method the close button reaches is the
one that gives the segmentation fault. The routine On_Window_Destroy is the
one that closes the window and ends the program.
I need that routine carried out. I don't think it is a good idea to alter
the gtk.object.destroy routine so what can I do?

L. Dries

"Dmitry A. Kazakov" schreef in bericht
news:sdmxk3iekz24.1pquann2siya2$.dlg@40tude.net...

On Thu, 22 Sep 2011 12:24:03 +0200, ldries46 wrote:

> I just have corrected the problem for the quit menu button, and that
> worked. Thanks for that. But the problem with the Close button on top of
> the
> window stays
>
> The code of the procedures is now
> procedure On_Quit1_Activate
> (Object : access Gtk_Image_Menu_Item_Record'Class)
> is
> pragma Unreferenced (Object);
> begin
> On_Window_Destroy(Transc_AdaWindow);


If you want to destroy a window, you have to call its Destroy. Calling a
handler is pointless.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Reply With Quote
  #6 (permalink)  
Old 09-22-2011, 01:48 PM
Dmitry A. Kazakov
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

On Thu, 22 Sep 2011 14:36:36 +0200, ldries46 wrote:

> The routine On_Window_Destroy is the
> one that closes the window and ends the program.


According to the code you posted On_Window_Destroy is a signal handler
connected to the "destroy" event. The intended use of such handler in Gtk
is to free all resources associated with the widget which are not managed
by Gtk.

In Gtk you shall never call any handlers explicitly.

> I need that routine carried out. I don't think it is a good idea to alter
> the gtk.object.destroy routine so what can I do?


Destroy emits the "destroy" event, which in turn notifies all handlers of
the signal, all reference holders release the reference which then lead to
deallocation of the widget.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Reply With Quote
  #7 (permalink)  
Old 09-22-2011, 11:06 PM
Randy Brukardt
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

"ldries46" <bertus.dries@planet.nl> wrote in message
news:4e7b2b6d$0$2601$703f8584@news.kpn.nl...
> It maybe pointless but the destroy method the close button reaches is the
> one that gives the segmentation fault. The routine On_Window_Destroy is
> the one that closes the window and ends the program.
> I need that routine carried out. I don't think it is a good idea to alter
> the gtk.object.destroy routine so what can I do?


Use Claw instead? :-)

[Or GWindows, QTAda, etc.]

Randy.


Reply With Quote
  #8 (permalink)  
Old 07-26-2012, 09:59 PM
Jack Mitchell
Guest
 
Posts: n/a
Default Re: Closing a program with GTK

In message <79iy1peuceu9$.bzuvizc9yuhz.dlg@40tude.net>, Dmitry A.
Kazakov <mailbox@dmitry-kazakov.de> writes
>On Thu, 22 Sep 2011 14:36:36 +0200, ldries46 wrote:
>
>> The routine On_Window_Destroy is the
>> one that closes the window and ends the program.

>
>According to the code you posted On_Window_Destroy is a signal handler
>connected to the "destroy" event. The intended use of such handler in Gtk
>is to free all resources associated with the widget which are not managed
>by Gtk.
>
>In Gtk you shall never call any handlers explicitly.
>
>> I need that routine carried out. I don't think it is a good idea to alter
>> the gtk.object.destroy routine so what can I do?

>
>Destroy emits the "destroy" event, which in turn notifies all handlers of
>the signal, all reference holders release the reference which then lead to
>deallocation of the widget.
>


Try something like :-

-- Here we just set a handler for delete_event that immediately exits
GTK.

MY_PROG_PACKAGE.Return_Handlers.Connect
(Window, "delete_event",
MY_PROG_PACKAGE.Return_Handlers.To_Marshaller
( MY_PROG_Package.Delete_Event'Access ) );

-- more setup

GTK.WINDOW.Show( Window );

-- All GtkAda applications must have a Main. Control ends here
-- and waits for an event to occur (like a key press or mouse event).
GTK.Main.Main;

end MY_PROG;




with Gdk.Event;
with Gtk.Widget;
with Gtk.Handlers;
with GLIB;

package MY_PROG_Package is


package Handlers is new Gtk.Handlers.User_Callback
(Widget_Type => gtk.Widget.Gtk_Widget_Record,
User_Type => String_Access);

package Return_Handlers is new Gtk.Handlers.Return_Callback
(Widget_Type => gtk.Widget.Gtk_Widget_Record,
Return_Type => Boolean);

function Delete_Event
(Widget : access gtk.Widget.Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event) return Boolean;


end MY_PROG_PACKAGE;

--
Jack Mitchell
Reply With Quote
 
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 12:31 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.