[gtkada] Addressing external data in a GUI

Preben Randhol randhol+gtkada at pvv.org
Thu Jun 16 09:08:41 CEST 2005


On Thu, Jun 16, 2005 at 09:16:04AM +0800, Rick Duley wrote:
> 
> However, there is another step.
> 
> Here is the dream:
> 
> I have a task which creates the GUI.  The GUI accepts user input and
> writes it to a record and, on command, passes a copy of the record to
> a protected type.  Another task, which runs the analysis engine reads
> the record from the protected type and then goes about the business of
> analysis.  There is two-way communication between the tasks through
> the protected type.  My current problem is to have the Main Loop of
> the GUI include checks on flags and data in the protected type.

Are you sure you need tasking?

--==========
with Gtk.Main;
with Analyse60_Window_Pkg; use Analyse60_Window_Pkg;

-- debug
with Ada.Text_Io; use Ada.Text_Io;
-- debug

procedure Analyse60_Window is
   Analyse60_Window : Analyse60_Window_Access;
begin
   Gtk.Main.Set_Locale;
   Gtk.Main.Init;
   Gtk_New(Analyse60_Window);
   Show_All(Analyse60_Window);
   Gtk.Main.Main;
end Analyse60_Window;

Nothing is going to happen after the Gtk.Main.Main before you quit the
program. In a normal program you would wait for the user to give the
program a command like open file or calculate this. By using callbacks
the right procedures gets called.

The only thing after Gtk.Main.Main; should be post prosessing before
closing the application. Such as catching exceptions and store the data
in a emergency file in case the program crashed.

> The problem is probably obvious to you.  The 'Pulse' method is not addressed
> until 'Main' is exited - by which time it is too late and an access failure
> occurs.

Yes you do not want to exit Main (see above)

> In my dream, the Engine Task sets a flag in the protected type which
> is read by the GUI Main Loop and the 'Pulse' method is called from
> there.  (In this example, I am trying to make the call from the driver
> but it does not break in to the Loop.  I tried adding a new method to
> Analyse60_Window_Pkg but that didn't work either.) 

Are you going to use a pulse or you want a progress bar that counts from
0 to 100% ? If only a pulse you start it from the callback when the user
presses the calculate/analyse button. You then call the analysis
procedure and when it finishes you can display the data. If you want to
count from 0 to 100% or that the user should be able to do other things
in the program in case the analysis are length, then I guess you need
tasking.

> What I cannot discern from reading the GtkAdaRM on Gtk.Main is how to
> get the check on the flag made within the loop.  I must, somehow, be
> able to make a modification to the list of things checked by the Main
> Loop to carry out that check.

You should use read this on tasking in general if you haven't already:

   http://www.it.bton.ac.uk/staff/je/adacraft/ch19.htm

And to do tasking in an GtkAda application have a look at my small
program Klokka (=the clock):

   http://www.pvv.org/~randhol/Ada95/Klokka.zip
   or
   http://www.pvv.org/~randhol/Ada95/Klokka.tar.gz

(Don't use the code from http://www.pvv.org/~randhol/Ada95/Klokka/ as it
is not updated. Problem is that I was updating Klokka but then I managed
to overwrite the source by some old files. Teached me to use a version
control like darcs. But I haven't had time to rewrite the lost code yet
and put it on the web)

You also want to look at the testgtk program (under examples in the
GtkAda source) as it shows you how to do many things.

HTH

Preben
-- 
Preben Randhol -------------- http://www.pvv.org/~randhol/Ada95 --
                 «For me, Ada95 puts back the joy in programming.»



More information about the gtkada mailing list