Every user has a preferred way of doing
things — and a good application should be accommodating
enough that important choices—such as what font to
use— can be set by the user. Of course, no one likes
applying their favorite settings every time they start an
application, so we will need to store the settings, too. This
chapter deals with settings — retrieving, storing and using.
Unfortunately, different platforms have
vastly differing traditions for the storing of user preferences.
You can either use the platform standard, or create your own
solution.
Platform differences
On a Windows system, most applications
store user preferences in a central database, called the
Registry. This book is not the place to argue about the wisdom
or folly of keeping all application and system settings in one
database, which can only be accessed with specialized tools.
Most modern windows applications no longer use the once
prevalent .ini standard. Using
.ini, an application could store settings
in a file in either the installation directory, the
windows directory, or in one of two
configuration files: win.ini or
system.ini. Windows has only recently
become a multi-user system, so it is still difficult to
determine where to store user specific settings. In Windows
2000, I suggest the C:\Documents and
Settings\{Username}\Local Settings\Application Data
directory. In the registry, there is the HKEY_USER
branch.
The Unix standard is not so much a standard
as a gentle guide. You can store system-wide application
settings in the /etc directory, or one of
its subdirectories, or in the /usr/share
directory together with resources... Or in
/usr/local/share — or in any number
of other places.
User settings on a Unix system are
generally stored in so-called dot files, or dot directories.
These are files or directories that start with a dot (.) and are
thus ‘invisible' when the user asks for the contents of a
directory using ls (or browses the
directory with a filemanager like konqueror). The dot-files or
dot-directories are located in the home directory of the user. A
Unix home directory can be compared to the user's directory
under C:\Documents And Settings in Windows
2000. It is generally found under /home.
You can retrieve the location of this directory with:
os.environ["HOME"]
This returns None when HOME is not set. If
you are developing for KDE, you might want to store the user
settings in
$HOME/.kde/share/config/instead, and the
application settings in
$KDEDIR/share/apps.