Added lists to config type, as a list. Changed data-views to new format; added htmlview.start-url

svn: r13347
This commit is contained in:
Doug Blank 2009-10-08 04:47:04 +00:00
parent 99282aa715
commit 9d8ff1bacf
3 changed files with 50 additions and 26 deletions

View File

@ -476,7 +476,7 @@ class HtmlView(PageView):
""" """
hbox = gtk.HBox(False, 4) hbox = gtk.HBox(False, 4)
self.urlfield = gtk.Entry() self.urlfield = gtk.Entry()
self.urlfield.set_text("http://gramps-project.org") self.urlfield.set_text(config.get("htmlview.start-url"))
self.urlfield.connect('activate', self._on_activate) self.urlfield.connect('activate', self._on_activate)
hbox.pack_start(self.urlfield, True, True, 4) hbox.pack_start(self.urlfield, True, True, 4)
button = gtk.Button(stock=gtk.STOCK_APPLY) button = gtk.Button(stock=gtk.STOCK_APPLY)

View File

@ -43,25 +43,20 @@ except:
try: try:
import config import config
dv = config.get('interface.data-views') dv = config.get('interface.data-views') # list of strings
#remove GeoView so we do not try to eval it if import fails #remove GeoView so we do not try to eval it if import fails
if not geopresent and not dv.find('GeoView') == -1: if not geopresent and dv.count('GeoView') > 0:
dv = dv.replace('GeoView','').replace(',,',',') dv.remove('GeoView')
DATA_VIEWS = eval("["+dv+"]") DATA_VIEWS = [eval(view) for view in dv]
#add or remove GeoView if config says so #add or remove GeoView if config says so
if geopresent and config.get('preferences.geoview') and \ if geopresent and config.get('preferences.geoview') and \
not GeoView in DATA_VIEWS: not GeoView in DATA_VIEWS:
DATA_VIEWS.append(GeoView) DATA_VIEWS.append(GeoView)
config.set('interface.data-views', config.get('interface.data-views').append('GeoView')
config.get('interface.data-views')+",GeoView")
elif geopresent and not config.get('preferences.geoview') and \ elif geopresent and not config.get('preferences.geoview') and \
GeoView in DATA_VIEWS: GeoView in DATA_VIEWS:
DATA_VIEWS.remove(GeoView) DATA_VIEWS.remove(GeoView)
newval = config.get('interface.data-views').replace('GeoView','')\ config.get('interface.data-views').remove('GeoView')
.replace(',,',',')
if newval[-1] == ',':
newval = newval[:-1]
config.set('interface.data-views', newval)
except AttributeError: except AttributeError:
# Fallback if bad config line, or if no Config system # Fallback if bad config line, or if no Config system
DATA_VIEWS = [ DATA_VIEWS = [

View File

@ -51,6 +51,33 @@ import const
#--------------------------------------------------------------- #---------------------------------------------------------------
INIFILE = os.path.join(const.HOME_DIR, "gramps32.ini") INIFILE = os.path.join(const.HOME_DIR, "gramps32.ini")
#---------------------------------------------------------------
#
# Local functions
#
#---------------------------------------------------------------
def eval_item(setting):
"""
Given a value from an ini file, return it in proper type.
May be recursively called, in the case of nested structures.
"""
setting = setting.strip()
value = None
if setting.startswith("'") and setting.endswith("'"):
value = setting[1:-1]
elif setting.startswith("[") and setting.endswith("]"):
list_data = setting[1:-1]
value = [eval_item(item) for item in list_data.split(",")]
elif setting == "True":
value = True
elif setting == "False":
value = False
elif "." in setting:
value = float(setting)
else:
value = int(setting)
return value
#--------------------------------------------------------------- #---------------------------------------------------------------
# #
# Classes # Classes
@ -135,14 +162,17 @@ class ConfigManager(object):
self.data[name] = {} self.data[name] = {}
for opt in parser.options(sec): for opt in parser.options(sec):
setting = parser.get(sec, opt).strip() setting = parser.get(sec, opt).strip()
####################### Upgrade from oldstyle < 3.2
if oldstyle: if oldstyle:
####################### Upgrade from oldstyle < 3.2
# if we know this setting, convert type # if we know this setting, convert type
key = "%s.%s" % (name, opt) key = "%s.%s" % (name, opt)
if self.has_default(key): if self.has_default(key):
vtype = type(self.get_default(key)) vtype = type(self.get_default(key))
if vtype == bool: if vtype == bool:
value = setting in ["1", "True"] value = setting in ["1", "True"]
elif vtype == list:
print "WARNING: ignoring old key '%s'" % key
continue # there were no lists in oldstyle
else: else:
value = vtype(setting) value = vtype(setting)
else: else:
@ -150,17 +180,14 @@ class ConfigManager(object):
print "WARNING: ignoring old key '%s'" % key print "WARNING: ignoring old key '%s'" % key
continue # with next setting continue # with next setting
####################### End upgrade code ####################### End upgrade code
elif setting.startswith("'") and setting.endswith("'"):
value = setting[1:-1]
elif setting == "True":
value = True
elif setting == "False":
value = False
elif "." in setting:
value = float(setting)
else: else:
value = int(setting) value = eval_item(setting)
self.data[name][opt.lower()] = value ####################### Now, let's test and set:
if type(value) == type(self.default[name][opt.lower()]):
self.data[name][opt.lower()] = value
else:
print ("WARNING: ignoring key with wrong type '%s.%s'"
% (name, opt.lower()))
def save(self, filename = None): def save(self, filename = None):
""" """
@ -421,6 +448,8 @@ register('geoview.map', "person")
register('geoview.stylesheet', "") register('geoview.stylesheet', "")
register('geoview.zoom', 0) register('geoview.zoom', 0)
register('htmlview.start-url', "http://gramps-project.org")
register('interface.address-height', 450) register('interface.address-height', 450)
register('interface.address-width', 650) register('interface.address-width', 650)
register('interface.attribute-height', 350) register('interface.attribute-height', 350)
@ -431,9 +460,9 @@ register('interface.clipboard-height', 300)
register('interface.clipboard-width', 300) register('interface.clipboard-width', 300)
register('interface.dont-ask', False) register('interface.dont-ask', False)
register('interface.data-views', register('interface.data-views',
'GrampletView,PersonView,RelationshipView,' ['GrampletView', 'PersonView', 'RelationshipView',
'FamilyListView,PedigreeView,EventView,SourceView,' 'FamilyListView', 'PedigreeView', 'EventView', 'SourceView',
'PlaceView,MediaView,RepositoryView,NoteView') 'PlaceView', 'MediaView', 'RepositoryView', 'NoteView'])
register('interface.event-height', 450) register('interface.event-height', 450)
register('interface.event-ref-height', 450) register('interface.event-ref-height', 450)
register('interface.event-ref-width', 600) register('interface.event-ref-width', 600)