Use string for default config

This commit is contained in:
Florian Bruhin 2014-01-30 08:25:49 +01:00
parent 143dba4461
commit 330332da6d

View File

@ -9,66 +9,64 @@ MONOSPACE -- A list of suitable monospace fonts.
import os.path import os.path
import os import os
import logging import logging
from configparser import ConfigParser from configparser import ConfigParser
config = None config = None
colordict = {} colordict = {}
default_config = { default_config = """
'general': { [general]
'show_completion': 'true', show_completion = true
'space_scroll': '200', space_scroll = 200
},
'keybind': { [keybind]
'o': 'open', o = open
'O': 'tabopen', O = tabopen
'd': 'tabclose', d = tabclose
'J': 'tabnext', J = tabnext
'K': 'tabprev', K = tabprev
'r': 'reload', r = reload
'H': 'back', H = back
'L': 'forward', L = forward
'h': 'scroll -50 0', h = scroll -50 0
'j': 'scroll 0 50', j = scroll 0 50
'k': 'scroll 0 -50', k = scroll 0 -50
'l': 'scroll 50 0', l = scroll 50 0
'u': 'undo', u = undo
'gg': 'scroll_perc_y 0', gg = scroll_perc_y 0
'G': 'scroll_perc_y', G = scroll_perc_y
'n': 'nextsearch', n = nextsearch
'yy': 'yank', yy = yank
'yY': 'yank sel', yY = yank sel
'yt': 'yanktitle', yt = yanktitle
'yT': 'yanktitle sel', yT = yanktitle sel
'pp': 'paste', pp = paste
'pP': 'paste sel', pP = paste sel
'Pp': 'tabpaste', Pp = tabpaste
'PP': 'tabpaste sel', PP = tabpaste sel
},
'colors': { [colors]
'completion.fg': '#333333', completion.fg = #333333
'completion.item.bg': 'white', completion.item.bg = white
'completion.category.bg': ('qlineargradient(x1:0, y1:0, x2:0, y2:1, ' completion.category.bg = qlineargradient(x1:0, y1:0, x2:0, y2:1,
'stop:0 #e4e4e4, stop:1 #dbdbdb)'), stop:0 #e4e4e4, stop:1 #dbdbdb)
'completion.category.border.top': '#808080', completion.category.border.top = #808080
'completion.category.border.bottom': '#bbbbbb', completion.category.border.bottom = #bbbbbb
'completion.item.selected.fg': '#333333', completion.item.selected.fg = #333333
'completion.item.selected.bg': '#ffec8b', completion.item.selected.bg = #ffec8b
'completion.item.selected.border.top': '#f2f2c0', completion.item.selected.border.top = #f2f2c0
'completion.item.selected.border.bottom': '#e6e680', completion.item.selected.border.bottom = #e6e680
'completion.match.fg': 'red', completion.match.fg = red
'statusbar.progress.bg': 'white', statusbar.progress.bg = white
'statusbar.progress.bg.error': 'red', statusbar.progress.bg.error = red
'statusbar.bg': 'black', statusbar.bg = black
'statusbar.fg': 'white', statusbar.fg = white
'statusbar.bg.error': 'red', statusbar.bg.error = red
'tab.bg': 'grey', tab.bg = grey
'tab.bg.selected': 'black', tab.bg.selected = black
'tab.fg': 'white', tab.fg = white
'tab.seperator': 'white', tab.seperator = white
}, """
}
_MONOSPACE = ['Monospace', 'DejaVu Sans Mono', 'Consolas', 'Monaco', _MONOSPACE = ['Monospace', 'DejaVu Sans Mono', 'Consolas', 'Monaco',
'Bitstream Vera Sans Mono', 'Andale Mono', 'Liberation Mono', 'Bitstream Vera Sans Mono', 'Andale Mono', 'Liberation Mono',
@ -157,11 +155,11 @@ class Config(ConfigParser):
"""Initialize Config from default_config and save it.""" """Initialize Config from default_config and save it."""
logging.info("Initializing default config.") logging.info("Initializing default config.")
if self.configdir is None: if self.configdir is None:
self.read_dict(default_config) self.read_string(default_config)
return return
cp = ConfigParser() cp = ConfigParser()
cp.optionxform = lambda opt: opt # be case-insensitive cp.optionxform = lambda opt: opt # be case-insensitive
cp.read_dict(default_config) cp.read_string(default_config)
if not os.path.exists(self.configdir): if not os.path.exists(self.configdir):
os.makedirs(self.configdir, 0o755) os.makedirs(self.configdir, 0o755)
with open(self.configfile, 'w') as f: with open(self.configfile, 'w') as f: