From: hreba <hreba@terra.com.br>
Subject: GTK and tasking (GNAT)
Date: Sat, 03 May 2014 17:30:08 -0300
Date: 2014-05-03T17:30:08-03:00 [thread overview]
Message-ID: <bsl1uhFd8asU1@mid.individual.net> (raw)
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
next reply other threads:[~2014-05-03 20:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-03 20:30 hreba [this message]
2014-05-03 21:23 ` GTK and tasking (GNAT) Simon Wright
2014-05-04 18:10 ` hreba
2014-05-04 18:29 ` Simon Wright
2014-05-04 22:10 ` hreba
2014-05-04 7:31 ` Dmitry A. Kazakov
2014-05-04 18:36 ` hreba
2014-05-04 19:26 ` Dmitry A. Kazakov
2014-05-04 20:40 ` hreba
2014-05-04 21:07 ` Shark8
2014-05-04 21:32 ` hreba
2014-05-04 21:44 ` Shark8
2014-05-04 21:57 ` hreba
2014-05-05 7:33 ` Dmitry A. Kazakov
2014-05-06 12:43 ` hreba
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox