* GTk3 without the Gtkbuilder and Glad @ 2016-06-10 18:16 ldries46 2016-06-10 18:38 ` Jeffrey R. Carter 2016-06-10 19:55 ` Dmitry A. Kazakov 0 siblings, 2 replies; 8+ messages in thread From: ldries46 @ 2016-06-10 18:16 UTC (permalink / raw) For a number of reasons I want to use Gtk3 without using Glade and GtkBuilder. I am Building A template program now and I just came to a problem I just could not find documentation about. I want to create a Callback routine that in each case where the program can be stopped can be called. Let us say : On_Quit. I can make that routine and let it run from the menu or some error, But I cannot find the way to run this routine from the destroy button of the window. How should I do that? For information the call back routine has the following code: procedure On_Quit(Object : access Gtk_Menu_Item_Record'Class) is pragma Unreferenced (Object); begin -- At this point the ini files must be closed. All ini files are updated -- and closed with one call to Close_IIni -- If no Init Files are used then this call can be deleted Close_Ini; Gtk.Main.Main_Quit; end On_Quit; I hope someone can help me L. Dries ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-10 18:16 GTk3 without the Gtkbuilder and Glad ldries46 @ 2016-06-10 18:38 ` Jeffrey R. Carter [not found] ` <575bcceb$0$28281$e4fe514c@news.kpn.nl> 2016-06-10 19:55 ` Dmitry A. Kazakov 1 sibling, 1 reply; 8+ messages in thread From: Jeffrey R. Carter @ 2016-06-10 18:38 UTC (permalink / raw) On 06/10/2016 11:16 AM, ldries46 wrote: > > I can make that routine and let it run from the menu or some error, But I cannot > find the way to run this routine from the destroy button of the window. How > should I do that? The GTK3 version of Mine_Detector (created by Pascal Malaise) has the following for the callback for the delete event: function When_Close (Object : access Gtk_Window_Record'Class; Event : Gdk.Event.Gdk_Event) return Boolean; so presumably you'll need a callback with this specification. It's connected by Window_Cb.Connect (Window, "delete_event", Window_Cb.To_Marshaller (When_Close'Access) ); using package Window_Cb is new Gtk.Handlers.Return_Callback (Gtk_Window_Record, Boolean); HTH -- Jeff Carter "Beyond 100,000 lines of code you should probably be coding in Ada." P. J. Plauger 26 ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <575bcceb$0$28281$e4fe514c@news.kpn.nl>]
* Re: GTk3 without the Gtkbuilder and Glad [not found] ` <575bcceb$0$28281$e4fe514c@news.kpn.nl> @ 2016-06-11 17:38 ` Jeffrey R. Carter 2016-06-12 7:50 ` ldries46 0 siblings, 1 reply; 8+ messages in thread From: Jeffrey R. Carter @ 2016-06-11 17:38 UTC (permalink / raw) On 06/11/2016 01:27 AM, ldries46 wrote: > > /I think I did exactly as you told, what went wrong/ Some observations: * Mine_Detector's handler handles the "delete_event" event and is called when the user clicks on the close button in the title bar (the only way to exit Mine_Detector). You're trying to handle the "destroy" event. If you want to respond to the close button in the title bar, and it sounds to me as if you do, then you should probably handle "delete_event". * The parameter list for your callback function is different from that in Mine_Detector. They should be the same. * You reference the Object parameter of your callback function (you pass it to a procedure), but have a pragma Unreferenced for it. -- Jeff Carter "I certainly have not the talent which some people possess, ... of conversing easily with those I have never seen before." Pride and Prejudice 121 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-11 17:38 ` Jeffrey R. Carter @ 2016-06-12 7:50 ` ldries46 2016-06-12 17:10 ` Jeffrey R. Carter 0 siblings, 1 reply; 8+ messages in thread From: ldries46 @ 2016-06-12 7:50 UTC (permalink / raw) Indeed I had still a few thing not correct, but now I havethe errors. I now have the following code: package Windows_Callback is new Gtk.Handlers.Return_Callback (Main_Window_Record, boolean); This line is the first only one the package where the following statement is used Windows_Callback.Connect(MainWindow, "delete_event", Windows_Callback.To_Marshaller(On_Window_Destroy'Access)); function On_Window_Destroy (Object : access Gtk_Window_Record'Class; Event : Gdk.Event.Gdk_Event) return Boolean; No candidate interpretation match the actuals point to just before .To_Marshaller and expected type handler defined points to just before 'Access Deleting 'Access does not solve the problem Changing "destroy"into "delete_event" does that neither. "Jeffrey R. Carter" schreef in bericht news:njhia6$6t5$1@dont-email.me... On 06/11/2016 01:27 AM, ldries46 wrote: > > /I think I did exactly as you told, what went wrong/ Some observations: * Mine_Detector's handler handles the "delete_event" event and is called when the user clicks on the close button in the title bar (the only way to exit Mine_Detector). You're trying to handle the "destroy" event. If you want to respond to the close button in the title bar, and it sounds to me as if you do, then you should probably handle "delete_event". * The parameter list for your callback function is different from that in Mine_Detector. They should be the same. * You reference the Object parameter of your callback function (you pass it to a procedure), but have a pragma Unreferenced for it. -- Jeff Carter "I certainly have not the talent which some people possess, ... of conversing easily with those I have never seen before." Pride and Prejudice 121 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-12 7:50 ` ldries46 @ 2016-06-12 17:10 ` Jeffrey R. Carter 2016-06-13 7:40 ` ldries46 0 siblings, 1 reply; 8+ messages in thread From: Jeffrey R. Carter @ 2016-06-12 17:10 UTC (permalink / raw) On 06/12/2016 12:50 AM, ldries46 wrote: > > package Windows_Callback is new > Gtk.Handlers.Return_Callback (Main_Window_Record, boolean); > > Windows_Callback.Connect(MainWindow, "delete_event", > Windows_Callback.To_Marshaller(On_Window_Destroy'Access)); > > function On_Window_Destroy (Object : access Gtk_Window_Record'Class; > Event : Gdk.Event.Gdk_Event) return Boolean; The only remaining difference I can see is that Mine_Detector instantiates Return_Callback with Gtk_Window_Record, while you instantiate it with Main_Window_Record. -- Jeff Carter "What I wouldn't give for a large sock with horse manure in it." Annie Hall 42 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-12 17:10 ` Jeffrey R. Carter @ 2016-06-13 7:40 ` ldries46 2016-06-13 15:50 ` Jeffrey R. Carter 0 siblings, 1 reply; 8+ messages in thread From: ldries46 @ 2016-06-13 7:40 UTC (permalink / raw) You are correct, this worked. I thought that because Main_Window_Record was an instantation of Gtk_window_record that should also do the trick and was more clear for the reader. "Jeffrey R. Carter" schreef in bericht news:njk52u$jmg$1@dont-email.me... On 06/12/2016 12:50 AM, ldries46 wrote: > > package Windows_Callback is new > Gtk.Handlers.Return_Callback (Main_Window_Record, boolean); > > Windows_Callback.Connect(MainWindow, "delete_event", > > Windows_Callback.To_Marshaller(On_Window_Destroy'Access)); > > function On_Window_Destroy (Object : access Gtk_Window_Record'Class; > Event : Gdk.Event.Gdk_Event) return Boolean; The only remaining difference I can see is that Mine_Detector instantiates Return_Callback with Gtk_Window_Record, while you instantiate it with Main_Window_Record. -- Jeff Carter "What I wouldn't give for a large sock with horse manure in it." Annie Hall 42 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-13 7:40 ` ldries46 @ 2016-06-13 15:50 ` Jeffrey R. Carter 0 siblings, 0 replies; 8+ messages in thread From: Jeffrey R. Carter @ 2016-06-13 15:50 UTC (permalink / raw) On 06/13/2016 12:40 AM, ldries46 wrote: > You are correct, this worked. > I thought that because Main_Window_Record was an instantation of > Gtk_window_record that should also do the trick and was more clear for the reader. Gtk_Window_Record isn't a generic, so I presume you mean "extension" rather than "instantiation". I gave you what Mine_Detector has because it works. It might also work to instantiate Return_Callback with Main_Window_Record and make the Object parameter of the callback function be "access Main_Window_Record'Class". I haven't tried that and so don't know for sure. -- Jeff Carter "One day he told me he was a gynecologist. He couldn't speak no foreign languages." Take the Money and Run 147 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: GTk3 without the Gtkbuilder and Glad 2016-06-10 18:16 GTk3 without the Gtkbuilder and Glad ldries46 2016-06-10 18:38 ` Jeffrey R. Carter @ 2016-06-10 19:55 ` Dmitry A. Kazakov 1 sibling, 0 replies; 8+ messages in thread From: Dmitry A. Kazakov @ 2016-06-10 19:55 UTC (permalink / raw) On 2016-06-10 20:16, ldries46 wrote: > I want to create a Callback routine that in each case where the program > can be stopped can be called. Let us say : On_Quit. > I can make that routine and let it run from the menu or some error, But > I cannot find the way to run this routine from the destroy button of the > window. How should I do that? The signal issued at an attempt to close the top-level window is "delete-event". It can be ignored, if the window must stay. The signal issued upon object destruction (window included) is "destroy". It cannot be rejected. Typically Gtk.Main.Main_Quit is called from the handler of the main window's "destroy". P.S. Maybe GLADE already calls Gtk.Main.Main_Quit, but you still can connect to "destroy". P.P.S. It is a bad place to store settings upon handling "destroy" because they can be lost on application crash. A better strategy is to do it from a timer, say each 30s or so. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-06-13 15:50 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-06-10 18:16 GTk3 without the Gtkbuilder and Glad ldries46 2016-06-10 18:38 ` Jeffrey R. Carter [not found] ` <575bcceb$0$28281$e4fe514c@news.kpn.nl> 2016-06-11 17:38 ` Jeffrey R. Carter 2016-06-12 7:50 ` ldries46 2016-06-12 17:10 ` Jeffrey R. Carter 2016-06-13 7:40 ` ldries46 2016-06-13 15:50 ` Jeffrey R. Carter 2016-06-10 19:55 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox