Cache colordict/fontdict

This commit is contained in:
Florian Bruhin 2014-04-07 17:33:12 +02:00
parent 361dc7d037
commit 63eaee50b8

View File

@ -19,6 +19,8 @@
import qutebrowser.config.config as config import qutebrowser.config.config as config
_colordict = None
_fontdict = None
def get_stylesheet(template): def get_stylesheet(template):
"""Format a stylesheet based on a template. """Format a stylesheet based on a template.
@ -30,10 +32,12 @@ def get_stylesheet(template):
The formatted template as string. The formatted template as string.
""" """
cdict = config.config['colors'] global _colordict, _fontdict
fdict = config.config['fonts'] if _colordict is None:
return template.strip().format(color=ColorDict(cdict), _colordict = ColorDict(config.config['colors'])
font=FontDict(fdict)) if _fontdict is None:
_fontdict = FontDict(config.config['fonts'])
return template.strip().format(color=_colordict, font=_fontdict)
class ColorDict(dict): class ColorDict(dict):