From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GtkAda question Date: Wed, 14 Apr 2021 22:40:56 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <6074bf6b$0$3702$426a74cc@news.free.fr> <60774222$0$6471$426a74cc@news.free.fr> NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:61788 List-Id: On 2021-04-14 21:27, DrPi wrote: > Le 14/04/2021 à 00:00, Gautier write-only address a écrit : >> If I search for "Glib.Key_File" on the Web, the first hit is: >> >> https://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html >> So perhaps you want to parse and write ".ini-like config files" as >> mentioned there? > That's it. > To be more precise, I need to save and retrieve few data like window > position and size. I [mis]use Gtk_Recent_Manager for the purpose. See the package Gtk.Recent_Manager_Keys. It has function Restore ( Key : UTF8_String; Default : UTF8_String; Manager : Gtk_Recent_Manager := Get_Default ) return UTF8_String; procedure Store ( Key : UTF8_String; Value : UTF8_String; Manager : Gtk_Recent_Manager := Get_Default ); This is basically all what you need. On top of that you set something like: function Restore (Key : String; Default : GInt) return GInt is begin return GInt'Value (Restore (Key, GInt'Image (Default))); exception when others => return GInt (Default); end Restore; Then you restore the window geometry simply as: Window.Resize (Restore ("width", 200), Restore ("height", 100)); Window.Move (Restore ("x", 0), Restore ("y", 0)); [You would add some sanity checks, of course] The advantage is that the recent manager is sort of standard in GTK, it is maintained by GTK on per user basis. All GTK applications share the same *.xbel file. The rest is disadvantages. The file is in XML, you can find your keys there. E.g. stored x position of max_home_automation looks like this: 1677 stored value for x Quite a lot of junk to store one puny value. As all GTK it is kind of buggy, you may experience data losses. But otherwise it is simple for keeping geometry and other settings there. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de