comp.lang.ada
 help / color / mirror / Atom feed
* Closing a program with GTK
@ 2011-09-22  1:21 ldries46
  2011-09-22  7:20 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: ldries46 @ 2011-09-22  1:21 UTC (permalink / raw)


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







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22  1:21 Closing a program with GTK ldries46
@ 2011-09-22  7:20 ` Dmitry A. Kazakov
  2011-09-22 10:24   ` ldries46
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2011-09-22  7:20 UTC (permalink / raw)


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

See:

http://rosettacode.org/wiki/Simple_windowed_application#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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22  7:20 ` Dmitry A. Kazakov
@ 2011-09-22 10:24   ` ldries46
  2011-09-22 12:07     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: ldries46 @ 2011-09-22 10:24 UTC (permalink / raw)


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_windowed_application#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 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22 10:24   ` ldries46
@ 2011-09-22 12:07     ` Dmitry A. Kazakov
  2011-09-22 12:36       ` ldries46
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2011-09-22 12:07 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22 12:07     ` Dmitry A. Kazakov
@ 2011-09-22 12:36       ` ldries46
  2011-09-22 13:48         ` Dmitry A. Kazakov
  2011-09-22 23:06         ` Randy Brukardt
  0 siblings, 2 replies; 8+ messages in thread
From: ldries46 @ 2011-09-22 12:36 UTC (permalink / raw)


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 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22 12:36       ` ldries46
@ 2011-09-22 13:48         ` Dmitry A. Kazakov
  2012-07-26 21:59           ` Jack Mitchell
  2011-09-22 23:06         ` Randy Brukardt
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2011-09-22 13:48 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22 12:36       ` ldries46
  2011-09-22 13:48         ` Dmitry A. Kazakov
@ 2011-09-22 23:06         ` Randy Brukardt
  1 sibling, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2011-09-22 23:06 UTC (permalink / raw)


"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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Closing a program with GTK
  2011-09-22 13:48         ` Dmitry A. Kazakov
@ 2012-07-26 21:59           ` Jack Mitchell
  0 siblings, 0 replies; 8+ messages in thread
From: Jack Mitchell @ 2012-07-26 21:59 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-01  2:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22  1:21 Closing a program with GTK ldries46
2011-09-22  7:20 ` Dmitry A. Kazakov
2011-09-22 10:24   ` ldries46
2011-09-22 12:07     ` Dmitry A. Kazakov
2011-09-22 12:36       ` ldries46
2011-09-22 13:48         ` Dmitry A. Kazakov
2012-07-26 21:59           ` Jack Mitchell
2011-09-22 23:06         ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox