diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index 700d9699e..cce833938 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -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: . + + """ + 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.""" diff --git a/qutebrowser/widgets/completion.py b/qutebrowser/widgets/completion.py index f6445da8c..f63308a56 100644 --- a/qutebrowser/widgets/completion.py +++ b/qutebrowser/widgets/completion.py @@ -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]}; diff --git a/qutebrowser/widgets/statusbar/__init__.py b/qutebrowser/widgets/statusbar/__init__.py index ecfe7dfb5..3bd3686a1 100644 --- a/qutebrowser/widgets/statusbar/__init__.py +++ b/qutebrowser/widgets/statusbar/__init__.py @@ -42,8 +42,7 @@ class StatusBar(QWidget): * {{ {color[statusbar.bg.__cur__]} {color[statusbar.fg.__cur__]} - font-family: {monospace}; - font-size: 8pt; + {font[statusbar]} }} """ diff --git a/qutebrowser/widgets/tabbar.py b/qutebrowser/widgets/tabbar.py index 2cea5ce31..b953bad0d 100644 --- a/qutebrowser/widgets/tabbar.py +++ b/qutebrowser/widgets/tabbar.py @@ -37,8 +37,7 @@ class TabWidget(QTabWidget): }} QTabBar {{ - font-family: {monospace}; - font-size: 8pt; + {font[tabbar]} }} QTabBar::tab {{