Make fonts configurable.

This commit is contained in:
Florian Bruhin 2014-02-10 07:03:51 +01:00
parent 9636432bd5
commit 1af78272bb
4 changed files with 46 additions and 14 deletions

View File

@ -105,28 +105,31 @@ tab.bg = grey
tab.bg.selected = black
tab.fg = white
tab.seperator = white
[fonts]
_monospace = Monospace, "DejaVu Sans Mono", Consolas, Monaco,
"Bitstream Vera Sans Mono", "Andale Mono", "Liberation Mono",
"Courier New", Courier, monospace, Fixed, Terminal
completion = 8pt ${_monospace}
tabbar = 8pt ${_monospace}
statusbar = 8pt ${_monospace}
"""
_MONOSPACE = ['Monospace', 'DejaVu Sans Mono', 'Consolas', 'Monaco',
'Bitstream Vera Sans Mono', 'Andale Mono', 'Liberation Mono',
'Courier New', 'Courier', 'monospace', 'Fixed', 'Terminal']
MONOSPACE = ', '.join(_MONOSPACE)
def init(confdir):
"""Initialize the global objects based on the config in configdir."""
global config, colordict
global config, colordict, fontdict
config = Config(confdir)
try:
colordict = ColorDict(config['colors'])
except KeyError:
colordict = ColorDict()
fontdict = FontDict(config['fonts'])
def get_stylesheet(template):
"""Return a formatted stylesheet based on a template."""
return template.strip().format(color=colordict, monospace=MONOSPACE)
return template.strip().format(color=colordict, font=fontdict)
class ColorDict(dict):
@ -168,6 +171,38 @@ class ColorDict(dict):
return None
class FontDict(dict):
"""A dict aimed at Qt stylesheet fonts."""
def __getitem__(self, key):
"""Override dict __getitem__.
If a value wasn't found, return an empty string.
(Color not defined, so no output in the stylesheet)
In all other cases, return font: <value>.
"""
try:
val = super().__getitem__(key)
except KeyError:
return ''
else:
return 'font: {};'.format(val)
def getraw(self, key):
"""Get a value without the transformations done in __getitem__.
Returns a value, or None if the value wasn't found.
"""
try:
return super().__getitem__(key)
except KeyError:
return None
class Config(ConfigParser):
"""Our own ConfigParser subclass."""

View File

@ -49,7 +49,7 @@ class CompletionView(QTreeView):
_stylesheet = """
QTreeView {{
font-family: {monospace};
{font[completion]}
{color[completion.fg]}
{color[completion.bg]}
outline: 0;
@ -59,7 +59,6 @@ class CompletionView(QTreeView):
{color[completion.item.bg]}
}}
QTreeView::item:has-children {{
font-weight: bold;
{color[completion.category.fg]}
{color[completion.category.bg]}
border-top: 1px solid {color[completion.category.border.top]};

View File

@ -42,8 +42,7 @@ class StatusBar(QWidget):
* {{
{color[statusbar.bg.__cur__]}
{color[statusbar.fg.__cur__]}
font-family: {monospace};
font-size: 8pt;
{font[statusbar]}
}}
"""

View File

@ -37,8 +37,7 @@ class TabWidget(QTabWidget):
}}
QTabBar {{
font-family: {monospace};
font-size: 8pt;
{font[tabbar]}
}}
QTabBar::tab {{