[gtkada] Limit Storage Size of Gtk_Text
Bade, Frank
Frank.Bade at astrium-space.com
Fri May 17 13:48:13 CEST 2002
Hi !
On Friday 17 May 2002 10:40, you wrote:
> "Bade, Frank" <Frank.Bade at astrium-space.com> writes:
> > This window should display logging information in an application which
> > must be able to run several days without being stopped. Therefore, the
> > amount of data stored by the window should be limited to do not eat up
> > all the memory.
>
> Just remove from the beginning of the gtk_text when it gets too big.
I did it and it worked. But I had problems to correct the vertical
adjustment.
I coded the following statement to force the window to display the last
message always:
Freeze(Log_Window_Ptr.Scrolled_Text);
-- limit the content of the window
Loc_Limit_Stored_Text(Text => Log_Window_Ptr.Scrolled_Text,
Max_Size => Max_Logged_Text_Size);
Insert(Text => Log_Window_Ptr.Scrolled_Text,
Chars => Get_Time & "> " & Msg & Ascii.Lf);
-- jump to the end of the scrolling area
Set_Value(Adjustment => Get_Vadj(Log_Window_Ptr.Scrolled_Text),
Value =>
Get_Upper(Get_Vadj(Log_Window_Ptr.Scrolled_Text)));
Thaw(Log_Window_Ptr.Scrolled_Text);
Here is the above called procedure:
procedure Loc_Limit_Stored_Text(Text : in Gtk.Text.Gtk_Text;
Max_Size : in Glib.Guint) is
use Gtk.Text;
use Glib;
Loc_Old_Len : constant Guint := Get_Length(Text);
Loc_Reduce_By : constant Guint := Max_Size / 10;
begin
if Loc_Old_Len >= Max_Size then
-- reduce it
-- check the size and delete chars if necessary
if Get_Length(Text) >= Max_Size then
Set_Point(Text,0);
if Forward_Delete(Text,Loc_Reduce_By) then
-- set the insertion point to the end of the text
Set_Point (Text => Text,
Index => Get_Length(Text));
else
Loc_New_Err_Msg("Unable to Forward_Delete Text",true);
end if; -- if Forward_Delete(Text,Loc_Reduce_By) then
end if;
end if; -- if Loc_Old_Len >= Max_Size then
end Loc_Limit_Stored_Text;
The result is that it stops working with an exception after having written a
few thousand messages:
Gtk-ERROR **: file gtktext.c: line 4712 (find_line_params): assertion failed:
(lp.end.property)
I didn't want to bother you with those details that's why I asked for an
example ....
Any ideas ??
Frank
--
.......................... Astrium SI ..............................
Frank Bade Tel: +49-421-5395648
Dep.: IO 62 Fax: +49-421-5394378
More information about the gtkada
mailing list