[gtkada] testgtk/create_spinners.adb patch proposal.

Pascal p.p14 at orange.fr
Sat Jul 14 09:36:18 CEST 2012


Hello, in testgtk-create_spinners from GtkAda GPL 2012, Timer isn't removed when exiting spinners.
Here is a patch proposal:

--- ./create_spinners.adb.0	2012-05-18 10:03:35.000000000 +0200
+++ ./create_spinners.adb	2012-07-11 22:05:49.000000000 +0200
@@ -33,6 +33,8 @@
 with Gtk.Label;       use Gtk.Label;
 with Gtk.Spinner;     use Gtk.Spinner;
 with Gtk.Table;       use Gtk.Table;
+with Gtk.Widget;      use Gtk.Widget;
+with Common;          use Common;
 
 package body Create_Spinners is
 
@@ -42,6 +44,21 @@
    --  Function passed to Time_Cb.Timeout_Add, to be invoked periodically.
    function Spinner_Timeout (Spinner : Gtk_Spinner) return Boolean;
 
+   Timer : G_Source_Id;
+   --  This is stored at the library level so that the On_Destroy callback
+   --  can refer to the results from the calls to Time_Cb.Timeout_Add in the
+   --  Run subprogram.
+
+   ----------------
+   -- On_Destroy --
+   ----------------
+
+   procedure On_Destroy (Window : access Gtk_Widget_Record'Class) is
+      pragma Unreferenced (Window);
+   begin
+      Remove (Timer);
+   end On_Destroy;
+
    ----------
    -- Help --
    ----------
@@ -63,7 +80,6 @@
       Active_Spinner, Transition_Spinner, Inactive_Spinner : Gtk_Spinner;
       Active_Label,   Transition_Label,   Inactive_Label   : Gtk_Label;
       Table1 : Gtk_Table;
-      Timer  : G_Source_Id;
 
    begin
       Set_Label (Frame, "Spinners");
@@ -71,6 +87,9 @@
       Gtk_New (Table1, Rows => 3, Columns => 2, Homogeneous => False);
       Add (Frame, Table1);
 
+      Widget_Handler.Connect
+        (Table1, "destroy", Widget_Handler.To_Marshaller (On_Destroy'Access));
+
       Gtk_New (Active_Label, "Active spinner:");
       Gtk_New (Active_Spinner);
       Attach

HTH, Pascal.
http://blady.pagesperso-orange.fr




More information about the gtkada mailing list