Use jinja for stylesheets.
This commit is contained in:
parent
a4c87b4c54
commit
0b15790f3d
@ -21,6 +21,7 @@
|
||||
|
||||
import functools
|
||||
|
||||
import jinja2
|
||||
from PyQt5.QtGui import QColor
|
||||
|
||||
from qutebrowser.config import config
|
||||
@ -28,19 +29,20 @@ from qutebrowser.utils import log, utils
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=16)
|
||||
def get_stylesheet(template):
|
||||
def get_stylesheet(template_str):
|
||||
"""Format a stylesheet based on a template.
|
||||
|
||||
Args:
|
||||
template: The stylesheet template as string.
|
||||
template_str: The stylesheet template as string.
|
||||
|
||||
Return:
|
||||
The formatted template as string.
|
||||
"""
|
||||
colordict = ColorDict(config.section('colors'))
|
||||
fontdict = FontDict(config.section('fonts'))
|
||||
return template.strip().format(color=colordict, font=fontdict,
|
||||
config=config.instance())
|
||||
template = jinja2.Template(template_str)
|
||||
return template.render(color=colordict, font=fontdict,
|
||||
config=config.instance())
|
||||
|
||||
|
||||
def set_register_stylesheet(obj):
|
||||
|
@ -58,29 +58,30 @@ class CompletionView(QTreeView):
|
||||
# Drawing the item foreground will be done by CompletionItemDelegate, so we
|
||||
# don't define that in this stylesheet.
|
||||
STYLESHEET = """
|
||||
QTreeView {{
|
||||
{font[completion]}
|
||||
{color[completion.bg]}
|
||||
QTreeView {
|
||||
{{font['completion']}}
|
||||
{{color['completion.bg']}}
|
||||
outline: 0;
|
||||
}}
|
||||
}
|
||||
|
||||
QTreeView::item:disabled {{
|
||||
{color[completion.category.bg]}
|
||||
border-top: 1px solid {color[completion.category.border.top]};
|
||||
QTreeView::item:disabled {
|
||||
{{color['completion.category.bg']}}
|
||||
border-top: 1px solid {{color['completion.category.border.top']}};
|
||||
border-bottom: 1px solid
|
||||
{color[completion.category.border.bottom]};
|
||||
}}
|
||||
{{color['completion.category.border.bottom']}};
|
||||
}
|
||||
|
||||
QTreeView::item:selected, QTreeView::item:selected:hover {{
|
||||
border-top: 1px solid {color[completion.item.selected.border.top]};
|
||||
QTreeView::item:selected, QTreeView::item:selected:hover {
|
||||
border-top: 1px solid
|
||||
{{color['completion.item.selected.border.top']}};
|
||||
border-bottom: 1px solid
|
||||
{color[completion.item.selected.border.bottom]};
|
||||
{color[completion.item.selected.bg]}
|
||||
}}
|
||||
{{color['completion.item.selected.border.bottom']}};
|
||||
{{color['completion.item.selected.bg']}}
|
||||
}
|
||||
|
||||
QTreeView:item::hover {{
|
||||
QTreeView:item::hover {
|
||||
border: 0px;
|
||||
}}
|
||||
}
|
||||
"""
|
||||
COLUMN_WIDTHS = (20, 70, 10)
|
||||
|
||||
|
@ -189,9 +189,9 @@ class CompletionItemDelegate(QStyledItemDelegate):
|
||||
self._doc.setDefaultFont(self._opt.font)
|
||||
self._doc.setDefaultTextOption(text_option)
|
||||
self._doc.setDefaultStyleSheet(style.get_stylesheet("""
|
||||
.highlight {{
|
||||
{color[completion.match.fg]}
|
||||
}}
|
||||
.highlight {
|
||||
{{color['completion.match.fg']}}
|
||||
}
|
||||
"""))
|
||||
self._doc.setDocumentMargin(2)
|
||||
|
||||
|
@ -37,14 +37,14 @@ class DownloadView(QListView):
|
||||
"""
|
||||
|
||||
STYLESHEET = """
|
||||
QListView {{
|
||||
{color[downloads.bg.bar]}
|
||||
{font[downloads]}
|
||||
}}
|
||||
QListView {
|
||||
{{color['downloads.bg.bar']}}
|
||||
{{font['downloads']}}
|
||||
}
|
||||
|
||||
QListView::item {{
|
||||
QListView::item {
|
||||
padding-right: 2px;
|
||||
}}
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
@ -93,26 +93,26 @@ class StatusBar(QWidget):
|
||||
_insert_active = False
|
||||
|
||||
STYLESHEET = """
|
||||
QWidget#StatusBar {{
|
||||
{color[statusbar.bg]}
|
||||
}}
|
||||
QWidget#StatusBar {
|
||||
{{color['statusbar.bg']}}
|
||||
}
|
||||
|
||||
QWidget#StatusBar[insert_active="true"] {{
|
||||
{color[statusbar.bg.insert]}
|
||||
}}
|
||||
QWidget#StatusBar[insert_active="true"] {
|
||||
{{color['statusbar.bg.insert']}}
|
||||
}
|
||||
|
||||
QWidget#StatusBar[prompt_active="true"] {{
|
||||
{color[statusbar.bg.prompt]}
|
||||
}}
|
||||
QWidget#StatusBar[prompt_active="true"] {
|
||||
{{color['statusbar.bg.prompt']}}
|
||||
}
|
||||
|
||||
QWidget#StatusBar[error="true"] {{
|
||||
{color[statusbar.bg.error]}
|
||||
}}
|
||||
QWidget#StatusBar[error="true"] {
|
||||
{{color['statusbar.bg.error']}}
|
||||
}
|
||||
|
||||
QWidget {{
|
||||
{color[statusbar.fg]}
|
||||
{font[statusbar]}
|
||||
}}
|
||||
QWidget {
|
||||
{{color['statusbar.fg']}}
|
||||
{{font['statusbar']}}
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
@ -32,16 +32,16 @@ class Progress(QProgressBar):
|
||||
|
||||
# FIXME for some reason, margin-left is not shown
|
||||
STYLESHEET = """
|
||||
QProgressBar {{
|
||||
QProgressBar {
|
||||
border-radius: 0px;
|
||||
border: 2px solid transparent;
|
||||
margin-left: 1px;
|
||||
background-color: transparent;
|
||||
}}
|
||||
}
|
||||
|
||||
QProgressBar::chunk {{
|
||||
{color[statusbar.progress.bg]}
|
||||
}}
|
||||
QProgressBar::chunk {
|
||||
{{color['statusbar.progress.bg']}}
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
@ -53,25 +53,25 @@ class UrlText(textbase.TextBase):
|
||||
_urltype = None
|
||||
|
||||
STYLESHEET = """
|
||||
QLabel#UrlText[urltype="normal"] {{
|
||||
{color[statusbar.url.fg]}
|
||||
}}
|
||||
QLabel#UrlText[urltype="normal"] {
|
||||
{{color['statusbar.url.fg']}}
|
||||
}
|
||||
|
||||
QLabel#UrlText[urltype="success"] {{
|
||||
{color[statusbar.url.fg.success]}
|
||||
}}
|
||||
QLabel#UrlText[urltype="success"] {
|
||||
{{color['statusbar.url.fg.success']}}
|
||||
}
|
||||
|
||||
QLabel#UrlText[urltype="error"] {{
|
||||
{color[statusbar.url.fg.error]}
|
||||
}}
|
||||
QLabel#UrlText[urltype="error"] {
|
||||
{{color['statusbar.url.fg.error']}}
|
||||
}
|
||||
|
||||
QLabel#UrlText[urltype="warn"] {{
|
||||
{color[statusbar.url.fg.warn]}
|
||||
}}
|
||||
QLabel#UrlText[urltype="warn"] {
|
||||
{{color['statusbar.url.fg.warn']}}
|
||||
}
|
||||
|
||||
QLabel#UrlText[urltype="hover"] {{
|
||||
{color[statusbar.url.fg.hover]}
|
||||
}}
|
||||
QLabel#UrlText[urltype="hover"] {
|
||||
{{color['statusbar.url.fg.hover']}}
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
Loading…
Reference in New Issue
Block a user