|
From: Jeremy G. <jr...@gm...> - 2009-10-14 15:23:34
|
Hi Michael and everyone,
I'm new to using configobj, and like it a lot. thanks for your work on this!
I have 3 hopefully simple questions that I could not figure out after
reading the online manuals / help pages or past postings to the list.
my goal: I want allow users to edit their application preferences, eg,
key-bindings and other settings for the app. I'm storing the settings
in text files with syntax as expected by configobj, and have a spec
file for default values and for validation purposes. the idea is to
let users edit their config files in a text window, validate their
entries, and save. Mostly this works fabulously. the eventual goal is
to do this through a GUI, but its text for now. I'm using python 2.5,
and need to end up with code that works cross-platform (mac, win,
linux).
here's what I'm asking about: if a user enters a badly formed value
(i.e., that fails validation against the spec file), I've been using
the flatten_errors() function to process it further, like this
mock-code (hopefully indentation will be preserved when posted...):
<code>
for (section_list, key, _) in configobj.flatten_errors(cfg,
resultOfValidate):
if key is not None:
print "Bad value"
# code here to replace the bad value with the default
given in the spec file
else:
print "Missing section"
# code here to handle missing sections
</code>
my questions:
1. how to restore a default value?
I tried using restore_default(), but I kept getting key errors (and
tried several things as keys). I also tried get_default_value(), but
am confused by how to call it, and what to pass to it. I wrote a few
lines to extract the default value from the spec file as a string and
then convert the type (which mostly works, I'm just having trouble
getting default lists to work properly). it would be nice to use the
existing functions. any ideas?
2. how are missing sections reported by a Validator()? I was thinking
that they would be indicated by the key being None, based on the
example(s) on the web, but my code never hits the "missing section"
part. if a user deletes a section, the section name appears to be
deleted in the config file, but there's no missing section flagged as
a key == None in flatten_errors(). if the user then adds the [section]
back into the text, I get a duplicate section name error. so I am
confused -- what should I be looking for?
3. finally, does anyone know of an existing project I could look at
(and borrow from) that uses wxPython for a GUI for letting users
manipulate configobj data? I found a relevant post to this list by
Sebastian Wiesner on Aug 12, 2008 that linked to examples using PyQt4
(http://paste.pocoo.org/show/79974/ ) -- is there anything using
wxPython?
thanks!
--Jeremy
|