Merge branch 'neeasade-templatemagic'
This commit is contained in:
commit
9c68a928ea
@ -147,6 +147,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Austin Anderson
|
* Austin Anderson
|
||||||
* Artur Shaik
|
* Artur Shaik
|
||||||
* Thorsten Wißmann
|
* Thorsten Wißmann
|
||||||
|
* Nathan Isom
|
||||||
* Alexey "Averrin" Nabrodov
|
* Alexey "Averrin" Nabrodov
|
||||||
* meles5
|
* meles5
|
||||||
* ZDarian
|
* ZDarian
|
||||||
@ -156,7 +157,6 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Zach-Button
|
* Zach-Button
|
||||||
* rikn00
|
* rikn00
|
||||||
* Patric Schmitz
|
* Patric Schmitz
|
||||||
* Nathan Isom
|
|
||||||
* Martin Zimmermann
|
* Martin Zimmermann
|
||||||
* Error 800
|
* Error 800
|
||||||
* Brian Jackson
|
* Brian Jackson
|
||||||
|
@ -64,8 +64,8 @@ class DownloadView(QListView):
|
|||||||
|
|
||||||
STYLESHEET = """
|
STYLESHEET = """
|
||||||
QListView {
|
QListView {
|
||||||
{{ color['downloads.bg.bar'] }}
|
background-color: {{ color['downloads.bg.bar'] }};
|
||||||
{{ font['downloads'] }}
|
font: {{ font['downloads'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QListView::item {
|
QListView::item {
|
||||||
|
@ -188,7 +188,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
|
|||||||
self._doc.setDefaultTextOption(text_option)
|
self._doc.setDefaultTextOption(text_option)
|
||||||
self._doc.setDefaultStyleSheet(style.get_stylesheet("""
|
self._doc.setDefaultStyleSheet(style.get_stylesheet("""
|
||||||
.highlight {
|
.highlight {
|
||||||
{{ color['completion.match.fg'] }}
|
color: {{ color['completion.match.fg'] }};
|
||||||
}
|
}
|
||||||
"""))
|
"""))
|
||||||
self._doc.setDocumentMargin(2)
|
self._doc.setDocumentMargin(2)
|
||||||
|
@ -55,15 +55,15 @@ class CompletionView(QTreeView):
|
|||||||
# don't define that in this stylesheet.
|
# don't define that in this stylesheet.
|
||||||
STYLESHEET = """
|
STYLESHEET = """
|
||||||
QTreeView {
|
QTreeView {
|
||||||
{{ font['completion'] }}
|
font: {{ font['completion'] }};
|
||||||
{{ color['completion.bg'] }}
|
background-color: {{ color['completion.bg'] }};
|
||||||
alternate-background-color: {{ color['completion.alternate-bg'] }};
|
alternate-background-color: {{ color['completion.alternate-bg'] }};
|
||||||
outline: 0;
|
outline: 0;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView::item:disabled {
|
QTreeView::item:disabled {
|
||||||
{{ color['completion.category.bg'] }}
|
background-color: {{ color['completion.category.bg'] }};
|
||||||
border-top: 1px solid
|
border-top: 1px solid
|
||||||
{{ color['completion.category.border.top'] }};
|
{{ color['completion.category.border.top'] }};
|
||||||
border-bottom: 1px solid
|
border-bottom: 1px solid
|
||||||
@ -75,7 +75,7 @@ class CompletionView(QTreeView):
|
|||||||
{{ color['completion.item.selected.border.top'] }};
|
{{ color['completion.item.selected.border.top'] }};
|
||||||
border-bottom: 1px solid
|
border-bottom: 1px solid
|
||||||
{{ color['completion.item.selected.border.bottom'] }};
|
{{ color['completion.item.selected.border.bottom'] }};
|
||||||
{{ color['completion.item.selected.bg'] }}
|
background-color: {{ color['completion.item.selected.bg'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView:item::hover {
|
QTreeView:item::hover {
|
||||||
|
@ -41,9 +41,8 @@ def get_stylesheet(template_str):
|
|||||||
The formatted template as string.
|
The formatted template as string.
|
||||||
"""
|
"""
|
||||||
colordict = ColorDict(config.section('colors'))
|
colordict = ColorDict(config.section('colors'))
|
||||||
fontdict = FontDict(config.section('fonts'))
|
|
||||||
template = jinja2.Template(template_str)
|
template = jinja2.Template(template_str)
|
||||||
return template.render(color=colordict, font=fontdict)
|
return template.render(color=colordict, font=config.section('fonts'))
|
||||||
|
|
||||||
|
|
||||||
def set_register_stylesheet(obj):
|
def set_register_stylesheet(obj):
|
||||||
@ -83,10 +82,7 @@ class ColorDict(collections.UserDict):
|
|||||||
If a value wasn't found, return an empty string.
|
If a value wasn't found, return an empty string.
|
||||||
(Color not defined, so no output in the stylesheet)
|
(Color not defined, so no output in the stylesheet)
|
||||||
|
|
||||||
If the key has a .fg. element in it, return color: X;.
|
else, return the plain value.
|
||||||
If the key has a .bg. element in it, return background-color: X;.
|
|
||||||
|
|
||||||
In all other cases, return the plain value.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
val = self.data[key]
|
val = self.data[key]
|
||||||
@ -98,33 +94,5 @@ class ColorDict(collections.UserDict):
|
|||||||
# QtColor instead of Color in the config, and it'd go unnoticed as
|
# QtColor instead of Color in the config, and it'd go unnoticed as
|
||||||
# the CSS is invalid then.
|
# the CSS is invalid then.
|
||||||
raise TypeError("QColor passed to ColorDict!")
|
raise TypeError("QColor passed to ColorDict!")
|
||||||
if 'fg' in key.split('.'):
|
|
||||||
return 'color: {};'.format(val)
|
|
||||||
elif 'bg' in key.split('.'):
|
|
||||||
return 'background-color: {};'.format(val)
|
|
||||||
else:
|
else:
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
class FontDict(collections.UserDict):
|
|
||||||
|
|
||||||
"""A dict aimed at Qt stylesheet fonts."""
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
"""Override dict __getitem__.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
key: The key to get from the dict.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
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 = self.data[key]
|
|
||||||
except KeyError:
|
|
||||||
return ''
|
|
||||||
else:
|
|
||||||
return 'font: {};'.format(val)
|
|
||||||
|
@ -110,58 +110,58 @@ class StatusBar(QWidget):
|
|||||||
QWidget#StatusBar,
|
QWidget#StatusBar,
|
||||||
QWidget#StatusBar QLabel,
|
QWidget#StatusBar QLabel,
|
||||||
QWidget#StatusBar QLineEdit {
|
QWidget#StatusBar QLineEdit {
|
||||||
{{ font['statusbar'] }}
|
font: {{ font['statusbar'] }};
|
||||||
{{ color['statusbar.bg'] }}
|
background-color: {{ color['statusbar.bg'] }};
|
||||||
{{ color['statusbar.fg'] }}
|
color: {{ color['statusbar.fg'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[caret_mode="on"],
|
QWidget#StatusBar[caret_mode="on"],
|
||||||
QWidget#StatusBar[caret_mode="on"] QLabel,
|
QWidget#StatusBar[caret_mode="on"] QLabel,
|
||||||
QWidget#StatusBar[caret_mode="on"] QLineEdit {
|
QWidget#StatusBar[caret_mode="on"] QLineEdit {
|
||||||
{{ color['statusbar.fg.caret'] }}
|
color: {{ color['statusbar.fg.caret'] }};
|
||||||
{{ color['statusbar.bg.caret'] }}
|
background-color: {{ color['statusbar.bg.caret'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[caret_mode="selection"],
|
QWidget#StatusBar[caret_mode="selection"],
|
||||||
QWidget#StatusBar[caret_mode="selection"] QLabel,
|
QWidget#StatusBar[caret_mode="selection"] QLabel,
|
||||||
QWidget#StatusBar[caret_mode="selection"] QLineEdit {
|
QWidget#StatusBar[caret_mode="selection"] QLineEdit {
|
||||||
{{ color['statusbar.fg.caret-selection'] }}
|
color: {{ color['statusbar.fg.caret-selection'] }};
|
||||||
{{ color['statusbar.bg.caret-selection'] }}
|
background-color: {{ color['statusbar.bg.caret-selection'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[severity="error"],
|
QWidget#StatusBar[severity="error"],
|
||||||
QWidget#StatusBar[severity="error"] QLabel,
|
QWidget#StatusBar[severity="error"] QLabel,
|
||||||
QWidget#StatusBar[severity="error"] QLineEdit {
|
QWidget#StatusBar[severity="error"] QLineEdit {
|
||||||
{{ color['statusbar.fg.error'] }}
|
color: {{ color['statusbar.fg.error'] }};
|
||||||
{{ color['statusbar.bg.error'] }}
|
background-color: {{ color['statusbar.bg.error'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[severity="warning"],
|
QWidget#StatusBar[severity="warning"],
|
||||||
QWidget#StatusBar[severity="warning"] QLabel,
|
QWidget#StatusBar[severity="warning"] QLabel,
|
||||||
QWidget#StatusBar[severity="warning"] QLineEdit {
|
QWidget#StatusBar[severity="warning"] QLineEdit {
|
||||||
{{ color['statusbar.fg.warning'] }}
|
color: {{ color['statusbar.fg.warning'] }};
|
||||||
{{ color['statusbar.bg.warning'] }}
|
background-color: {{ color['statusbar.bg.warning'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[prompt_active="true"],
|
QWidget#StatusBar[prompt_active="true"],
|
||||||
QWidget#StatusBar[prompt_active="true"] QLabel,
|
QWidget#StatusBar[prompt_active="true"] QLabel,
|
||||||
QWidget#StatusBar[prompt_active="true"] QLineEdit {
|
QWidget#StatusBar[prompt_active="true"] QLineEdit {
|
||||||
{{ color['statusbar.fg.prompt'] }}
|
color: {{ color['statusbar.fg.prompt'] }};
|
||||||
{{ color['statusbar.bg.prompt'] }}
|
background-color: {{ color['statusbar.bg.prompt'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[insert_active="true"],
|
QWidget#StatusBar[insert_active="true"],
|
||||||
QWidget#StatusBar[insert_active="true"] QLabel,
|
QWidget#StatusBar[insert_active="true"] QLabel,
|
||||||
QWidget#StatusBar[insert_active="true"] QLineEdit {
|
QWidget#StatusBar[insert_active="true"] QLineEdit {
|
||||||
{{ color['statusbar.fg.insert'] }}
|
color: {{ color['statusbar.fg.insert'] }};
|
||||||
{{ color['statusbar.bg.insert'] }}
|
background-color: {{ color['statusbar.bg.insert'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget#StatusBar[command_active="true"],
|
QWidget#StatusBar[command_active="true"],
|
||||||
QWidget#StatusBar[command_active="true"] QLabel,
|
QWidget#StatusBar[command_active="true"] QLabel,
|
||||||
QWidget#StatusBar[command_active="true"] QLineEdit {
|
QWidget#StatusBar[command_active="true"] QLineEdit {
|
||||||
{{ color['statusbar.fg.command'] }}
|
color: {{ color['statusbar.fg.command'] }};
|
||||||
{{ color['statusbar.bg.command'] }}
|
background-color: {{ color['statusbar.bg.command'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -39,7 +39,7 @@ class Progress(QProgressBar):
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProgressBar::chunk {
|
QProgressBar::chunk {
|
||||||
{{ color['statusbar.progress.bg'] }}
|
background-color: {{ color['statusbar.progress.bg'] }};
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -54,27 +54,27 @@ class UrlText(textbase.TextBase):
|
|||||||
|
|
||||||
STYLESHEET = """
|
STYLESHEET = """
|
||||||
QLabel#UrlText[urltype="normal"] {
|
QLabel#UrlText[urltype="normal"] {
|
||||||
{{ color['statusbar.url.fg'] }}
|
color: {{ color['statusbar.url.fg'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel#UrlText[urltype="success"] {
|
QLabel#UrlText[urltype="success"] {
|
||||||
{{ color['statusbar.url.fg.success'] }}
|
color: {{ color['statusbar.url.fg.success'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel#UrlText[urltype="success_https"] {
|
QLabel#UrlText[urltype="success_https"] {
|
||||||
{{ color['statusbar.url.fg.success.https'] }}
|
color: {{ color['statusbar.url.fg.success.https'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel#UrlText[urltype="error"] {
|
QLabel#UrlText[urltype="error"] {
|
||||||
{{ color['statusbar.url.fg.error'] }}
|
color: {{ color['statusbar.url.fg.error'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel#UrlText[urltype="warn"] {
|
QLabel#UrlText[urltype="warn"] {
|
||||||
{{ color['statusbar.url.fg.warn'] }}
|
color: {{ color['statusbar.url.fg.warn'] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel#UrlText[urltype="hover"] {
|
QLabel#UrlText[urltype="hover"] {
|
||||||
{{ color['statusbar.url.fg.hover'] }}
|
color: {{ color['statusbar.url.fg.hover'] }};
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ def test_get_stylesheet(config_stub):
|
|||||||
}
|
}
|
||||||
template = "{{ color['completion.bg'] }}\n{{ font['completion'] }}"
|
template = "{{ color['completion.bg'] }}\n{{ font['completion'] }}"
|
||||||
rendered = style.get_stylesheet(template)
|
rendered = style.get_stylesheet(template)
|
||||||
assert rendered == 'background-color: black;\nfont: foo;'
|
assert rendered == 'black\nfoo'
|
||||||
|
|
||||||
|
|
||||||
class Obj(QObject):
|
class Obj(QObject):
|
||||||
@ -59,9 +59,9 @@ def test_set_register_stylesheet(delete, qtbot, config_stub, caplog):
|
|||||||
|
|
||||||
records = caplog.records()
|
records = caplog.records()
|
||||||
assert len(records) == 1
|
assert len(records) == 1
|
||||||
assert records[0].message == 'stylesheet for Obj: font: bar;'
|
assert records[0].message == 'stylesheet for Obj: bar'
|
||||||
|
|
||||||
assert obj.rendered_stylesheet == 'font: bar;'
|
assert obj.rendered_stylesheet == 'bar'
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
with qtbot.waitSignal(obj.destroyed):
|
with qtbot.waitSignal(obj.destroyed):
|
||||||
@ -72,9 +72,9 @@ def test_set_register_stylesheet(delete, qtbot, config_stub, caplog):
|
|||||||
config_stub.changed.emit('fonts', 'foo')
|
config_stub.changed.emit('fonts', 'foo')
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
expected = 'font: bar;'
|
expected = 'bar'
|
||||||
else:
|
else:
|
||||||
expected = 'font: baz;'
|
expected = 'baz'
|
||||||
assert obj.rendered_stylesheet == expected
|
assert obj.rendered_stylesheet == expected
|
||||||
|
|
||||||
|
|
||||||
@ -82,8 +82,8 @@ class TestColorDict:
|
|||||||
|
|
||||||
@pytest.mark.parametrize('key, expected', [
|
@pytest.mark.parametrize('key, expected', [
|
||||||
('foo', 'one'),
|
('foo', 'one'),
|
||||||
('foo.fg', 'color: two;'),
|
('foo.fg', 'two'),
|
||||||
('foo.bg', 'background-color: three;'),
|
('foo.bg', 'three'),
|
||||||
])
|
])
|
||||||
def test_values(self, key, expected):
|
def test_values(self, key, expected):
|
||||||
d = style.ColorDict()
|
d = style.ColorDict()
|
||||||
@ -107,11 +107,3 @@ class TestColorDict:
|
|||||||
d['foo'] # pylint: disable=pointless-statement
|
d['foo'] # pylint: disable=pointless-statement
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('key, expected', [
|
|
||||||
('foo', 'font: one;'),
|
|
||||||
('bar', ''),
|
|
||||||
])
|
|
||||||
def test_font_dict(key, expected):
|
|
||||||
d = style.FontDict()
|
|
||||||
d['foo'] = 'one'
|
|
||||||
assert d[key] == expected
|
|
||||||
|
Loading…
Reference in New Issue
Block a user