From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: backlog3.nntp.ams3.giganews.com!backlog3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: GTK and tasking (GNAT) Date: Sat, 03 May 2014 17:30:08 -0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net o93/Rp34TqjW5UKRTO0KzAM5iHdCVultlaJzN4Qi2U/uemZDnj Cancel-Lock: sha1:6T5gGwFulNA6XonFQTTUDPrErsg= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 Xref: number.nntp.dca.giganews.com comp.lang.ada:186197 Date: 2014-05-03T17:30:08-03:00 List-Id: I guess the following reveals my ignorance about GTK as well as about tasking, but anyway, still beginner. I made a GTK window with a button and a text box. Upon pressing the button, the text box shall count to 10 in 0.5 s intervals. Here follows my callback package (for the button callback function 'Start', 'with'-clauses omitted): ------------------------------------------------------------------- package Callback is type UserType is record txtBox: Gtk.GEntry.Gtk_Entry; end record; package Handlers is new Gtk.Handlers.User_Callback (Widget_Type => Gtk.Widget.Gtk_Widget_Record, User_Type => UserType); procedure Start (widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event; ud: UserType); end Callback; package body Callback is procedure Start (widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event; ud: UserType) is begin for i in 1..10 loop Gtk.GEntry.Set_Text (ud.txtBox, Integer'Image(i)); --Gtk.Widget.Queue_Draw (Gtk.Widget.Gtk_Widget(ud.txtBox)); delay 0.5; end loop; end Start; end Callback; ------------------------------------------------------------------ Now when I press the button nothing happens at first, and after 5 seconds a "1" appears in the text box. Uncommenting the QueueDraw line didn't change anything. Searching for an explication, I thought perhaps somehow some display-update mechanism of GTK is suspended together with my main task during the delays. So I wrote a version using Ada tasks (for the first time in my life). Well, it didn't work either, exactly the same behavior. Can somebody tell me what is wrong and how to do it right? The source of the tasked version follows. The other callback function, 'Quit' is connected to the 'delete' event of the main window. --------------------------------------------------------------------- package Callback is type UserType is record txtBox: Gtk.GEntry.Gtk_Entry; end record; package Handlers is new Gtk.Handlers.User_Callback (Widget_Type => Gtk.Widget.Gtk_Widget_Record, User_Type => UserType); package Return_Handlers is new Gtk.Handlers.Return_Callback (Widget_Type => Gtk.Widget.Gtk_Widget_Record, Return_Type => Boolean); function Quit ( widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event) return Boolean; procedure Start (widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event; ud: UserType); end Callback; package body Callback is goon: Boolean:= true; task Task2 is entry StartCounter (txtBox: Gtk.GEntry.Gtk_Entry); entry TermTask; -- terminate task end Task2; task body Task2 is begin while goon loop select accept StartCounter (txtBox: Gtk.GEntry.Gtk_Entry) do for i in 1..10 loop Gtk.GEntry.Set_Text (txtBox, Integer'Image(i)); Gtk.Widget.Queue_Draw (Gtk.Widget.Gtk_Widget(txtBox)); delay 0.5; end loop; end StartCounter; or accept TermTask do goon:= false; end TermTask; end select; end loop; Ada.Text_IO.Put_Line("Task2 terminating"); end Task2; function Quit ( widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event) return Boolean is --pragma Unreferenced (widget); pragma Unreferenced (event); begin Task2.TermTask; Gtk.Main.Main_Quit; return False; end Quit; procedure Start (widget: access Gtk.Widget.Gtk_Widget_Record'Class; event: Gdk.Event.Gdk_Event; ud: UserType) is begin Task2.StartCounter (ud.txtBox); end Start; end Callback; ------------------------------------------------------------------------ -- Frank Hrebabetzky +55 / 48 / 3235 1106 Florianopolis, Brazil