★ Preference system for IDL applications
posted Fri 28 Mar 2008 by Michael Galloy under IDL, ObjectsIt is frequently useful for applications to store information between runs. In general, if it is important enough to ask the user, it is important enough to remember. IDL provides a handy routine APP_USER_DIR
to get a directory to store this type of information, but you are on your own reading and writing these preferences (unfortunately, PREF_SET
and PREF_GET
don’t allow application defined or user-defined preferences). MG_Prefs
(code, docs) handles the dirty work for you by creating and restoring a SAV file for each of your preferences. This is a bit heavy-handed, but it means you store nearly anything as a preference value.
The class is intended to be simple to use. To store a preference do
prefs = obj_new('mg_prefs', author='mgalloy', application='myapp')
prefs->set, 'last_edited', 'myfile.txt'
Then in a later IDL session this preference can be retrieved with
prefs = obj_new('mg_prefs', author='mgalloy', application='myapp')
lastEdited = prefs->get('last_edited')
April 1st, 2008 at 3:31 pm
Coding up something like this was on my to-do list! I like it a lot, thanks for doing it. What is your usage policy? :)
April 1st, 2008 at 3:40 pm
Feel free to use it. It’s released under a Attribution-Noncommercial-Share Alike 2.5 Generic Creative Commons license. These licenses are not normally used for code, but I think of most of the code released this way on this website more as demos/explanations/proof of concept than production code.